annotate src/share/vm/gc_implementation/g1/g1RemSet.hpp @ 794:315a5d70b295

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