src/share/vm/gc_implementation/g1/g1RemSet.cpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6552
8847586c9037
child 6876
710a3c8b516e
child 6969
02e61cf08ab3
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

ysr@777 1 /*
drchase@6680 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/g1/bufferingOopClosure.hpp"
stefank@2314 27 #include "gc_implementation/g1/concurrentG1Refine.hpp"
stefank@2314 28 #include "gc_implementation/g1/concurrentG1RefineThread.hpp"
stefank@2314 29 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
stefank@2314 30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@2314 31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
johnc@5078 32 #include "gc_implementation/g1/g1HotCardCache.hpp"
brutisso@3923 33 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
stefank@2314 34 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@2314 35 #include "gc_implementation/g1/g1RemSet.inline.hpp"
stefank@2314 36 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
tschatzl@5204 37 #include "gc_implementation/g1/heapRegionRemSet.hpp"
stefank@2314 38 #include "memory/iterator.hpp"
stefank@2314 39 #include "oops/oop.inline.hpp"
stefank@2314 40 #include "utilities/intHisto.hpp"
ysr@777 41
drchase@6680 42 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 43
ysr@777 44 #define CARD_REPEAT_HISTO 0
ysr@777 45
ysr@777 46 #if CARD_REPEAT_HISTO
ysr@777 47 static size_t ct_freq_sz;
ysr@777 48 static jbyte* ct_freq = NULL;
ysr@777 49
ysr@777 50 void init_ct_freq_table(size_t heap_sz_bytes) {
ysr@777 51 if (ct_freq == NULL) {
ysr@777 52 ct_freq_sz = heap_sz_bytes/CardTableModRefBS::card_size;
ysr@777 53 ct_freq = new jbyte[ct_freq_sz];
ysr@777 54 for (size_t j = 0; j < ct_freq_sz; j++) ct_freq[j] = 0;
ysr@777 55 }
ysr@777 56 }
ysr@777 57
ysr@777 58 void ct_freq_note_card(size_t index) {
ysr@777 59 assert(0 <= index && index < ct_freq_sz, "Bounds error.");
ysr@777 60 if (ct_freq[index] < 100) { ct_freq[index]++; }
ysr@777 61 }
ysr@777 62
ysr@777 63 static IntHistogram card_repeat_count(10, 10);
ysr@777 64
ysr@777 65 void ct_freq_update_histo_and_reset() {
ysr@777 66 for (size_t j = 0; j < ct_freq_sz; j++) {
ysr@777 67 card_repeat_count.add_entry(ct_freq[j]);
ysr@777 68 ct_freq[j] = 0;
ysr@777 69 }
ysr@777 70
ysr@777 71 }
ysr@777 72 #endif
ysr@777 73
johnc@2216 74 G1RemSet::G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs)
johnc@2216 75 : _g1(g1), _conc_refine_cards(0),
johnc@2216 76 _ct_bs(ct_bs), _g1p(_g1->g1_policy()),
ysr@777 77 _cg1r(g1->concurrent_g1_refine()),
johnc@2060 78 _cset_rs_update_cl(NULL),
tschatzl@5204 79 _cards_scanned(NULL), _total_cards_scanned(0),
tschatzl@5204 80 _prev_period_summary()
ysr@777 81 {
ysr@777 82 _seq_task = new SubTasksDone(NumSeqTasks);
iveresov@1051 83 guarantee(n_workers() > 0, "There should be some workers");
zgu@3900 84 _cset_rs_update_cl = NEW_C_HEAP_ARRAY(OopsInHeapRegionClosure*, n_workers(), mtGC);
iveresov@1051 85 for (uint i = 0; i < n_workers(); i++) {
johnc@2060 86 _cset_rs_update_cl[i] = NULL;
iveresov@1051 87 }
tschatzl@5812 88 if (G1SummarizeRSetStats) {
tschatzl@5812 89 _prev_period_summary.initialize(this);
tschatzl@5812 90 }
ysr@777 91 }
ysr@777 92
johnc@2216 93 G1RemSet::~G1RemSet() {
ysr@777 94 delete _seq_task;
iveresov@1051 95 for (uint i = 0; i < n_workers(); i++) {
johnc@2060 96 assert(_cset_rs_update_cl[i] == NULL, "it should be");
iveresov@1051 97 }
zgu@3900 98 FREE_C_HEAP_ARRAY(OopsInHeapRegionClosure*, _cset_rs_update_cl, mtGC);
ysr@777 99 }
ysr@777 100
ysr@777 101 void CountNonCleanMemRegionClosure::do_MemRegion(MemRegion mr) {
ysr@777 102 if (_g1->is_in_g1_reserved(mr.start())) {
ysr@777 103 _n += (int) ((mr.byte_size() / CardTableModRefBS::card_size));
ysr@777 104 if (_start_first == NULL) _start_first = mr.start();
ysr@777 105 }
ysr@777 106 }
ysr@777 107
ysr@777 108 class ScanRSClosure : public HeapRegionClosure {
ysr@777 109 size_t _cards_done, _cards;
ysr@777 110 G1CollectedHeap* _g1h;
johnc@5548 111
ysr@777 112 OopsInHeapRegionClosure* _oc;
johnc@5548 113 CodeBlobToOopClosure* _code_root_cl;
johnc@5548 114
ysr@777 115 G1BlockOffsetSharedArray* _bot_shared;
mgerdin@5811 116 G1SATBCardTableModRefBS *_ct_bs;
johnc@5548 117
johnc@5548 118 double _strong_code_root_scan_time_sec;
vkempik@6552 119 uint _worker_i;
johnc@5548 120 int _block_size;
johnc@5548 121 bool _try_claimed;
johnc@5548 122
ysr@777 123 public:
johnc@5548 124 ScanRSClosure(OopsInHeapRegionClosure* oc,
johnc@5548 125 CodeBlobToOopClosure* code_root_cl,
vkempik@6552 126 uint worker_i) :
ysr@777 127 _oc(oc),
johnc@5548 128 _code_root_cl(code_root_cl),
johnc@5548 129 _strong_code_root_scan_time_sec(0.0),
ysr@777 130 _cards(0),
ysr@777 131 _cards_done(0),
ysr@777 132 _worker_i(worker_i),
ysr@777 133 _try_claimed(false)
ysr@777 134 {
ysr@777 135 _g1h = G1CollectedHeap::heap();
ysr@777 136 _bot_shared = _g1h->bot_shared();
mgerdin@5811 137 _ct_bs = _g1h->g1_barrier_set();
iveresov@1696 138 _block_size = MAX2<int>(G1RSetScanBlockSize, 1);
ysr@777 139 }
ysr@777 140
ysr@777 141 void set_try_claimed() { _try_claimed = true; }
ysr@777 142
ysr@777 143 void scanCard(size_t index, HeapRegion *r) {
johnc@3219 144 // Stack allocate the DirtyCardToOopClosure instance
johnc@3219 145 HeapRegionDCTOC cl(_g1h, r, _oc,
johnc@3219 146 CardTableModRefBS::Precise,
johnc@3219 147 HeapRegionDCTOC::IntoCSFilterKind);
ysr@777 148
ysr@777 149 // Set the "from" region in the closure.
ysr@777 150 _oc->set_region(r);
ysr@777 151 HeapWord* card_start = _bot_shared->address_for_index(index);
ysr@777 152 HeapWord* card_end = card_start + G1BlockOffsetSharedArray::N_words;
ysr@777 153 Space *sp = SharedHeap::heap()->space_containing(card_start);
tonyp@2849 154 MemRegion sm_region = sp->used_region_at_save_marks();
ysr@777 155 MemRegion mr = sm_region.intersection(MemRegion(card_start,card_end));
tonyp@2849 156 if (!mr.is_empty() && !_ct_bs->is_card_claimed(index)) {
tonyp@2849 157 // We make the card as "claimed" lazily (so races are possible
tonyp@2849 158 // but they're benign), which reduces the number of duplicate
tonyp@2849 159 // scans (the rsets of the regions in the cset can intersect).
tonyp@2849 160 _ct_bs->set_card_claimed(index);
tonyp@2849 161 _cards_done++;
johnc@3219 162 cl.do_MemRegion(mr);
ysr@777 163 }
ysr@777 164 }
ysr@777 165
ysr@777 166 void printCard(HeapRegion* card_region, size_t card_index,
ysr@777 167 HeapWord* card_start) {
vkempik@6552 168 gclog_or_tty->print_cr("T " UINT32_FORMAT " Region [" PTR_FORMAT ", " PTR_FORMAT ") "
ysr@777 169 "RS names card %p: "
ysr@777 170 "[" PTR_FORMAT ", " PTR_FORMAT ")",
ysr@777 171 _worker_i,
ysr@777 172 card_region->bottom(), card_region->end(),
ysr@777 173 card_index,
ysr@777 174 card_start, card_start + G1BlockOffsetSharedArray::N_words);
ysr@777 175 }
ysr@777 176
johnc@5548 177 void scan_strong_code_roots(HeapRegion* r) {
johnc@5548 178 double scan_start = os::elapsedTime();
johnc@5548 179 r->strong_code_roots_do(_code_root_cl);
johnc@5548 180 _strong_code_root_scan_time_sec += (os::elapsedTime() - scan_start);
johnc@5548 181 }
johnc@5548 182
ysr@777 183 bool doHeapRegion(HeapRegion* r) {
ysr@777 184 assert(r->in_collection_set(), "should only be called on elements of CS.");
ysr@777 185 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 186 if (hrrs->iter_is_complete()) return false; // All done.
ysr@777 187 if (!_try_claimed && !hrrs->claim_iter()) return false;
tonyp@2849 188 // If we ever free the collection set concurrently, we should also
tonyp@2849 189 // clear the card table concurrently therefore we won't need to
tonyp@2849 190 // add regions of the collection set to the dirty cards region.
apetrusenko@1231 191 _g1h->push_dirty_cards_region(r);
ysr@777 192 // If we didn't return above, then
ysr@777 193 // _try_claimed || r->claim_iter()
ysr@777 194 // is true: either we're supposed to work on claimed-but-not-complete
ysr@777 195 // regions, or we successfully claimed the region.
johnc@5548 196
johnc@5014 197 HeapRegionRemSetIterator iter(hrrs);
ysr@777 198 size_t card_index;
iveresov@1696 199
iveresov@1696 200 // We claim cards in block so as to recude the contention. The block size is determined by
iveresov@1696 201 // the G1RSetScanBlockSize parameter.
iveresov@1696 202 size_t jump_to_card = hrrs->iter_claimed_next(_block_size);
johnc@5014 203 for (size_t current_card = 0; iter.has_next(card_index); current_card++) {
iveresov@1696 204 if (current_card >= jump_to_card + _block_size) {
iveresov@1696 205 jump_to_card = hrrs->iter_claimed_next(_block_size);
iveresov@1182 206 }
iveresov@1696 207 if (current_card < jump_to_card) continue;
ysr@777 208 HeapWord* card_start = _g1h->bot_shared()->address_for_index(card_index);
ysr@777 209 #if 0
ysr@777 210 gclog_or_tty->print("Rem set iteration yielded card [" PTR_FORMAT ", " PTR_FORMAT ").\n",
ysr@777 211 card_start, card_start + CardTableModRefBS::card_size_in_words);
ysr@777 212 #endif
ysr@777 213
ysr@777 214 HeapRegion* card_region = _g1h->heap_region_containing(card_start);
ysr@777 215 assert(card_region != NULL, "Yielding cards not in the heap?");
ysr@777 216 _cards++;
ysr@777 217
apetrusenko@1231 218 if (!card_region->is_on_dirty_cards_region_list()) {
apetrusenko@1231 219 _g1h->push_dirty_cards_region(card_region);
apetrusenko@1231 220 }
apetrusenko@1231 221
tonyp@2849 222 // If the card is dirty, then we will scan it during updateRS.
tonyp@2849 223 if (!card_region->in_collection_set() &&
tonyp@2849 224 !_ct_bs->is_card_dirty(card_index)) {
tonyp@2849 225 scanCard(card_index, card_region);
ysr@777 226 }
ysr@777 227 }
iveresov@1182 228 if (!_try_claimed) {
johnc@5548 229 // Scan the strong code root list attached to the current region
johnc@5548 230 scan_strong_code_roots(r);
johnc@5548 231
iveresov@1182 232 hrrs->set_iter_complete();
iveresov@1182 233 }
ysr@777 234 return false;
ysr@777 235 }
johnc@5548 236
johnc@5548 237 double strong_code_root_scan_time_sec() {
johnc@5548 238 return _strong_code_root_scan_time_sec;
johnc@5548 239 }
johnc@5548 240
ysr@777 241 size_t cards_done() { return _cards_done;}
ysr@777 242 size_t cards_looked_up() { return _cards;}
ysr@777 243 };
ysr@777 244
johnc@5548 245 void G1RemSet::scanRS(OopsInHeapRegionClosure* oc,
johnc@5548 246 CodeBlobToOopClosure* code_root_cl,
vkempik@6552 247 uint worker_i) {
ysr@777 248 double rs_time_start = os::elapsedTime();
johnc@3296 249 HeapRegion *startRegion = _g1->start_cset_region_for_worker(worker_i);
ysr@777 250
johnc@5548 251 ScanRSClosure scanRScl(oc, code_root_cl, worker_i);
johnc@3175 252
ysr@777 253 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 254 scanRScl.set_try_claimed();
ysr@777 255 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 256
johnc@5548 257 double scan_rs_time_sec = (os::elapsedTime() - rs_time_start)
johnc@5548 258 - scanRScl.strong_code_root_scan_time_sec();
ysr@777 259
johnc@5548 260 assert(_cards_scanned != NULL, "invariant");
ysr@777 261 _cards_scanned[worker_i] = scanRScl.cards_done();
ysr@777 262
brutisso@3923 263 _g1p->phase_times()->record_scan_rs_time(worker_i, scan_rs_time_sec * 1000.0);
johnc@5548 264 _g1p->phase_times()->record_strong_code_root_scan_time(worker_i,
johnc@5548 265 scanRScl.strong_code_root_scan_time_sec() * 1000.0);
ysr@777 266 }
ysr@777 267
johnc@2060 268 // Closure used for updating RSets and recording references that
johnc@2060 269 // point into the collection set. Only called during an
johnc@2060 270 // evacuation pause.
ysr@777 271
johnc@2060 272 class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure {
johnc@2060 273 G1RemSet* _g1rs;
johnc@2060 274 DirtyCardQueue* _into_cset_dcq;
johnc@2060 275 public:
johnc@2060 276 RefineRecordRefsIntoCSCardTableEntryClosure(G1CollectedHeap* g1h,
johnc@2060 277 DirtyCardQueue* into_cset_dcq) :
johnc@2060 278 _g1rs(g1h->g1_rem_set()), _into_cset_dcq(into_cset_dcq)
johnc@2060 279 {}
vkempik@6552 280 bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
johnc@2060 281 // The only time we care about recording cards that
johnc@2060 282 // contain references that point into the collection set
johnc@2060 283 // is during RSet updating within an evacuation pause.
johnc@2060 284 // In this case worker_i should be the id of a GC worker thread.
johnc@2060 285 assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
vkempik@6552 286 assert(worker_i < (ParallelGCThreads == 0 ? 1 : ParallelGCThreads), "should be a GC worker");
johnc@2060 287
johnc@5078 288 if (_g1rs->refine_card(card_ptr, worker_i, true)) {
johnc@2060 289 // 'card_ptr' contains references that point into the collection
johnc@2060 290 // set. We need to record the card in the DCQS
johnc@2060 291 // (G1CollectedHeap::into_cset_dirty_card_queue_set())
johnc@2060 292 // that's used for that purpose.
johnc@2060 293 //
johnc@2060 294 // Enqueue the card
johnc@2060 295 _into_cset_dcq->enqueue(card_ptr);
johnc@2060 296 }
johnc@2060 297 return true;
johnc@2060 298 }
johnc@2060 299 };
johnc@2060 300
vkempik@6552 301 void G1RemSet::updateRS(DirtyCardQueue* into_cset_dcq, uint worker_i) {
ysr@777 302 double start = os::elapsedTime();
johnc@2060 303 // Apply the given closure to all remaining log entries.
johnc@2060 304 RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq);
johnc@3175 305
johnc@2060 306 _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, into_cset_dcq, false, worker_i);
johnc@2060 307
iveresov@1229 308 // Now there should be no dirty cards.
iveresov@1229 309 if (G1RSLogCheckCardTable) {
iveresov@1229 310 CountNonCleanMemRegionClosure cl(_g1);
iveresov@1229 311 _ct_bs->mod_card_iterate(&cl);
iveresov@1229 312 // XXX This isn't true any more: keeping cards of young regions
iveresov@1229 313 // marked dirty broke it. Need some reasonable fix.
iveresov@1229 314 guarantee(cl.n() == 0, "Card table should be clean.");
ysr@777 315 }
iveresov@1229 316
brutisso@3923 317 _g1p->phase_times()->record_update_rs_time(worker_i, (os::elapsedTime() - start) * 1000.0);
ysr@777 318 }
ysr@777 319
johnc@2216 320 void G1RemSet::cleanupHRRS() {
ysr@777 321 HeapRegionRemSet::cleanup();
ysr@777 322 }
ysr@777 323
johnc@2216 324 void G1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc,
johnc@5548 325 CodeBlobToOopClosure* code_root_cl,
vkempik@6552 326 uint worker_i) {
ysr@777 327 #if CARD_REPEAT_HISTO
ysr@777 328 ct_freq_update_histo_and_reset();
ysr@777 329 #endif
ysr@777 330
johnc@2060 331 // We cache the value of 'oc' closure into the appropriate slot in the
johnc@2060 332 // _cset_rs_update_cl for this worker
vkempik@6552 333 assert(worker_i < n_workers(), "sanity");
johnc@2060 334 _cset_rs_update_cl[worker_i] = oc;
johnc@2060 335
johnc@2060 336 // A DirtyCardQueue that is used to hold cards containing references
johnc@2060 337 // that point into the collection set. This DCQ is associated with a
johnc@2060 338 // special DirtyCardQueueSet (see g1CollectedHeap.hpp). Under normal
johnc@2060 339 // circumstances (i.e. the pause successfully completes), these cards
johnc@2060 340 // are just discarded (there's no need to update the RSets of regions
johnc@2060 341 // that were in the collection set - after the pause these regions
johnc@2060 342 // are wholly 'free' of live objects. In the event of an evacuation
johnc@2060 343 // failure the cards/buffers in this queue set are:
johnc@2060 344 // * passed to the DirtyCardQueueSet that is used to manage deferred
johnc@2060 345 // RSet updates, or
johnc@2060 346 // * scanned for references that point into the collection set
johnc@2060 347 // and the RSet of the corresponding region in the collection set
johnc@2060 348 // is updated immediately.
johnc@2060 349 DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set());
johnc@2060 350
johnc@2063 351 assert((ParallelGCThreads > 0) || worker_i == 0, "invariant");
johnc@2063 352
johnc@2063 353 // The two flags below were introduced temporarily to serialize
johnc@2063 354 // the updating and scanning of remembered sets. There are some
johnc@2063 355 // race conditions when these two operations are done in parallel
johnc@2063 356 // and they are causing failures. When we resolve said race
johnc@2063 357 // conditions, we'll revert back to parallel remembered set
johnc@2063 358 // updating and scanning. See CRs 6677707 and 6677708.
johnc@2063 359 if (G1UseParallelRSetUpdating || (worker_i == 0)) {
johnc@2063 360 updateRS(&into_cset_dcq, worker_i);
ysr@777 361 } else {
brutisso@4015 362 _g1p->phase_times()->record_update_rs_processed_buffers(worker_i, 0);
brutisso@3923 363 _g1p->phase_times()->record_update_rs_time(worker_i, 0.0);
johnc@2063 364 }
johnc@2063 365 if (G1UseParallelRSetScanning || (worker_i == 0)) {
johnc@5548 366 scanRS(oc, code_root_cl, worker_i);
johnc@2063 367 } else {
brutisso@3923 368 _g1p->phase_times()->record_scan_rs_time(worker_i, 0.0);
ysr@777 369 }
johnc@2060 370
johnc@2060 371 // We now clear the cached values of _cset_rs_update_cl for this worker
johnc@2060 372 _cset_rs_update_cl[worker_i] = NULL;
ysr@777 373 }
ysr@777 374
johnc@2216 375 void G1RemSet::prepare_for_oops_into_collection_set_do() {
ysr@777 376 cleanupHRRS();
ysr@777 377 ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine();
ysr@777 378 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 379 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 380 dcqs.concatenate_logs();
ysr@777 381
ysr@777 382 guarantee( _cards_scanned == NULL, "invariant" );
zgu@3900 383 _cards_scanned = NEW_C_HEAP_ARRAY(size_t, n_workers(), mtGC);
apetrusenko@980 384 for (uint i = 0; i < n_workers(); ++i) {
apetrusenko@980 385 _cards_scanned[i] = 0;
apetrusenko@980 386 }
ysr@777 387 _total_cards_scanned = 0;
ysr@777 388 }
ysr@777 389
ysr@777 390
johnc@2060 391 // This closure, applied to a DirtyCardQueueSet, is used to immediately
johnc@2060 392 // update the RSets for the regions in the CSet. For each card it iterates
johnc@2060 393 // through the oops which coincide with that card. It scans the reference
johnc@2060 394 // fields in each oop; when it finds an oop that points into the collection
johnc@2060 395 // set, the RSet for the region containing the referenced object is updated.
johnc@2060 396 class UpdateRSetCardTableEntryIntoCSetClosure: public CardTableEntryClosure {
iveresov@1051 397 G1CollectedHeap* _g1;
johnc@2060 398 CardTableModRefBS* _ct_bs;
iveresov@1051 399 public:
johnc@2060 400 UpdateRSetCardTableEntryIntoCSetClosure(G1CollectedHeap* g1,
johnc@2060 401 CardTableModRefBS* bs):
johnc@2060 402 _g1(g1), _ct_bs(bs)
johnc@2060 403 { }
johnc@2060 404
vkempik@6552 405 bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
johnc@2060 406 // Construct the region representing the card.
johnc@2060 407 HeapWord* start = _ct_bs->addr_for(card_ptr);
johnc@2060 408 // And find the region containing it.
johnc@2060 409 HeapRegion* r = _g1->heap_region_containing(start);
johnc@2060 410 assert(r != NULL, "unexpected null");
johnc@2060 411
johnc@2060 412 // Scan oops in the card looking for references into the collection set
coleenp@4037 413 // Don't use addr_for(card_ptr + 1) which can ask for
coleenp@4037 414 // a card beyond the heap. This is not safe without a perm
coleenp@4037 415 // gen.
coleenp@4037 416 HeapWord* end = start + CardTableModRefBS::card_size_in_words;
johnc@2060 417 MemRegion scanRegion(start, end);
johnc@2060 418
johnc@2060 419 UpdateRSetImmediate update_rs_cl(_g1->g1_rem_set());
johnc@3179 420 FilterIntoCSClosure update_rs_cset_oop_cl(NULL, _g1, &update_rs_cl);
johnc@2060 421 FilterOutOfRegionClosure filter_then_update_rs_cset_oop_cl(r, &update_rs_cset_oop_cl);
johnc@2060 422
johnc@2060 423 // We can pass false as the "filter_young" parameter here as:
johnc@2060 424 // * we should be in a STW pause,
johnc@2060 425 // * the DCQS to which this closure is applied is used to hold
johnc@2060 426 // references that point into the collection set from the prior
johnc@2060 427 // RSet updating,
johnc@2060 428 // * the post-write barrier shouldn't be logging updates to young
johnc@2060 429 // regions (but there is a situation where this can happen - see
johnc@5078 430 // the comment in G1RemSet::refine_card() below -
johnc@2060 431 // that should not be applicable here), and
johnc@2060 432 // * during actual RSet updating, the filtering of cards in young
johnc@2060 433 // regions in HeapRegion::oops_on_card_seq_iterate_careful is
johnc@2060 434 // employed.
johnc@2060 435 // As a result, when this closure is applied to "refs into cset"
johnc@2060 436 // DCQS, we shouldn't see any cards in young regions.
johnc@2060 437 update_rs_cl.set_region(r);
johnc@2060 438 HeapWord* stop_point =
johnc@2060 439 r->oops_on_card_seq_iterate_careful(scanRegion,
tonyp@2849 440 &filter_then_update_rs_cset_oop_cl,
tonyp@2849 441 false /* filter_young */,
tonyp@2849 442 NULL /* card_ptr */);
johnc@2060 443
johnc@2060 444 // Since this is performed in the event of an evacuation failure, we
johnc@2060 445 // we shouldn't see a non-null stop point
johnc@2060 446 assert(stop_point == NULL, "saw an unallocated region");
johnc@2060 447 return true;
iveresov@1051 448 }
iveresov@1051 449 };
iveresov@1051 450
johnc@2216 451 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
ysr@777 452 guarantee( _cards_scanned != NULL, "invariant" );
ysr@777 453 _total_cards_scanned = 0;
tonyp@2974 454 for (uint i = 0; i < n_workers(); ++i) {
ysr@777 455 _total_cards_scanned += _cards_scanned[i];
tonyp@2974 456 }
zgu@3900 457 FREE_C_HEAP_ARRAY(size_t, _cards_scanned, mtGC);
ysr@777 458 _cards_scanned = NULL;
ysr@777 459 // Cleanup after copy
ysr@777 460 _g1->set_refine_cte_cl_concurrency(true);
ysr@777 461 // Set all cards back to clean.
ysr@777 462 _g1->cleanUpCardTable();
iveresov@1229 463
johnc@2060 464 DirtyCardQueueSet& into_cset_dcqs = _g1->into_cset_dirty_card_queue_set();
johnc@2060 465 int into_cset_n_buffers = into_cset_dcqs.completed_buffers_num();
johnc@2060 466
iveresov@1051 467 if (_g1->evacuation_failed()) {
tschatzl@6406 468 double restore_remembered_set_start = os::elapsedTime();
tschatzl@6406 469
johnc@2060 470 // Restore remembered sets for the regions pointing into the collection set.
iveresov@1051 471 if (G1DeferredRSUpdate) {
johnc@2060 472 // If deferred RS updates are enabled then we just need to transfer
johnc@2060 473 // the completed buffers from (a) the DirtyCardQueueSet used to hold
johnc@2060 474 // cards that contain references that point into the collection set
johnc@2060 475 // to (b) the DCQS used to hold the deferred RS updates
johnc@2060 476 _g1->dirty_card_queue_set().merge_bufferlists(&into_cset_dcqs);
iveresov@1051 477 } else {
johnc@2060 478
johnc@2060 479 CardTableModRefBS* bs = (CardTableModRefBS*)_g1->barrier_set();
johnc@2060 480 UpdateRSetCardTableEntryIntoCSetClosure update_rs_cset_immediate(_g1, bs);
johnc@2060 481
johnc@2060 482 int n_completed_buffers = 0;
johnc@2060 483 while (into_cset_dcqs.apply_closure_to_completed_buffer(&update_rs_cset_immediate,
johnc@2060 484 0, 0, true)) {
johnc@2060 485 n_completed_buffers++;
johnc@2060 486 }
johnc@2060 487 assert(n_completed_buffers == into_cset_n_buffers, "missed some buffers");
iveresov@1051 488 }
tschatzl@6406 489
tschatzl@6406 490 _g1->g1_policy()->phase_times()->record_evac_fail_restore_remsets((os::elapsedTime() - restore_remembered_set_start) * 1000.0);
iveresov@1051 491 }
johnc@2060 492
johnc@2060 493 // Free any completed buffers in the DirtyCardQueueSet used to hold cards
johnc@2060 494 // which contain references that point into the collection.
johnc@2060 495 _g1->into_cset_dirty_card_queue_set().clear();
johnc@2060 496 assert(_g1->into_cset_dirty_card_queue_set().completed_buffers_num() == 0,
johnc@2060 497 "all buffers should be freed");
johnc@2060 498 _g1->into_cset_dirty_card_queue_set().clear_n_completed_buffers();
ysr@777 499 }
ysr@777 500
ysr@777 501 class ScrubRSClosure: public HeapRegionClosure {
ysr@777 502 G1CollectedHeap* _g1h;
ysr@777 503 BitMap* _region_bm;
ysr@777 504 BitMap* _card_bm;
ysr@777 505 CardTableModRefBS* _ctbs;
ysr@777 506 public:
ysr@777 507 ScrubRSClosure(BitMap* region_bm, BitMap* card_bm) :
ysr@777 508 _g1h(G1CollectedHeap::heap()),
ysr@777 509 _region_bm(region_bm), _card_bm(card_bm),
mgerdin@5811 510 _ctbs(_g1h->g1_barrier_set()) {}
ysr@777 511
ysr@777 512 bool doHeapRegion(HeapRegion* r) {
ysr@777 513 if (!r->continuesHumongous()) {
ysr@777 514 r->rem_set()->scrub(_ctbs, _region_bm, _card_bm);
ysr@777 515 }
ysr@777 516 return false;
ysr@777 517 }
ysr@777 518 };
ysr@777 519
johnc@2216 520 void G1RemSet::scrub(BitMap* region_bm, BitMap* card_bm) {
ysr@777 521 ScrubRSClosure scrub_cl(region_bm, card_bm);
ysr@777 522 _g1->heap_region_iterate(&scrub_cl);
ysr@777 523 }
ysr@777 524
johnc@2216 525 void G1RemSet::scrub_par(BitMap* region_bm, BitMap* card_bm,
jmasa@3357 526 uint worker_num, int claim_val) {
ysr@777 527 ScrubRSClosure scrub_cl(region_bm, card_bm);
jmasa@3294 528 _g1->heap_region_par_iterate_chunked(&scrub_cl,
jmasa@3294 529 worker_num,
jmasa@3357 530 n_workers(),
jmasa@3294 531 claim_val);
ysr@777 532 }
ysr@777 533
johnc@3466 534 G1TriggerClosure::G1TriggerClosure() :
johnc@3466 535 _triggered(false) { }
johnc@2060 536
johnc@3466 537 G1InvokeIfNotTriggeredClosure::G1InvokeIfNotTriggeredClosure(G1TriggerClosure* t_cl,
johnc@3466 538 OopClosure* oop_cl) :
johnc@3466 539 _trigger_cl(t_cl), _oop_cl(oop_cl) { }
johnc@3466 540
johnc@3466 541 G1Mux2Closure::G1Mux2Closure(OopClosure *c1, OopClosure *c2) :
johnc@3466 542 _c1(c1), _c2(c2) { }
johnc@3466 543
johnc@3466 544 G1UpdateRSOrPushRefOopClosure::
johnc@3466 545 G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
johnc@3466 546 G1RemSet* rs,
johnc@3466 547 OopsInHeapRegionClosure* push_ref_cl,
johnc@3466 548 bool record_refs_into_cset,
vkempik@6552 549 uint worker_i) :
johnc@3466 550 _g1(g1h), _g1_rem_set(rs), _from(NULL),
johnc@3466 551 _record_refs_into_cset(record_refs_into_cset),
johnc@3466 552 _push_ref_cl(push_ref_cl), _worker_i(worker_i) { }
johnc@2060 553
johnc@5078 554 // Returns true if the given card contains references that point
johnc@5078 555 // into the collection set, if we're checking for such references;
johnc@5078 556 // false otherwise.
johnc@5078 557
vkempik@6552 558 bool G1RemSet::refine_card(jbyte* card_ptr, uint worker_i,
johnc@5078 559 bool check_for_refs_into_cset) {
johnc@5078 560
johnc@5078 561 // If the card is no longer dirty, nothing to do.
johnc@5078 562 if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
johnc@5078 563 // No need to return that this card contains refs that point
johnc@5078 564 // into the collection set.
johnc@5078 565 return false;
johnc@5078 566 }
johnc@5078 567
johnc@1325 568 // Construct the region representing the card.
johnc@1325 569 HeapWord* start = _ct_bs->addr_for(card_ptr);
johnc@1325 570 // And find the region containing it.
johnc@1325 571 HeapRegion* r = _g1->heap_region_containing(start);
johnc@5078 572 if (r == NULL) {
johnc@5078 573 // Again no need to return that this card contains refs that
johnc@5078 574 // point into the collection set.
johnc@5078 575 return false; // Not in the G1 heap (might be in perm, for example.)
johnc@5078 576 }
johnc@5078 577
johnc@5078 578 // Why do we have to check here whether a card is on a young region,
johnc@5078 579 // given that we dirty young regions and, as a result, the
johnc@5078 580 // post-barrier is supposed to filter them out and never to enqueue
johnc@5078 581 // them? When we allocate a new region as the "allocation region" we
johnc@5078 582 // actually dirty its cards after we release the lock, since card
johnc@5078 583 // dirtying while holding the lock was a performance bottleneck. So,
johnc@5078 584 // as a result, it is possible for other threads to actually
johnc@5078 585 // allocate objects in the region (after the acquire the lock)
johnc@5078 586 // before all the cards on the region are dirtied. This is unlikely,
johnc@5078 587 // and it doesn't happen often, but it can happen. So, the extra
johnc@5078 588 // check below filters out those cards.
johnc@5078 589 if (r->is_young()) {
johnc@5078 590 return false;
johnc@5078 591 }
johnc@5078 592
johnc@5078 593 // While we are processing RSet buffers during the collection, we
johnc@5078 594 // actually don't want to scan any cards on the collection set,
johnc@5078 595 // since we don't want to update remebered sets with entries that
johnc@5078 596 // point into the collection set, given that live objects from the
johnc@5078 597 // collection set are about to move and such entries will be stale
johnc@5078 598 // very soon. This change also deals with a reliability issue which
johnc@5078 599 // involves scanning a card in the collection set and coming across
johnc@5078 600 // an array that was being chunked and looking malformed. Note,
johnc@5078 601 // however, that if evacuation fails, we have to scan any objects
johnc@5078 602 // that were not moved and create any missing entries.
johnc@5078 603 if (r->in_collection_set()) {
johnc@5078 604 return false;
johnc@5078 605 }
johnc@5078 606
johnc@5078 607 // The result from the hot card cache insert call is either:
johnc@5078 608 // * pointer to the current card
johnc@5078 609 // (implying that the current card is not 'hot'),
johnc@5078 610 // * null
johnc@5078 611 // (meaning we had inserted the card ptr into the "hot" card cache,
johnc@5078 612 // which had some headroom),
johnc@5078 613 // * a pointer to a "hot" card that was evicted from the "hot" cache.
johnc@5078 614 //
johnc@5078 615
johnc@5078 616 G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
johnc@5078 617 if (hot_card_cache->use_cache()) {
johnc@5078 618 assert(!check_for_refs_into_cset, "sanity");
johnc@5078 619 assert(!SafepointSynchronize::is_at_safepoint(), "sanity");
johnc@5078 620
johnc@5078 621 card_ptr = hot_card_cache->insert(card_ptr);
johnc@5078 622 if (card_ptr == NULL) {
johnc@5078 623 // There was no eviction. Nothing to do.
johnc@5078 624 return false;
johnc@5078 625 }
johnc@5078 626
johnc@5078 627 start = _ct_bs->addr_for(card_ptr);
johnc@5078 628 r = _g1->heap_region_containing(start);
johnc@5078 629 if (r == NULL) {
johnc@5078 630 // Not in the G1 heap
johnc@5078 631 return false;
johnc@5078 632 }
johnc@5078 633
johnc@5078 634 // Checking whether the region we got back from the cache
johnc@5078 635 // is young here is inappropriate. The region could have been
johnc@5078 636 // freed, reallocated and tagged as young while in the cache.
johnc@5078 637 // Hence we could see its young type change at any time.
johnc@5078 638 }
johnc@1325 639
coleenp@4037 640 // Don't use addr_for(card_ptr + 1) which can ask for
coleenp@4037 641 // a card beyond the heap. This is not safe without a perm
coleenp@4037 642 // gen at the upper end of the heap.
coleenp@4037 643 HeapWord* end = start + CardTableModRefBS::card_size_in_words;
johnc@1325 644 MemRegion dirtyRegion(start, end);
johnc@1325 645
johnc@1325 646 #if CARD_REPEAT_HISTO
johnc@2504 647 init_ct_freq_table(_g1->max_capacity());
johnc@1325 648 ct_freq_note_card(_ct_bs->index_for(start));
johnc@1325 649 #endif
johnc@1325 650
brutisso@3267 651 OopsInHeapRegionClosure* oops_in_heap_closure = NULL;
brutisso@3267 652 if (check_for_refs_into_cset) {
brutisso@3267 653 // ConcurrentG1RefineThreads have worker numbers larger than what
brutisso@3267 654 // _cset_rs_update_cl[] is set up to handle. But those threads should
brutisso@3267 655 // only be active outside of a collection which means that when they
brutisso@3267 656 // reach here they should have check_for_refs_into_cset == false.
brutisso@3267 657 assert((size_t)worker_i < n_workers(), "index of worker larger than _cset_rs_update_cl[].length");
brutisso@3267 658 oops_in_heap_closure = _cset_rs_update_cl[worker_i];
brutisso@3267 659 }
johnc@3466 660 G1UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
johnc@3466 661 _g1->g1_rem_set(),
johnc@3466 662 oops_in_heap_closure,
johnc@3466 663 check_for_refs_into_cset,
johnc@3466 664 worker_i);
johnc@1325 665 update_rs_oop_cl.set_from(r);
johnc@2060 666
johnc@3466 667 G1TriggerClosure trigger_cl;
johnc@3179 668 FilterIntoCSClosure into_cs_cl(NULL, _g1, &trigger_cl);
johnc@3466 669 G1InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl);
johnc@3466 670 G1Mux2Closure mux(&invoke_cl, &update_rs_oop_cl);
johnc@2060 671
johnc@2060 672 FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r,
johnc@2060 673 (check_for_refs_into_cset ?
johnc@2060 674 (OopClosure*)&mux :
johnc@2060 675 (OopClosure*)&update_rs_oop_cl));
johnc@1325 676
johnc@2021 677 // The region for the current card may be a young region. The
johnc@2021 678 // current card may have been a card that was evicted from the
johnc@2021 679 // card cache. When the card was inserted into the cache, we had
johnc@2021 680 // determined that its region was non-young. While in the cache,
johnc@2021 681 // the region may have been freed during a cleanup pause, reallocated
johnc@2021 682 // and tagged as young.
johnc@2021 683 //
johnc@2021 684 // We wish to filter out cards for such a region but the current
tonyp@2849 685 // thread, if we're running concurrently, may "see" the young type
johnc@2021 686 // change at any time (so an earlier "is_young" check may pass or
johnc@2021 687 // fail arbitrarily). We tell the iteration code to perform this
johnc@2021 688 // filtering when it has been determined that there has been an actual
johnc@2021 689 // allocation in this region and making it safe to check the young type.
johnc@2021 690 bool filter_young = true;
johnc@2021 691
johnc@1325 692 HeapWord* stop_point =
johnc@1325 693 r->oops_on_card_seq_iterate_careful(dirtyRegion,
johnc@2021 694 &filter_then_update_rs_oop_cl,
tonyp@2849 695 filter_young,
tonyp@2849 696 card_ptr);
johnc@2021 697
johnc@1325 698 // If stop_point is non-null, then we encountered an unallocated region
johnc@1325 699 // (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the
johnc@1325 700 // card and re-enqueue: if we put off the card until a GC pause, then the
johnc@1325 701 // unallocated portion will be filled in. Alternatively, we might try
johnc@1325 702 // the full complexity of the technique used in "regular" precleaning.
johnc@1325 703 if (stop_point != NULL) {
johnc@1325 704 // The card might have gotten re-dirtied and re-enqueued while we
johnc@1325 705 // worked. (In fact, it's pretty likely.)
johnc@1325 706 if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
johnc@1325 707 *card_ptr = CardTableModRefBS::dirty_card_val();
johnc@1325 708 MutexLockerEx x(Shared_DirtyCardQ_lock,
johnc@1325 709 Mutex::_no_safepoint_check_flag);
johnc@1325 710 DirtyCardQueue* sdcq =
johnc@1325 711 JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
johnc@1325 712 sdcq->enqueue(card_ptr);
johnc@1325 713 }
johnc@1325 714 } else {
johnc@1325 715 _conc_refine_cards++;
johnc@1325 716 }
johnc@2060 717
johnc@5078 718 // This gets set to true if the card being refined has
johnc@5078 719 // references that point into the collection set.
johnc@5078 720 bool has_refs_into_cset = trigger_cl.triggered();
johnc@1325 721
johnc@5078 722 // We should only be detecting that the card contains references
johnc@5078 723 // that point into the collection set if the current thread is
johnc@5078 724 // a GC worker thread.
johnc@5078 725 assert(!has_refs_into_cset || SafepointSynchronize::is_at_safepoint(),
johnc@5078 726 "invalid result at non safepoint");
ysr@777 727
johnc@5078 728 return has_refs_into_cset;
ysr@777 729 }
ysr@777 730
tschatzl@5807 731 void G1RemSet::print_periodic_summary_info(const char* header) {
tschatzl@5204 732 G1RemSetSummary current;
tschatzl@5812 733 current.initialize(this);
ysr@777 734
tschatzl@5204 735 _prev_period_summary.subtract_from(&current);
tschatzl@5807 736 print_summary_info(&_prev_period_summary, header);
ysr@777 737
tschatzl@5204 738 _prev_period_summary.set(&current);
tschatzl@5204 739 }
iveresov@1229 740
johnc@2216 741 void G1RemSet::print_summary_info() {
tschatzl@5204 742 G1RemSetSummary current;
tschatzl@5812 743 current.initialize(this);
tschatzl@5204 744
tschatzl@5204 745 print_summary_info(&current, " Cumulative RS summary");
tschatzl@5204 746 }
tschatzl@5204 747
tschatzl@5204 748 void G1RemSet::print_summary_info(G1RemSetSummary * summary, const char * header) {
tschatzl@5204 749 assert(summary != NULL, "just checking");
tschatzl@5204 750
tschatzl@5204 751 if (header != NULL) {
tschatzl@5204 752 gclog_or_tty->print_cr("%s", header);
tschatzl@5204 753 }
ysr@777 754
ysr@777 755 #if CARD_REPEAT_HISTO
ysr@777 756 gclog_or_tty->print_cr("\nG1 card_repeat count histogram: ");
ysr@777 757 gclog_or_tty->print_cr(" # of repeats --> # of cards with that number.");
ysr@777 758 card_repeat_count.print_on(gclog_or_tty);
ysr@777 759 #endif
ysr@777 760
tschatzl@5204 761 summary->print_on(gclog_or_tty);
ysr@777 762 }
johnc@2060 763
johnc@2216 764 void G1RemSet::prepare_for_verify() {
iveresov@1072 765 if (G1HRRSFlushLogBuffersOnVerify &&
iveresov@1072 766 (VerifyBeforeGC || VerifyAfterGC)
johnc@5205 767 && (!_g1->full_collection() || G1VerifyRSetsDuringFullGC)) {
ysr@777 768 cleanupHRRS();
ysr@777 769 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 770 if (SafepointSynchronize::is_at_safepoint()) {
ysr@777 771 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 772 dcqs.concatenate_logs();
ysr@777 773 }
johnc@5078 774
johnc@5078 775 G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
johnc@5078 776 bool use_hot_card_cache = hot_card_cache->use_cache();
johnc@5078 777 hot_card_cache->set_use_cache(false);
johnc@5078 778
johnc@2060 779 DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set());
johnc@2060 780 updateRS(&into_cset_dcq, 0);
johnc@2060 781 _g1->into_cset_dirty_card_queue_set().clear();
iveresov@1072 782
johnc@5078 783 hot_card_cache->set_use_cache(use_hot_card_cache);
iveresov@1072 784 assert(JavaThread::dirty_card_queue_set().completed_buffers_num() == 0, "All should be consumed");
ysr@777 785 }
ysr@777 786 }

mercurial