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

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8280
f3f2f71d2dc8
parent 7994
04ff2f6cd0eb
child 9448
73d689add964
permissions
-rw-r--r--

Merge

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

mercurial