annotate hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp @ 6958:cfa71cf3564d

6971296: G1: simplify G1RemSet class hierarchy Summary: Remove G1RemSet base class and StupidG1RemSet class; rename HRInto_G1RemSet to just G1RemSet. Reviewed-by: ysr, tonyp
author johnc
date Tue, 12 Oct 2010 09:36:48 -0700
parents 5680f968c721
children eaca4b61b374
rev   line source
ysr@1374 1 /*
johnc@6247 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
ysr@1374 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@1374 4 *
ysr@1374 5 * This code is free software; you can redistribute it and/or modify it
ysr@1374 6 * under the terms of the GNU General Public License version 2 only, as
ysr@1374 7 * published by the Free Software Foundation.
ysr@1374 8 *
ysr@1374 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@1374 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@1374 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@1374 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@1374 13 * accompanied this code).
ysr@1374 14 *
ysr@1374 15 * You should have received a copy of the GNU General Public License version
ysr@1374 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@1374 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@1374 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
ysr@1374 22 *
ysr@1374 23 */
ysr@1374 24
ysr@1374 25 // A G1RemSet provides ways of iterating over pointers into a selected
ysr@1374 26 // collection set.
ysr@1374 27
ysr@1374 28 class G1CollectedHeap;
ysr@1374 29 class CardTableModRefBarrierSet;
ysr@1374 30 class ConcurrentG1Refine;
ysr@1374 31
johnc@6958 32 // A G1RemSet in which each heap region has a rem set that records the
johnc@6958 33 // external heap references into it. Uses a mod ref bs to track updates,
johnc@6958 34 // so that they can be used to update the individual region remsets.
johnc@6958 35
apetrusenko@2013 36 class G1RemSet: public CHeapObj {
ysr@1374 37 protected:
ysr@1374 38 G1CollectedHeap* _g1;
ysr@1374 39 unsigned _conc_refine_cards;
ysr@1374 40 size_t n_workers();
ysr@1374 41
ysr@1374 42 protected:
ysr@1374 43 enum SomePrivateConstants {
ysr@1374 44 UpdateRStoMergeSync = 0,
ysr@1374 45 MergeRStoDoDirtySync = 1,
ysr@1374 46 DoDirtySync = 2,
ysr@1374 47 LastSync = 3,
ysr@1374 48
ysr@1374 49 SeqTask = 0,
ysr@1374 50 NumSeqTasks = 1
ysr@1374 51 };
ysr@1374 52
ysr@1374 53 CardTableModRefBS* _ct_bs;
ysr@1374 54 SubTasksDone* _seq_task;
ysr@1374 55 G1CollectorPolicy* _g1p;
ysr@1374 56
ysr@1374 57 ConcurrentG1Refine* _cg1r;
ysr@1374 58
ysr@1374 59 size_t* _cards_scanned;
ysr@1374 60 size_t _total_cards_scanned;
ysr@1374 61
johnc@6250 62 // _traversal_in_progress is "true" iff a traversal is in progress.
johnc@6250 63
johnc@6250 64 bool _traversal_in_progress;
johnc@6250 65 void set_traversal(bool b) { _traversal_in_progress = b; }
johnc@6247 66
johnc@6247 67 // Used for caching the closure that is responsible for scanning
johnc@6247 68 // references into the collection set.
johnc@6247 69 OopsInHeapRegionClosure** _cset_rs_update_cl;
ysr@3262 70
johnc@3590 71 // The routine that performs the actual work of refining a dirty
johnc@3590 72 // card.
johnc@6247 73 // If check_for_refs_into_refs is true then a true result is returned
johnc@6247 74 // if the card contains oops that have references into the current
johnc@6247 75 // collection set.
johnc@6247 76 bool concurrentRefineOneCard_impl(jbyte* card_ptr, int worker_i,
johnc@6247 77 bool check_for_refs_into_cset);
johnc@3590 78
ysr@3262 79 protected:
ysr@3262 80 template <class T> void write_ref_nv(HeapRegion* from, T* p);
ysr@3262 81 template <class T> void par_write_ref_nv(HeapRegion* from, T* p, int tid);
ysr@1374 82
ysr@1374 83 public:
ysr@1374 84 // This is called to reset dual hash tables after the gc pause
ysr@1374 85 // is finished and the initial hash table is no longer being
ysr@1374 86 // scanned.
ysr@1374 87 void cleanupHRRS();
ysr@1374 88
johnc@6958 89 G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs);
johnc@6958 90 ~G1RemSet();
ysr@1374 91
johnc@6958 92 // Invoke "blk->do_oop" on all pointers into the CS in objects in regions
johnc@6958 93 // outside the CS (having invoked "blk->set_region" to set the "from"
johnc@6958 94 // region correctly beforehand.) The "worker_i" param is for the
johnc@6958 95 // parallel case where the number of the worker thread calling this
johnc@6958 96 // function can be helpful in partitioning the work to be done. It
johnc@6958 97 // should be the same as the "i" passed to the calling thread's
johnc@6958 98 // work(i) function. In the sequential case this param will be ingored.
ysr@1374 99 void oops_into_collection_set_do(OopsInHeapRegionClosure* blk,
ysr@1374 100 int worker_i);
ysr@1374 101
johnc@6958 102 // Prepare for and cleanup after an oops_into_collection_set_do
johnc@6958 103 // call. Must call each of these once before and after (in sequential
johnc@6958 104 // code) any threads call oops_into_collection_set_do. (This offers an
johnc@6958 105 // opportunity to sequential setup and teardown of structures needed by a
johnc@6958 106 // parallel iteration over the CS's RS.)
ysr@1374 107 void prepare_for_oops_into_collection_set_do();
ysr@1374 108 void cleanup_after_oops_into_collection_set_do();
johnc@6958 109
ysr@1374 110 void scanRS(OopsInHeapRegionClosure* oc, int worker_i);
johnc@6247 111 void updateRS(DirtyCardQueue* into_cset_dcq, int worker_i);
johnc@6958 112
ysr@1374 113 HeapRegion* calculateStartRegion(int i);
ysr@1374 114
ysr@1374 115 CardTableModRefBS* ct_bs() { return _ct_bs; }
ysr@1374 116 size_t cardsScanned() { return _total_cards_scanned; }
ysr@1374 117
ysr@1374 118 // Record, if necessary, the fact that *p (where "p" is in region "from",
ysr@1374 119 // which is required to be non-NULL) has changed to a new non-NULL value.
ysr@3262 120 // [Below the virtual version calls a non-virtual protected
ysr@3262 121 // workhorse that is templatified for narrow vs wide oop.]
ysr@3262 122 inline void write_ref(HeapRegion* from, oop* p) {
ysr@3262 123 write_ref_nv(from, p);
ysr@3262 124 }
ysr@3262 125 inline void write_ref(HeapRegion* from, narrowOop* p) {
ysr@3262 126 write_ref_nv(from, p);
ysr@3262 127 }
ysr@3262 128 inline void par_write_ref(HeapRegion* from, oop* p, int tid) {
ysr@3262 129 par_write_ref_nv(from, p, tid);
ysr@3262 130 }
ysr@3262 131 inline void par_write_ref(HeapRegion* from, narrowOop* p, int tid) {
ysr@3262 132 par_write_ref_nv(from, p, tid);
ysr@3262 133 }
ysr@1374 134
ysr@3262 135 bool self_forwarded(oop obj);
ysr@1374 136
johnc@6958 137 // Requires "region_bm" and "card_bm" to be bitmaps with 1 bit per region
johnc@6958 138 // or card, respectively, such that a region or card with a corresponding
johnc@6958 139 // 0 bit contains no part of any live object. Eliminates any remembered
johnc@6958 140 // set entries that correspond to dead heap ranges.
ysr@1374 141 void scrub(BitMap* region_bm, BitMap* card_bm);
johnc@6958 142
johnc@6958 143 // Like the above, but assumes is called in parallel: "worker_num" is the
johnc@6958 144 // parallel thread id of the current thread, and "claim_val" is the
johnc@6958 145 // value that should be used to claim heap regions.
ysr@1374 146 void scrub_par(BitMap* region_bm, BitMap* card_bm,
ysr@1374 147 int worker_num, int claim_val);
ysr@1374 148
johnc@6958 149 // Refine the card corresponding to "card_ptr". If "sts" is non-NULL,
johnc@6958 150 // join and leave around parts that must be atomic wrt GC. (NULL means
johnc@6958 151 // being done at a safepoint.)
johnc@6958 152 // If check_for_refs_into_cset is true, a true result is returned
johnc@6958 153 // if the given card contains oops that have references into the
johnc@6958 154 // current collection set.
johnc@6247 155 virtual bool concurrentRefineOneCard(jbyte* card_ptr, int worker_i,
johnc@6247 156 bool check_for_refs_into_cset);
ysr@1374 157
johnc@6958 158 // Print any relevant summary info.
ysr@1374 159 virtual void print_summary_info();
johnc@6958 160
johnc@6958 161 // Prepare remembered set for verification.
ysr@1374 162 virtual void prepare_for_verify();
ysr@1374 163 };
ysr@1374 164
ysr@1374 165 #define G1_REM_SET_LOGGING 0
ysr@1374 166
ysr@1374 167 class CountNonCleanMemRegionClosure: public MemRegionClosure {
ysr@1374 168 G1CollectedHeap* _g1;
ysr@1374 169 int _n;
ysr@1374 170 HeapWord* _start_first;
ysr@1374 171 public:
ysr@1374 172 CountNonCleanMemRegionClosure(G1CollectedHeap* g1) :
ysr@1374 173 _g1(g1), _n(0), _start_first(NULL)
ysr@1374 174 {}
ysr@1374 175 void do_MemRegion(MemRegion mr);
ysr@1374 176 int n() { return _n; };
ysr@1374 177 HeapWord* start_first() { return _start_first; }
ysr@1374 178 };
apetrusenko@2152 179
apetrusenko@2152 180 class UpdateRSOopClosure: public OopClosure {
apetrusenko@2152 181 HeapRegion* _from;
johnc@6958 182 G1RemSet* _rs;
apetrusenko@2152 183 int _worker_i;
ysr@3262 184
ysr@3262 185 template <class T> void do_oop_work(T* p);
ysr@3262 186
apetrusenko@2152 187 public:
johnc@6958 188 UpdateRSOopClosure(G1RemSet* rs, int worker_i = 0) :
apetrusenko@2152 189 _from(NULL), _rs(rs), _worker_i(worker_i) {
apetrusenko@2152 190 guarantee(_rs != NULL, "Requires an HRIntoG1RemSet");
apetrusenko@2152 191 }
apetrusenko@2152 192
apetrusenko@2152 193 void set_from(HeapRegion* from) {
apetrusenko@2152 194 assert(from != NULL, "from region must be non-NULL");
apetrusenko@2152 195 _from = from;
apetrusenko@2152 196 }
apetrusenko@2152 197
ysr@3262 198 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@3262 199 virtual void do_oop(oop* p) { do_oop_work(p); }
apetrusenko@2152 200
apetrusenko@2152 201 // Override: this closure is idempotent.
apetrusenko@2152 202 // bool idempotent() { return true; }
apetrusenko@2152 203 bool apply_to_weak_ref_discovered_field() { return true; }
apetrusenko@2152 204 };
johnc@6247 205
johnc@6247 206 class UpdateRSetImmediate: public OopsInHeapRegionClosure {
johnc@6247 207 private:
johnc@6247 208 G1RemSet* _g1_rem_set;
johnc@6247 209
johnc@6247 210 template <class T> void do_oop_work(T* p);
johnc@6247 211 public:
johnc@6247 212 UpdateRSetImmediate(G1RemSet* rs) :
johnc@6247 213 _g1_rem_set(rs) {}
johnc@6247 214
johnc@6247 215 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@6247 216 virtual void do_oop( oop* p) { do_oop_work(p); }
johnc@6247 217 };