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

Mon, 08 Dec 2014 18:57:33 +0100

author
mgerdin
date
Mon, 08 Dec 2014 18:57:33 +0100
changeset 7971
b554c7fa9478
parent 7218
6948da6d7c13
child 7972
a9b72f566e9f
permissions
-rw-r--r--

8067655: Clean up G1 remembered set oop iteration
Summary: Pass on the static type G1ParPushHeapRSClosure to allow oop_iterate devirtualization
Reviewed-by: jmasa, kbarrett

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

mercurial