342N/A/*
4539N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1REMSET_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_G1REMSET_HPP
1879N/A
342N/A// A G1RemSet provides ways of iterating over pointers into a selected
342N/A// collection set.
342N/A
342N/Aclass G1CollectedHeap;
342N/Aclass CardTableModRefBarrierSet;
342N/Aclass ConcurrentG1Refine;
342N/A
1781N/A// A G1RemSet in which each heap region has a rem set that records the
1781N/A// external heap references into it. Uses a mod ref bs to track updates,
1781N/A// so that they can be used to update the individual region remsets.
1781N/A
3863N/Aclass G1RemSet: public CHeapObj<mtGC> {
342N/Aprotected:
342N/A G1CollectedHeap* _g1;
342N/A unsigned _conc_refine_cards;
3008N/A uint n_workers();
342N/A
342N/Aprotected:
342N/A enum SomePrivateConstants {
342N/A UpdateRStoMergeSync = 0,
342N/A MergeRStoDoDirtySync = 1,
342N/A DoDirtySync = 2,
342N/A LastSync = 3,
342N/A
342N/A SeqTask = 0,
342N/A NumSeqTasks = 1
342N/A };
342N/A
342N/A CardTableModRefBS* _ct_bs;
342N/A SubTasksDone* _seq_task;
342N/A G1CollectorPolicy* _g1p;
342N/A
342N/A ConcurrentG1Refine* _cg1r;
342N/A
342N/A size_t* _cards_scanned;
342N/A size_t _total_cards_scanned;
342N/A
1625N/A // Used for caching the closure that is responsible for scanning
1625N/A // references into the collection set.
1625N/A OopsInHeapRegionClosure** _cset_rs_update_cl;
845N/A
342N/Apublic:
342N/A // This is called to reset dual hash tables after the gc pause
342N/A // is finished and the initial hash table is no longer being
342N/A // scanned.
342N/A void cleanupHRRS();
342N/A
1781N/A G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs);
1781N/A ~G1RemSet();
342N/A
1781N/A // Invoke "blk->do_oop" on all pointers into the CS in objects in regions
1781N/A // outside the CS (having invoked "blk->set_region" to set the "from"
1781N/A // region correctly beforehand.) The "worker_i" param is for the
1781N/A // parallel case where the number of the worker thread calling this
1781N/A // function can be helpful in partitioning the work to be done. It
1781N/A // should be the same as the "i" passed to the calling thread's
1781N/A // work(i) function. In the sequential case this param will be ingored.
4539N/A void oops_into_collection_set_do(OopsInHeapRegionClosure* blk, int worker_i);
342N/A
1781N/A // Prepare for and cleanup after an oops_into_collection_set_do
1781N/A // call. Must call each of these once before and after (in sequential
1781N/A // code) any threads call oops_into_collection_set_do. (This offers an
1781N/A // opportunity to sequential setup and teardown of structures needed by a
1781N/A // parallel iteration over the CS's RS.)
342N/A void prepare_for_oops_into_collection_set_do();
342N/A void cleanup_after_oops_into_collection_set_do();
1781N/A
342N/A void scanRS(OopsInHeapRegionClosure* oc, int worker_i);
1625N/A void updateRS(DirtyCardQueue* into_cset_dcq, int worker_i);
1781N/A
342N/A CardTableModRefBS* ct_bs() { return _ct_bs; }
342N/A size_t cardsScanned() { return _total_cards_scanned; }
342N/A
342N/A // Record, if necessary, the fact that *p (where "p" is in region "from",
342N/A // which is required to be non-NULL) has changed to a new non-NULL value.
1867N/A template <class T> void write_ref(HeapRegion* from, T* p);
1867N/A template <class T> void par_write_ref(HeapRegion* from, T* p, int tid);
342N/A
1781N/A // Requires "region_bm" and "card_bm" to be bitmaps with 1 bit per region
1781N/A // or card, respectively, such that a region or card with a corresponding
1781N/A // 0 bit contains no part of any live object. Eliminates any remembered
1781N/A // set entries that correspond to dead heap ranges.
342N/A void scrub(BitMap* region_bm, BitMap* card_bm);
1781N/A
1781N/A // Like the above, but assumes is called in parallel: "worker_num" is the
1781N/A // parallel thread id of the current thread, and "claim_val" is the
1781N/A // value that should be used to claim heap regions.
342N/A void scrub_par(BitMap* region_bm, BitMap* card_bm,
3008N/A uint worker_num, int claim_val);
342N/A
4539N/A // Refine the card corresponding to "card_ptr".
1781N/A // If check_for_refs_into_cset is true, a true result is returned
1781N/A // if the given card contains oops that have references into the
1781N/A // current collection set.
4539N/A virtual bool refine_card(jbyte* card_ptr,
4539N/A int worker_i,
4539N/A bool check_for_refs_into_cset);
342N/A
1781N/A // Print any relevant summary info.
342N/A virtual void print_summary_info();
1781N/A
1781N/A // Prepare remembered set for verification.
342N/A virtual void prepare_for_verify();
342N/A};
342N/A
342N/Aclass CountNonCleanMemRegionClosure: public MemRegionClosure {
342N/A G1CollectedHeap* _g1;
342N/A int _n;
342N/A HeapWord* _start_first;
342N/Apublic:
342N/A CountNonCleanMemRegionClosure(G1CollectedHeap* g1) :
342N/A _g1(g1), _n(0), _start_first(NULL)
342N/A {}
342N/A void do_MemRegion(MemRegion mr);
342N/A int n() { return _n; };
342N/A HeapWord* start_first() { return _start_first; }
342N/A};
626N/A
626N/Aclass UpdateRSOopClosure: public OopClosure {
626N/A HeapRegion* _from;
1781N/A G1RemSet* _rs;
626N/A int _worker_i;
845N/A
845N/A template <class T> void do_oop_work(T* p);
845N/A
626N/Apublic:
1781N/A UpdateRSOopClosure(G1RemSet* rs, int worker_i = 0) :
1867N/A _from(NULL), _rs(rs), _worker_i(worker_i)
1867N/A {}
626N/A
626N/A void set_from(HeapRegion* from) {
626N/A assert(from != NULL, "from region must be non-NULL");
626N/A _from = from;
626N/A }
626N/A
845N/A virtual void do_oop(narrowOop* p) { do_oop_work(p); }
845N/A virtual void do_oop(oop* p) { do_oop_work(p); }
626N/A
626N/A // Override: this closure is idempotent.
626N/A // bool idempotent() { return true; }
626N/A bool apply_to_weak_ref_discovered_field() { return true; }
626N/A};
1625N/A
1625N/Aclass UpdateRSetImmediate: public OopsInHeapRegionClosure {
1625N/Aprivate:
1625N/A G1RemSet* _g1_rem_set;
1625N/A
1625N/A template <class T> void do_oop_work(T* p);
1625N/Apublic:
1625N/A UpdateRSetImmediate(G1RemSet* rs) :
1625N/A _g1_rem_set(rs) {}
1625N/A
1625N/A virtual void do_oop(narrowOop* p) { do_oop_work(p); }
1625N/A virtual void do_oop( oop* p) { do_oop_work(p); }
1625N/A};
1867N/A
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1REMSET_HPP