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