annotate hotspot/src/share/vm/gc_implementation/g1/g1RemSet.hpp @ 7385:eaca4b61b374

6978187: G1: assert(ParallelGCThreads> 1 || n_yielded() == _hrrs->occupied()) strikes again Summary: An evacuation failure while copying the roots caused an object, A, to be forwarded to itself. During the subsequent RSet updating a reference to A was processed causing the reference to be added to the RSet of A's heap region. As a result of adding to the remembered set we ran into the issue described in 6930581 - the sparse table expanded and the RSet scanning code walked the cards in one instance of RHashTable (_cur) while the occupied() counts the cards in the expanded table (_next). Reviewed-by: tonyp, iveresov
author johnc
date Tue, 16 Nov 2010 14:07:33 -0800
parents cfa71cf3564d
children 5b173b4ca846
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@6247 62 // Used for caching the closure that is responsible for scanning
johnc@6247 63 // references into the collection set.
johnc@6247 64 OopsInHeapRegionClosure** _cset_rs_update_cl;
ysr@3262 65
johnc@3590 66 // The routine that performs the actual work of refining a dirty
johnc@3590 67 // card.
johnc@6247 68 // If check_for_refs_into_refs is true then a true result is returned
johnc@6247 69 // if the card contains oops that have references into the current
johnc@6247 70 // collection set.
johnc@6247 71 bool concurrentRefineOneCard_impl(jbyte* card_ptr, int worker_i,
johnc@6247 72 bool check_for_refs_into_cset);
johnc@3590 73
ysr@1374 74 public:
ysr@1374 75 // This is called to reset dual hash tables after the gc pause
ysr@1374 76 // is finished and the initial hash table is no longer being
ysr@1374 77 // scanned.
ysr@1374 78 void cleanupHRRS();
ysr@1374 79
johnc@6958 80 G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs);
johnc@6958 81 ~G1RemSet();
ysr@1374 82
johnc@6958 83 // Invoke "blk->do_oop" on all pointers into the CS in objects in regions
johnc@6958 84 // outside the CS (having invoked "blk->set_region" to set the "from"
johnc@6958 85 // region correctly beforehand.) The "worker_i" param is for the
johnc@6958 86 // parallel case where the number of the worker thread calling this
johnc@6958 87 // function can be helpful in partitioning the work to be done. It
johnc@6958 88 // should be the same as the "i" passed to the calling thread's
johnc@6958 89 // work(i) function. In the sequential case this param will be ingored.
ysr@1374 90 void oops_into_collection_set_do(OopsInHeapRegionClosure* blk,
ysr@1374 91 int worker_i);
ysr@1374 92
johnc@6958 93 // Prepare for and cleanup after an oops_into_collection_set_do
johnc@6958 94 // call. Must call each of these once before and after (in sequential
johnc@6958 95 // code) any threads call oops_into_collection_set_do. (This offers an
johnc@6958 96 // opportunity to sequential setup and teardown of structures needed by a
johnc@6958 97 // parallel iteration over the CS's RS.)
ysr@1374 98 void prepare_for_oops_into_collection_set_do();
ysr@1374 99 void cleanup_after_oops_into_collection_set_do();
johnc@6958 100
ysr@1374 101 void scanRS(OopsInHeapRegionClosure* oc, int worker_i);
johnc@6247 102 void updateRS(DirtyCardQueue* into_cset_dcq, int worker_i);
johnc@6958 103
ysr@1374 104 HeapRegion* calculateStartRegion(int i);
ysr@1374 105
ysr@1374 106 CardTableModRefBS* ct_bs() { return _ct_bs; }
ysr@1374 107 size_t cardsScanned() { return _total_cards_scanned; }
ysr@1374 108
ysr@1374 109 // Record, if necessary, the fact that *p (where "p" is in region "from",
ysr@1374 110 // which is required to be non-NULL) has changed to a new non-NULL value.
johnc@7385 111 template <class T> void write_ref(HeapRegion* from, T* p);
johnc@7385 112 template <class T> void par_write_ref(HeapRegion* from, T* p, int tid);
ysr@1374 113
johnc@6958 114 // Requires "region_bm" and "card_bm" to be bitmaps with 1 bit per region
johnc@6958 115 // or card, respectively, such that a region or card with a corresponding
johnc@6958 116 // 0 bit contains no part of any live object. Eliminates any remembered
johnc@6958 117 // set entries that correspond to dead heap ranges.
ysr@1374 118 void scrub(BitMap* region_bm, BitMap* card_bm);
johnc@6958 119
johnc@6958 120 // Like the above, but assumes is called in parallel: "worker_num" is the
johnc@6958 121 // parallel thread id of the current thread, and "claim_val" is the
johnc@6958 122 // value that should be used to claim heap regions.
ysr@1374 123 void scrub_par(BitMap* region_bm, BitMap* card_bm,
ysr@1374 124 int worker_num, int claim_val);
ysr@1374 125
johnc@6958 126 // Refine the card corresponding to "card_ptr". If "sts" is non-NULL,
johnc@6958 127 // join and leave around parts that must be atomic wrt GC. (NULL means
johnc@6958 128 // being done at a safepoint.)
johnc@6958 129 // If check_for_refs_into_cset is true, a true result is returned
johnc@6958 130 // if the given card contains oops that have references into the
johnc@6958 131 // current collection set.
johnc@6247 132 virtual bool concurrentRefineOneCard(jbyte* card_ptr, int worker_i,
johnc@6247 133 bool check_for_refs_into_cset);
ysr@1374 134
johnc@6958 135 // Print any relevant summary info.
ysr@1374 136 virtual void print_summary_info();
johnc@6958 137
johnc@6958 138 // Prepare remembered set for verification.
ysr@1374 139 virtual void prepare_for_verify();
ysr@1374 140 };
ysr@1374 141
ysr@1374 142 #define G1_REM_SET_LOGGING 0
ysr@1374 143
ysr@1374 144 class CountNonCleanMemRegionClosure: public MemRegionClosure {
ysr@1374 145 G1CollectedHeap* _g1;
ysr@1374 146 int _n;
ysr@1374 147 HeapWord* _start_first;
ysr@1374 148 public:
ysr@1374 149 CountNonCleanMemRegionClosure(G1CollectedHeap* g1) :
ysr@1374 150 _g1(g1), _n(0), _start_first(NULL)
ysr@1374 151 {}
ysr@1374 152 void do_MemRegion(MemRegion mr);
ysr@1374 153 int n() { return _n; };
ysr@1374 154 HeapWord* start_first() { return _start_first; }
ysr@1374 155 };
apetrusenko@2152 156
apetrusenko@2152 157 class UpdateRSOopClosure: public OopClosure {
apetrusenko@2152 158 HeapRegion* _from;
johnc@6958 159 G1RemSet* _rs;
apetrusenko@2152 160 int _worker_i;
ysr@3262 161
ysr@3262 162 template <class T> void do_oop_work(T* p);
ysr@3262 163
apetrusenko@2152 164 public:
johnc@6958 165 UpdateRSOopClosure(G1RemSet* rs, int worker_i = 0) :
johnc@7385 166 _from(NULL), _rs(rs), _worker_i(worker_i)
johnc@7385 167 {}
apetrusenko@2152 168
apetrusenko@2152 169 void set_from(HeapRegion* from) {
apetrusenko@2152 170 assert(from != NULL, "from region must be non-NULL");
apetrusenko@2152 171 _from = from;
apetrusenko@2152 172 }
apetrusenko@2152 173
ysr@3262 174 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@3262 175 virtual void do_oop(oop* p) { do_oop_work(p); }
apetrusenko@2152 176
apetrusenko@2152 177 // Override: this closure is idempotent.
apetrusenko@2152 178 // bool idempotent() { return true; }
apetrusenko@2152 179 bool apply_to_weak_ref_discovered_field() { return true; }
apetrusenko@2152 180 };
johnc@6247 181
johnc@6247 182 class UpdateRSetImmediate: public OopsInHeapRegionClosure {
johnc@6247 183 private:
johnc@6247 184 G1RemSet* _g1_rem_set;
johnc@6247 185
johnc@6247 186 template <class T> void do_oop_work(T* p);
johnc@6247 187 public:
johnc@6247 188 UpdateRSetImmediate(G1RemSet* rs) :
johnc@6247 189 _g1_rem_set(rs) {}
johnc@6247 190
johnc@6247 191 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@6247 192 virtual void do_oop( oop* p) { do_oop_work(p); }
johnc@6247 193 };
johnc@7385 194
johnc@7385 195 class UpdateRSOrPushRefOopClosure: public OopClosure {
johnc@7385 196 G1CollectedHeap* _g1;
johnc@7385 197 G1RemSet* _g1_rem_set;
johnc@7385 198 HeapRegion* _from;
johnc@7385 199 OopsInHeapRegionClosure* _push_ref_cl;
johnc@7385 200 bool _record_refs_into_cset;
johnc@7385 201 int _worker_i;
johnc@7385 202
johnc@7385 203 template <class T> void do_oop_work(T* p);
johnc@7385 204
johnc@7385 205 public:
johnc@7385 206 UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
johnc@7385 207 G1RemSet* rs,
johnc@7385 208 OopsInHeapRegionClosure* push_ref_cl,
johnc@7385 209 bool record_refs_into_cset,
johnc@7385 210 int worker_i = 0) :
johnc@7385 211 _g1(g1h),
johnc@7385 212 _g1_rem_set(rs),
johnc@7385 213 _from(NULL),
johnc@7385 214 _record_refs_into_cset(record_refs_into_cset),
johnc@7385 215 _push_ref_cl(push_ref_cl),
johnc@7385 216 _worker_i(worker_i) { }
johnc@7385 217
johnc@7385 218 void set_from(HeapRegion* from) {
johnc@7385 219 assert(from != NULL, "from region must be non-NULL");
johnc@7385 220 _from = from;
johnc@7385 221 }
johnc@7385 222
johnc@7385 223 bool self_forwarded(oop obj) {
johnc@7385 224 bool result = (obj->is_forwarded() && (obj->forwardee()== obj));
johnc@7385 225 return result;
johnc@7385 226 }
johnc@7385 227
johnc@7385 228 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@7385 229 virtual void do_oop(oop* p) { do_oop_work(p); }
johnc@7385 230
johnc@7385 231 bool apply_to_weak_ref_discovered_field() { return true; }
johnc@7385 232 };
johnc@7385 233