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

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2302
878b57474103
child 2504
c33825b68624
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

ysr@777 1 /*
johnc@2021 2 * Copyright (c) 2001, 2010, 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"
stefank@2314 32 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@2314 33 #include "gc_implementation/g1/g1RemSet.inline.hpp"
stefank@2314 34 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@2314 35 #include "memory/iterator.hpp"
stefank@2314 36 #include "oops/oop.inline.hpp"
stefank@2314 37 #include "utilities/intHisto.hpp"
ysr@777 38
ysr@777 39 #define CARD_REPEAT_HISTO 0
ysr@777 40
ysr@777 41 #if CARD_REPEAT_HISTO
ysr@777 42 static size_t ct_freq_sz;
ysr@777 43 static jbyte* ct_freq = NULL;
ysr@777 44
ysr@777 45 void init_ct_freq_table(size_t heap_sz_bytes) {
ysr@777 46 if (ct_freq == NULL) {
ysr@777 47 ct_freq_sz = heap_sz_bytes/CardTableModRefBS::card_size;
ysr@777 48 ct_freq = new jbyte[ct_freq_sz];
ysr@777 49 for (size_t j = 0; j < ct_freq_sz; j++) ct_freq[j] = 0;
ysr@777 50 }
ysr@777 51 }
ysr@777 52
ysr@777 53 void ct_freq_note_card(size_t index) {
ysr@777 54 assert(0 <= index && index < ct_freq_sz, "Bounds error.");
ysr@777 55 if (ct_freq[index] < 100) { ct_freq[index]++; }
ysr@777 56 }
ysr@777 57
ysr@777 58 static IntHistogram card_repeat_count(10, 10);
ysr@777 59
ysr@777 60 void ct_freq_update_histo_and_reset() {
ysr@777 61 for (size_t j = 0; j < ct_freq_sz; j++) {
ysr@777 62 card_repeat_count.add_entry(ct_freq[j]);
ysr@777 63 ct_freq[j] = 0;
ysr@777 64 }
ysr@777 65
ysr@777 66 }
ysr@777 67 #endif
ysr@777 68
ysr@777 69
ysr@777 70 class IntoCSOopClosure: public OopsInHeapRegionClosure {
ysr@777 71 OopsInHeapRegionClosure* _blk;
ysr@777 72 G1CollectedHeap* _g1;
ysr@777 73 public:
ysr@777 74 IntoCSOopClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) :
ysr@777 75 _g1(g1), _blk(blk) {}
ysr@777 76 void set_region(HeapRegion* from) {
ysr@777 77 _blk->set_region(from);
ysr@777 78 }
ysr@1280 79 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@1280 80 virtual void do_oop( oop* p) { do_oop_work(p); }
ysr@1280 81 template <class T> void do_oop_work(T* p) {
ysr@1280 82 oop obj = oopDesc::load_decode_heap_oop(p);
ysr@777 83 if (_g1->obj_in_cs(obj)) _blk->do_oop(p);
ysr@777 84 }
ysr@777 85 bool apply_to_weak_ref_discovered_field() { return true; }
ysr@777 86 bool idempotent() { return true; }
ysr@777 87 };
ysr@777 88
ysr@777 89 class IntoCSRegionClosure: public HeapRegionClosure {
ysr@777 90 IntoCSOopClosure _blk;
ysr@777 91 G1CollectedHeap* _g1;
ysr@777 92 public:
ysr@777 93 IntoCSRegionClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) :
ysr@777 94 _g1(g1), _blk(g1, blk) {}
ysr@777 95 bool doHeapRegion(HeapRegion* r) {
ysr@777 96 if (!r->in_collection_set()) {
ysr@777 97 _blk.set_region(r);
ysr@777 98 if (r->isHumongous()) {
ysr@777 99 if (r->startsHumongous()) {
ysr@777 100 oop obj = oop(r->bottom());
ysr@777 101 obj->oop_iterate(&_blk);
ysr@777 102 }
ysr@777 103 } else {
ysr@777 104 r->oop_before_save_marks_iterate(&_blk);
ysr@777 105 }
ysr@777 106 }
ysr@777 107 return false;
ysr@777 108 }
ysr@777 109 };
ysr@777 110
ysr@777 111 class VerifyRSCleanCardOopClosure: public OopClosure {
ysr@777 112 G1CollectedHeap* _g1;
ysr@777 113 public:
ysr@777 114 VerifyRSCleanCardOopClosure(G1CollectedHeap* g1) : _g1(g1) {}
ysr@777 115
ysr@1280 116 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
ysr@1280 117 virtual void do_oop( oop* p) { do_oop_work(p); }
ysr@1280 118 template <class T> void do_oop_work(T* p) {
ysr@1280 119 oop obj = oopDesc::load_decode_heap_oop(p);
ysr@777 120 HeapRegion* to = _g1->heap_region_containing(obj);
ysr@777 121 guarantee(to == NULL || !to->in_collection_set(),
ysr@777 122 "Missed a rem set member.");
ysr@777 123 }
ysr@777 124 };
ysr@777 125
johnc@2216 126 G1RemSet::G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs)
johnc@2216 127 : _g1(g1), _conc_refine_cards(0),
johnc@2216 128 _ct_bs(ct_bs), _g1p(_g1->g1_policy()),
ysr@777 129 _cg1r(g1->concurrent_g1_refine()),
johnc@2060 130 _cset_rs_update_cl(NULL),
ysr@777 131 _cards_scanned(NULL), _total_cards_scanned(0)
ysr@777 132 {
ysr@777 133 _seq_task = new SubTasksDone(NumSeqTasks);
iveresov@1051 134 guarantee(n_workers() > 0, "There should be some workers");
johnc@2060 135 _cset_rs_update_cl = NEW_C_HEAP_ARRAY(OopsInHeapRegionClosure*, n_workers());
iveresov@1051 136 for (uint i = 0; i < n_workers(); i++) {
johnc@2060 137 _cset_rs_update_cl[i] = NULL;
iveresov@1051 138 }
ysr@777 139 }
ysr@777 140
johnc@2216 141 G1RemSet::~G1RemSet() {
ysr@777 142 delete _seq_task;
iveresov@1051 143 for (uint i = 0; i < n_workers(); i++) {
johnc@2060 144 assert(_cset_rs_update_cl[i] == NULL, "it should be");
iveresov@1051 145 }
johnc@2060 146 FREE_C_HEAP_ARRAY(OopsInHeapRegionClosure*, _cset_rs_update_cl);
ysr@777 147 }
ysr@777 148
ysr@777 149 void CountNonCleanMemRegionClosure::do_MemRegion(MemRegion mr) {
ysr@777 150 if (_g1->is_in_g1_reserved(mr.start())) {
ysr@777 151 _n += (int) ((mr.byte_size() / CardTableModRefBS::card_size));
ysr@777 152 if (_start_first == NULL) _start_first = mr.start();
ysr@777 153 }
ysr@777 154 }
ysr@777 155
ysr@777 156 class ScanRSClosure : public HeapRegionClosure {
ysr@777 157 size_t _cards_done, _cards;
ysr@777 158 G1CollectedHeap* _g1h;
ysr@777 159 OopsInHeapRegionClosure* _oc;
ysr@777 160 G1BlockOffsetSharedArray* _bot_shared;
ysr@777 161 CardTableModRefBS *_ct_bs;
ysr@777 162 int _worker_i;
iveresov@1696 163 int _block_size;
ysr@777 164 bool _try_claimed;
ysr@777 165 public:
ysr@777 166 ScanRSClosure(OopsInHeapRegionClosure* oc, int worker_i) :
ysr@777 167 _oc(oc),
ysr@777 168 _cards(0),
ysr@777 169 _cards_done(0),
ysr@777 170 _worker_i(worker_i),
ysr@777 171 _try_claimed(false)
ysr@777 172 {
ysr@777 173 _g1h = G1CollectedHeap::heap();
ysr@777 174 _bot_shared = _g1h->bot_shared();
ysr@777 175 _ct_bs = (CardTableModRefBS*) (_g1h->barrier_set());
iveresov@1696 176 _block_size = MAX2<int>(G1RSetScanBlockSize, 1);
ysr@777 177 }
ysr@777 178
ysr@777 179 void set_try_claimed() { _try_claimed = true; }
ysr@777 180
ysr@777 181 void scanCard(size_t index, HeapRegion *r) {
ysr@777 182 _cards_done++;
ysr@777 183 DirtyCardToOopClosure* cl =
ysr@777 184 r->new_dcto_closure(_oc,
ysr@777 185 CardTableModRefBS::Precise,
ysr@777 186 HeapRegionDCTOC::IntoCSFilterKind);
ysr@777 187
ysr@777 188 // Set the "from" region in the closure.
ysr@777 189 _oc->set_region(r);
ysr@777 190 HeapWord* card_start = _bot_shared->address_for_index(index);
ysr@777 191 HeapWord* card_end = card_start + G1BlockOffsetSharedArray::N_words;
ysr@777 192 Space *sp = SharedHeap::heap()->space_containing(card_start);
ysr@777 193 MemRegion sm_region;
ysr@777 194 if (ParallelGCThreads > 0) {
ysr@777 195 // first find the used area
ysr@777 196 sm_region = sp->used_region_at_save_marks();
ysr@777 197 } else {
ysr@777 198 // The closure is not idempotent. We shouldn't look at objects
ysr@777 199 // allocated during the GC.
ysr@777 200 sm_region = sp->used_region_at_save_marks();
ysr@777 201 }
ysr@777 202 MemRegion mr = sm_region.intersection(MemRegion(card_start,card_end));
ysr@777 203 if (!mr.is_empty()) {
ysr@777 204 cl->do_MemRegion(mr);
ysr@777 205 }
ysr@777 206 }
ysr@777 207
ysr@777 208 void printCard(HeapRegion* card_region, size_t card_index,
ysr@777 209 HeapWord* card_start) {
ysr@777 210 gclog_or_tty->print_cr("T %d Region [" PTR_FORMAT ", " PTR_FORMAT ") "
ysr@777 211 "RS names card %p: "
ysr@777 212 "[" PTR_FORMAT ", " PTR_FORMAT ")",
ysr@777 213 _worker_i,
ysr@777 214 card_region->bottom(), card_region->end(),
ysr@777 215 card_index,
ysr@777 216 card_start, card_start + G1BlockOffsetSharedArray::N_words);
ysr@777 217 }
ysr@777 218
ysr@777 219 bool doHeapRegion(HeapRegion* r) {
ysr@777 220 assert(r->in_collection_set(), "should only be called on elements of CS.");
ysr@777 221 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 222 if (hrrs->iter_is_complete()) return false; // All done.
ysr@777 223 if (!_try_claimed && !hrrs->claim_iter()) return false;
apetrusenko@1231 224 _g1h->push_dirty_cards_region(r);
ysr@777 225 // If we didn't return above, then
ysr@777 226 // _try_claimed || r->claim_iter()
ysr@777 227 // is true: either we're supposed to work on claimed-but-not-complete
ysr@777 228 // regions, or we successfully claimed the region.
ysr@777 229 HeapRegionRemSetIterator* iter = _g1h->rem_set_iterator(_worker_i);
ysr@777 230 hrrs->init_iterator(iter);
ysr@777 231 size_t card_index;
iveresov@1696 232
iveresov@1696 233 // We claim cards in block so as to recude the contention. The block size is determined by
iveresov@1696 234 // the G1RSetScanBlockSize parameter.
iveresov@1696 235 size_t jump_to_card = hrrs->iter_claimed_next(_block_size);
iveresov@1696 236 for (size_t current_card = 0; iter->has_next(card_index); current_card++) {
iveresov@1696 237 if (current_card >= jump_to_card + _block_size) {
iveresov@1696 238 jump_to_card = hrrs->iter_claimed_next(_block_size);
iveresov@1182 239 }
iveresov@1696 240 if (current_card < jump_to_card) continue;
ysr@777 241 HeapWord* card_start = _g1h->bot_shared()->address_for_index(card_index);
ysr@777 242 #if 0
ysr@777 243 gclog_or_tty->print("Rem set iteration yielded card [" PTR_FORMAT ", " PTR_FORMAT ").\n",
ysr@777 244 card_start, card_start + CardTableModRefBS::card_size_in_words);
ysr@777 245 #endif
ysr@777 246
ysr@777 247 HeapRegion* card_region = _g1h->heap_region_containing(card_start);
ysr@777 248 assert(card_region != NULL, "Yielding cards not in the heap?");
ysr@777 249 _cards++;
ysr@777 250
apetrusenko@1231 251 if (!card_region->is_on_dirty_cards_region_list()) {
apetrusenko@1231 252 _g1h->push_dirty_cards_region(card_region);
apetrusenko@1231 253 }
apetrusenko@1231 254
iveresov@1182 255 // If the card is dirty, then we will scan it during updateRS.
iveresov@1182 256 if (!card_region->in_collection_set() && !_ct_bs->is_card_dirty(card_index)) {
iveresov@1696 257 // We make the card as "claimed" lazily (so races are possible but they're benign),
iveresov@1696 258 // which reduces the number of duplicate scans (the rsets of the regions in the cset
iveresov@1696 259 // can intersect).
iveresov@1696 260 if (!_ct_bs->is_card_claimed(card_index)) {
iveresov@1696 261 _ct_bs->set_card_claimed(card_index);
iveresov@1696 262 scanCard(card_index, card_region);
iveresov@1696 263 }
ysr@777 264 }
ysr@777 265 }
iveresov@1182 266 if (!_try_claimed) {
iveresov@1182 267 hrrs->set_iter_complete();
iveresov@1182 268 }
ysr@777 269 return false;
ysr@777 270 }
ysr@777 271 // Set all cards back to clean.
ysr@777 272 void cleanup() {_g1h->cleanUpCardTable();}
ysr@777 273 size_t cards_done() { return _cards_done;}
ysr@777 274 size_t cards_looked_up() { return _cards;}
ysr@777 275 };
ysr@777 276
ysr@777 277 // We want the parallel threads to start their scanning at
ysr@777 278 // different collection set regions to avoid contention.
ysr@777 279 // If we have:
ysr@777 280 // n collection set regions
ysr@777 281 // p threads
ysr@777 282 // Then thread t will start at region t * floor (n/p)
ysr@777 283
johnc@2216 284 HeapRegion* G1RemSet::calculateStartRegion(int worker_i) {
ysr@777 285 HeapRegion* result = _g1p->collection_set();
ysr@777 286 if (ParallelGCThreads > 0) {
ysr@777 287 size_t cs_size = _g1p->collection_set_size();
ysr@777 288 int n_workers = _g1->workers()->total_workers();
ysr@777 289 size_t cs_spans = cs_size / n_workers;
ysr@777 290 size_t ind = cs_spans * worker_i;
ysr@777 291 for (size_t i = 0; i < ind; i++)
ysr@777 292 result = result->next_in_collection_set();
ysr@777 293 }
ysr@777 294 return result;
ysr@777 295 }
ysr@777 296
johnc@2216 297 void G1RemSet::scanRS(OopsInHeapRegionClosure* oc, int worker_i) {
ysr@777 298 double rs_time_start = os::elapsedTime();
ysr@777 299 HeapRegion *startRegion = calculateStartRegion(worker_i);
ysr@777 300
iveresov@1696 301 ScanRSClosure scanRScl(oc, worker_i);
ysr@777 302 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 303 scanRScl.set_try_claimed();
ysr@777 304 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 305
iveresov@1696 306 double scan_rs_time_sec = os::elapsedTime() - rs_time_start;
ysr@777 307
ysr@777 308 assert( _cards_scanned != NULL, "invariant" );
ysr@777 309 _cards_scanned[worker_i] = scanRScl.cards_done();
ysr@777 310
ysr@777 311 _g1p->record_scan_rs_time(worker_i, scan_rs_time_sec * 1000.0);
ysr@777 312 }
ysr@777 313
johnc@2060 314 // Closure used for updating RSets and recording references that
johnc@2060 315 // point into the collection set. Only called during an
johnc@2060 316 // evacuation pause.
ysr@777 317
johnc@2060 318 class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure {
johnc@2060 319 G1RemSet* _g1rs;
johnc@2060 320 DirtyCardQueue* _into_cset_dcq;
johnc@2060 321 public:
johnc@2060 322 RefineRecordRefsIntoCSCardTableEntryClosure(G1CollectedHeap* g1h,
johnc@2060 323 DirtyCardQueue* into_cset_dcq) :
johnc@2060 324 _g1rs(g1h->g1_rem_set()), _into_cset_dcq(into_cset_dcq)
johnc@2060 325 {}
johnc@2060 326 bool do_card_ptr(jbyte* card_ptr, int worker_i) {
johnc@2060 327 // The only time we care about recording cards that
johnc@2060 328 // contain references that point into the collection set
johnc@2060 329 // is during RSet updating within an evacuation pause.
johnc@2060 330 // In this case worker_i should be the id of a GC worker thread.
johnc@2060 331 assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
johnc@2060 332 assert(worker_i < (int) DirtyCardQueueSet::num_par_ids(), "should be a GC worker");
johnc@2060 333
johnc@2060 334 if (_g1rs->concurrentRefineOneCard(card_ptr, worker_i, true)) {
johnc@2060 335 // 'card_ptr' contains references that point into the collection
johnc@2060 336 // set. We need to record the card in the DCQS
johnc@2060 337 // (G1CollectedHeap::into_cset_dirty_card_queue_set())
johnc@2060 338 // that's used for that purpose.
johnc@2060 339 //
johnc@2060 340 // Enqueue the card
johnc@2060 341 _into_cset_dcq->enqueue(card_ptr);
johnc@2060 342 }
johnc@2060 343 return true;
johnc@2060 344 }
johnc@2060 345 };
johnc@2060 346
johnc@2216 347 void G1RemSet::updateRS(DirtyCardQueue* into_cset_dcq, int worker_i) {
ysr@777 348 double start = os::elapsedTime();
johnc@2060 349 // Apply the given closure to all remaining log entries.
johnc@2060 350 RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq);
johnc@2060 351 _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, into_cset_dcq, false, worker_i);
johnc@2060 352
iveresov@1229 353 // Now there should be no dirty cards.
iveresov@1229 354 if (G1RSLogCheckCardTable) {
iveresov@1229 355 CountNonCleanMemRegionClosure cl(_g1);
iveresov@1229 356 _ct_bs->mod_card_iterate(&cl);
iveresov@1229 357 // XXX This isn't true any more: keeping cards of young regions
iveresov@1229 358 // marked dirty broke it. Need some reasonable fix.
iveresov@1229 359 guarantee(cl.n() == 0, "Card table should be clean.");
ysr@777 360 }
iveresov@1229 361
ysr@777 362 _g1p->record_update_rs_time(worker_i, (os::elapsedTime() - start) * 1000.0);
ysr@777 363 }
ysr@777 364
ysr@777 365 #ifndef PRODUCT
ysr@777 366 class PrintRSClosure : public HeapRegionClosure {
ysr@777 367 int _count;
ysr@777 368 public:
ysr@777 369 PrintRSClosure() : _count(0) {}
ysr@777 370 bool doHeapRegion(HeapRegion* r) {
ysr@777 371 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 372 _count += (int) hrrs->occupied();
ysr@777 373 if (hrrs->occupied() == 0) {
ysr@777 374 gclog_or_tty->print("Heap Region [" PTR_FORMAT ", " PTR_FORMAT ") "
ysr@777 375 "has no remset entries\n",
ysr@777 376 r->bottom(), r->end());
ysr@777 377 } else {
ysr@777 378 gclog_or_tty->print("Printing rem set for heap region [" PTR_FORMAT ", " PTR_FORMAT ")\n",
ysr@777 379 r->bottom(), r->end());
ysr@777 380 r->print();
ysr@777 381 hrrs->print();
ysr@777 382 gclog_or_tty->print("\nDone printing rem set\n");
ysr@777 383 }
ysr@777 384 return false;
ysr@777 385 }
ysr@777 386 int occupied() {return _count;}
ysr@777 387 };
ysr@777 388 #endif
ysr@777 389
ysr@777 390 class CountRSSizeClosure: public HeapRegionClosure {
ysr@777 391 size_t _n;
ysr@777 392 size_t _tot;
ysr@777 393 size_t _max;
ysr@777 394 HeapRegion* _max_r;
ysr@777 395 enum {
ysr@777 396 N = 20,
ysr@777 397 MIN = 6
ysr@777 398 };
ysr@777 399 int _histo[N];
ysr@777 400 public:
ysr@777 401 CountRSSizeClosure() : _n(0), _tot(0), _max(0), _max_r(NULL) {
ysr@777 402 for (int i = 0; i < N; i++) _histo[i] = 0;
ysr@777 403 }
ysr@777 404 bool doHeapRegion(HeapRegion* r) {
ysr@777 405 if (!r->continuesHumongous()) {
ysr@777 406 size_t occ = r->rem_set()->occupied();
ysr@777 407 _n++;
ysr@777 408 _tot += occ;
ysr@777 409 if (occ > _max) {
ysr@777 410 _max = occ;
ysr@777 411 _max_r = r;
ysr@777 412 }
ysr@777 413 // Fit it into a histo bin.
ysr@777 414 int s = 1 << MIN;
ysr@777 415 int i = 0;
ysr@777 416 while (occ > (size_t) s && i < (N-1)) {
ysr@777 417 s = s << 1;
ysr@777 418 i++;
ysr@777 419 }
ysr@777 420 _histo[i]++;
ysr@777 421 }
ysr@777 422 return false;
ysr@777 423 }
ysr@777 424 size_t n() { return _n; }
ysr@777 425 size_t tot() { return _tot; }
ysr@777 426 size_t mx() { return _max; }
ysr@777 427 HeapRegion* mxr() { return _max_r; }
ysr@777 428 void print_histo() {
ysr@777 429 int mx = N;
ysr@777 430 while (mx >= 0) {
ysr@777 431 if (_histo[mx-1] > 0) break;
ysr@777 432 mx--;
ysr@777 433 }
ysr@777 434 gclog_or_tty->print_cr("Number of regions with given RS sizes:");
ysr@777 435 gclog_or_tty->print_cr(" <= %8d %8d", 1 << MIN, _histo[0]);
ysr@777 436 for (int i = 1; i < mx-1; i++) {
ysr@777 437 gclog_or_tty->print_cr(" %8d - %8d %8d",
ysr@777 438 (1 << (MIN + i - 1)) + 1,
ysr@777 439 1 << (MIN + i),
ysr@777 440 _histo[i]);
ysr@777 441 }
ysr@777 442 gclog_or_tty->print_cr(" > %8d %8d", (1 << (MIN+mx-2))+1, _histo[mx-1]);
ysr@777 443 }
ysr@777 444 };
ysr@777 445
johnc@2216 446 void G1RemSet::cleanupHRRS() {
ysr@777 447 HeapRegionRemSet::cleanup();
ysr@777 448 }
ysr@777 449
johnc@2216 450 void G1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc,
ysr@777 451 int worker_i) {
ysr@777 452 #if CARD_REPEAT_HISTO
ysr@777 453 ct_freq_update_histo_and_reset();
ysr@777 454 #endif
ysr@777 455 if (worker_i == 0) {
ysr@777 456 _cg1r->clear_and_record_card_counts();
ysr@777 457 }
ysr@777 458
ysr@777 459 // Make this into a command-line flag...
ysr@777 460 if (G1RSCountHisto && (ParallelGCThreads == 0 || worker_i == 0)) {
ysr@777 461 CountRSSizeClosure count_cl;
ysr@777 462 _g1->heap_region_iterate(&count_cl);
ysr@777 463 gclog_or_tty->print_cr("Avg of %d RS counts is %f, max is %d, "
ysr@777 464 "max region is " PTR_FORMAT,
ysr@777 465 count_cl.n(), (float)count_cl.tot()/(float)count_cl.n(),
ysr@777 466 count_cl.mx(), count_cl.mxr());
ysr@777 467 count_cl.print_histo();
ysr@777 468 }
ysr@777 469
johnc@2060 470 // We cache the value of 'oc' closure into the appropriate slot in the
johnc@2060 471 // _cset_rs_update_cl for this worker
johnc@2060 472 assert(worker_i < (int)n_workers(), "sanity");
johnc@2060 473 _cset_rs_update_cl[worker_i] = oc;
johnc@2060 474
johnc@2060 475 // A DirtyCardQueue that is used to hold cards containing references
johnc@2060 476 // that point into the collection set. This DCQ is associated with a
johnc@2060 477 // special DirtyCardQueueSet (see g1CollectedHeap.hpp). Under normal
johnc@2060 478 // circumstances (i.e. the pause successfully completes), these cards
johnc@2060 479 // are just discarded (there's no need to update the RSets of regions
johnc@2060 480 // that were in the collection set - after the pause these regions
johnc@2060 481 // are wholly 'free' of live objects. In the event of an evacuation
johnc@2060 482 // failure the cards/buffers in this queue set are:
johnc@2060 483 // * passed to the DirtyCardQueueSet that is used to manage deferred
johnc@2060 484 // RSet updates, or
johnc@2060 485 // * scanned for references that point into the collection set
johnc@2060 486 // and the RSet of the corresponding region in the collection set
johnc@2060 487 // is updated immediately.
johnc@2060 488 DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set());
johnc@2060 489
johnc@2063 490 assert((ParallelGCThreads > 0) || worker_i == 0, "invariant");
johnc@2063 491
johnc@2063 492 // The two flags below were introduced temporarily to serialize
johnc@2063 493 // the updating and scanning of remembered sets. There are some
johnc@2063 494 // race conditions when these two operations are done in parallel
johnc@2063 495 // and they are causing failures. When we resolve said race
johnc@2063 496 // conditions, we'll revert back to parallel remembered set
johnc@2063 497 // updating and scanning. See CRs 6677707 and 6677708.
johnc@2063 498 if (G1UseParallelRSetUpdating || (worker_i == 0)) {
johnc@2063 499 updateRS(&into_cset_dcq, worker_i);
ysr@777 500 } else {
johnc@2063 501 _g1p->record_update_rs_processed_buffers(worker_i, 0.0);
johnc@2063 502 _g1p->record_update_rs_time(worker_i, 0.0);
johnc@2063 503 }
johnc@2063 504 if (G1UseParallelRSetScanning || (worker_i == 0)) {
johnc@2063 505 scanRS(oc, worker_i);
johnc@2063 506 } else {
johnc@2063 507 _g1p->record_scan_rs_time(worker_i, 0.0);
ysr@777 508 }
johnc@2060 509
johnc@2060 510 // We now clear the cached values of _cset_rs_update_cl for this worker
johnc@2060 511 _cset_rs_update_cl[worker_i] = NULL;
ysr@777 512 }
ysr@777 513
johnc@2216 514 void G1RemSet::prepare_for_oops_into_collection_set_do() {
ysr@777 515 #if G1_REM_SET_LOGGING
ysr@777 516 PrintRSClosure cl;
ysr@777 517 _g1->collection_set_iterate(&cl);
ysr@777 518 #endif
ysr@777 519 cleanupHRRS();
ysr@777 520 ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine();
ysr@777 521 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 522 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 523 dcqs.concatenate_logs();
ysr@777 524
ysr@777 525 if (ParallelGCThreads > 0) {
jmasa@2188 526 _seq_task->set_n_threads((int)n_workers());
ysr@777 527 }
ysr@777 528 guarantee( _cards_scanned == NULL, "invariant" );
ysr@777 529 _cards_scanned = NEW_C_HEAP_ARRAY(size_t, n_workers());
apetrusenko@980 530 for (uint i = 0; i < n_workers(); ++i) {
apetrusenko@980 531 _cards_scanned[i] = 0;
apetrusenko@980 532 }
ysr@777 533 _total_cards_scanned = 0;
ysr@777 534 }
ysr@777 535
ysr@777 536
ysr@777 537 class cleanUpIteratorsClosure : public HeapRegionClosure {
ysr@777 538 bool doHeapRegion(HeapRegion *r) {
ysr@777 539 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 540 hrrs->init_for_par_iteration();
ysr@777 541 return false;
ysr@777 542 }
ysr@777 543 };
ysr@777 544
johnc@2060 545 // This closure, applied to a DirtyCardQueueSet, is used to immediately
johnc@2060 546 // update the RSets for the regions in the CSet. For each card it iterates
johnc@2060 547 // through the oops which coincide with that card. It scans the reference
johnc@2060 548 // fields in each oop; when it finds an oop that points into the collection
johnc@2060 549 // set, the RSet for the region containing the referenced object is updated.
johnc@2060 550 class UpdateRSetCardTableEntryIntoCSetClosure: public CardTableEntryClosure {
iveresov@1051 551 G1CollectedHeap* _g1;
johnc@2060 552 CardTableModRefBS* _ct_bs;
iveresov@1051 553 public:
johnc@2060 554 UpdateRSetCardTableEntryIntoCSetClosure(G1CollectedHeap* g1,
johnc@2060 555 CardTableModRefBS* bs):
johnc@2060 556 _g1(g1), _ct_bs(bs)
johnc@2060 557 { }
johnc@2060 558
johnc@2060 559 bool do_card_ptr(jbyte* card_ptr, int worker_i) {
johnc@2060 560 // Construct the region representing the card.
johnc@2060 561 HeapWord* start = _ct_bs->addr_for(card_ptr);
johnc@2060 562 // And find the region containing it.
johnc@2060 563 HeapRegion* r = _g1->heap_region_containing(start);
johnc@2060 564 assert(r != NULL, "unexpected null");
johnc@2060 565
johnc@2060 566 // Scan oops in the card looking for references into the collection set
johnc@2060 567 HeapWord* end = _ct_bs->addr_for(card_ptr + 1);
johnc@2060 568 MemRegion scanRegion(start, end);
johnc@2060 569
johnc@2060 570 UpdateRSetImmediate update_rs_cl(_g1->g1_rem_set());
johnc@2060 571 FilterIntoCSClosure update_rs_cset_oop_cl(NULL, _g1, &update_rs_cl);
johnc@2060 572 FilterOutOfRegionClosure filter_then_update_rs_cset_oop_cl(r, &update_rs_cset_oop_cl);
johnc@2060 573
johnc@2060 574 // We can pass false as the "filter_young" parameter here as:
johnc@2060 575 // * we should be in a STW pause,
johnc@2060 576 // * the DCQS to which this closure is applied is used to hold
johnc@2060 577 // references that point into the collection set from the prior
johnc@2060 578 // RSet updating,
johnc@2060 579 // * the post-write barrier shouldn't be logging updates to young
johnc@2060 580 // regions (but there is a situation where this can happen - see
johnc@2216 581 // the comment in G1RemSet::concurrentRefineOneCard below -
johnc@2060 582 // that should not be applicable here), and
johnc@2060 583 // * during actual RSet updating, the filtering of cards in young
johnc@2060 584 // regions in HeapRegion::oops_on_card_seq_iterate_careful is
johnc@2060 585 // employed.
johnc@2060 586 // As a result, when this closure is applied to "refs into cset"
johnc@2060 587 // DCQS, we shouldn't see any cards in young regions.
johnc@2060 588 update_rs_cl.set_region(r);
johnc@2060 589 HeapWord* stop_point =
johnc@2060 590 r->oops_on_card_seq_iterate_careful(scanRegion,
johnc@2060 591 &filter_then_update_rs_cset_oop_cl,
johnc@2060 592 false /* filter_young */);
johnc@2060 593
johnc@2060 594 // Since this is performed in the event of an evacuation failure, we
johnc@2060 595 // we shouldn't see a non-null stop point
johnc@2060 596 assert(stop_point == NULL, "saw an unallocated region");
johnc@2060 597 return true;
iveresov@1051 598 }
iveresov@1051 599 };
iveresov@1051 600
johnc@2216 601 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
ysr@777 602 guarantee( _cards_scanned != NULL, "invariant" );
ysr@777 603 _total_cards_scanned = 0;
ysr@777 604 for (uint i = 0; i < n_workers(); ++i)
ysr@777 605 _total_cards_scanned += _cards_scanned[i];
ysr@777 606 FREE_C_HEAP_ARRAY(size_t, _cards_scanned);
ysr@777 607 _cards_scanned = NULL;
ysr@777 608 // Cleanup after copy
ysr@777 609 #if G1_REM_SET_LOGGING
ysr@777 610 PrintRSClosure cl;
ysr@777 611 _g1->heap_region_iterate(&cl);
ysr@777 612 #endif
ysr@777 613 _g1->set_refine_cte_cl_concurrency(true);
ysr@777 614 cleanUpIteratorsClosure iterClosure;
ysr@777 615 _g1->collection_set_iterate(&iterClosure);
ysr@777 616 // Set all cards back to clean.
ysr@777 617 _g1->cleanUpCardTable();
iveresov@1229 618
johnc@2060 619 DirtyCardQueueSet& into_cset_dcqs = _g1->into_cset_dirty_card_queue_set();
johnc@2060 620 int into_cset_n_buffers = into_cset_dcqs.completed_buffers_num();
johnc@2060 621
iveresov@1051 622 if (_g1->evacuation_failed()) {
johnc@2060 623 // Restore remembered sets for the regions pointing into the collection set.
johnc@2060 624
iveresov@1051 625 if (G1DeferredRSUpdate) {
johnc@2060 626 // If deferred RS updates are enabled then we just need to transfer
johnc@2060 627 // the completed buffers from (a) the DirtyCardQueueSet used to hold
johnc@2060 628 // cards that contain references that point into the collection set
johnc@2060 629 // to (b) the DCQS used to hold the deferred RS updates
johnc@2060 630 _g1->dirty_card_queue_set().merge_bufferlists(&into_cset_dcqs);
iveresov@1051 631 } else {
johnc@2060 632
johnc@2060 633 CardTableModRefBS* bs = (CardTableModRefBS*)_g1->barrier_set();
johnc@2060 634 UpdateRSetCardTableEntryIntoCSetClosure update_rs_cset_immediate(_g1, bs);
johnc@2060 635
johnc@2060 636 int n_completed_buffers = 0;
johnc@2060 637 while (into_cset_dcqs.apply_closure_to_completed_buffer(&update_rs_cset_immediate,
johnc@2060 638 0, 0, true)) {
johnc@2060 639 n_completed_buffers++;
johnc@2060 640 }
johnc@2060 641 assert(n_completed_buffers == into_cset_n_buffers, "missed some buffers");
iveresov@1051 642 }
iveresov@1051 643 }
johnc@2060 644
johnc@2060 645 // Free any completed buffers in the DirtyCardQueueSet used to hold cards
johnc@2060 646 // which contain references that point into the collection.
johnc@2060 647 _g1->into_cset_dirty_card_queue_set().clear();
johnc@2060 648 assert(_g1->into_cset_dirty_card_queue_set().completed_buffers_num() == 0,
johnc@2060 649 "all buffers should be freed");
johnc@2060 650 _g1->into_cset_dirty_card_queue_set().clear_n_completed_buffers();
ysr@777 651 }
ysr@777 652
ysr@777 653 class ScrubRSClosure: public HeapRegionClosure {
ysr@777 654 G1CollectedHeap* _g1h;
ysr@777 655 BitMap* _region_bm;
ysr@777 656 BitMap* _card_bm;
ysr@777 657 CardTableModRefBS* _ctbs;
ysr@777 658 public:
ysr@777 659 ScrubRSClosure(BitMap* region_bm, BitMap* card_bm) :
ysr@777 660 _g1h(G1CollectedHeap::heap()),
ysr@777 661 _region_bm(region_bm), _card_bm(card_bm),
ysr@777 662 _ctbs(NULL)
ysr@777 663 {
ysr@777 664 ModRefBarrierSet* bs = _g1h->mr_bs();
ysr@777 665 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
ysr@777 666 _ctbs = (CardTableModRefBS*)bs;
ysr@777 667 }
ysr@777 668
ysr@777 669 bool doHeapRegion(HeapRegion* r) {
ysr@777 670 if (!r->continuesHumongous()) {
ysr@777 671 r->rem_set()->scrub(_ctbs, _region_bm, _card_bm);
ysr@777 672 }
ysr@777 673 return false;
ysr@777 674 }
ysr@777 675 };
ysr@777 676
johnc@2216 677 void G1RemSet::scrub(BitMap* region_bm, BitMap* card_bm) {
ysr@777 678 ScrubRSClosure scrub_cl(region_bm, card_bm);
ysr@777 679 _g1->heap_region_iterate(&scrub_cl);
ysr@777 680 }
ysr@777 681
johnc@2216 682 void G1RemSet::scrub_par(BitMap* region_bm, BitMap* card_bm,
ysr@777 683 int worker_num, int claim_val) {
ysr@777 684 ScrubRSClosure scrub_cl(region_bm, card_bm);
ysr@777 685 _g1->heap_region_par_iterate_chunked(&scrub_cl, worker_num, claim_val);
ysr@777 686 }
ysr@777 687
ysr@777 688
ysr@777 689 static IntHistogram out_of_histo(50, 50);
ysr@777 690
johnc@2060 691 class TriggerClosure : public OopClosure {
johnc@2060 692 bool _trigger;
johnc@2060 693 public:
johnc@2060 694 TriggerClosure() : _trigger(false) { }
johnc@2060 695 bool value() const { return _trigger; }
johnc@2060 696 template <class T> void do_oop_nv(T* p) { _trigger = true; }
johnc@2060 697 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@2060 698 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@2060 699 };
johnc@2060 700
johnc@2060 701 class InvokeIfNotTriggeredClosure: public OopClosure {
johnc@2060 702 TriggerClosure* _t;
johnc@2060 703 OopClosure* _oc;
johnc@2060 704 public:
johnc@2060 705 InvokeIfNotTriggeredClosure(TriggerClosure* t, OopClosure* oc):
johnc@2060 706 _t(t), _oc(oc) { }
johnc@2060 707 template <class T> void do_oop_nv(T* p) {
johnc@2060 708 if (!_t->value()) _oc->do_oop(p);
johnc@2060 709 }
johnc@2060 710 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@2060 711 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@2060 712 };
johnc@2060 713
johnc@2060 714 class Mux2Closure : public OopClosure {
johnc@2060 715 OopClosure* _c1;
johnc@2060 716 OopClosure* _c2;
johnc@2060 717 public:
johnc@2060 718 Mux2Closure(OopClosure *c1, OopClosure *c2) : _c1(c1), _c2(c2) { }
johnc@2060 719 template <class T> void do_oop_nv(T* p) {
johnc@2060 720 _c1->do_oop(p); _c2->do_oop(p);
johnc@2060 721 }
johnc@2060 722 virtual void do_oop(oop* p) { do_oop_nv(p); }
johnc@2060 723 virtual void do_oop(narrowOop* p) { do_oop_nv(p); }
johnc@2060 724 };
johnc@2060 725
johnc@2216 726 bool G1RemSet::concurrentRefineOneCard_impl(jbyte* card_ptr, int worker_i,
johnc@2060 727 bool check_for_refs_into_cset) {
johnc@1325 728 // Construct the region representing the card.
johnc@1325 729 HeapWord* start = _ct_bs->addr_for(card_ptr);
johnc@1325 730 // And find the region containing it.
johnc@1325 731 HeapRegion* r = _g1->heap_region_containing(start);
johnc@1325 732 assert(r != NULL, "unexpected null");
johnc@1325 733
johnc@1325 734 HeapWord* end = _ct_bs->addr_for(card_ptr + 1);
johnc@1325 735 MemRegion dirtyRegion(start, end);
johnc@1325 736
johnc@1325 737 #if CARD_REPEAT_HISTO
johnc@1325 738 init_ct_freq_table(_g1->g1_reserved_obj_bytes());
johnc@1325 739 ct_freq_note_card(_ct_bs->index_for(start));
johnc@1325 740 #endif
johnc@1325 741
johnc@2302 742 assert(!check_for_refs_into_cset || _cset_rs_update_cl[worker_i] != NULL, "sanity");
johnc@2302 743 UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
johnc@2302 744 _g1->g1_rem_set(),
johnc@2302 745 _cset_rs_update_cl[worker_i],
johnc@2302 746 check_for_refs_into_cset,
johnc@2302 747 worker_i);
johnc@1325 748 update_rs_oop_cl.set_from(r);
johnc@2060 749
johnc@2060 750 TriggerClosure trigger_cl;
johnc@2060 751 FilterIntoCSClosure into_cs_cl(NULL, _g1, &trigger_cl);
johnc@2060 752 InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl);
johnc@2060 753 Mux2Closure mux(&invoke_cl, &update_rs_oop_cl);
johnc@2060 754
johnc@2060 755 FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r,
johnc@2060 756 (check_for_refs_into_cset ?
johnc@2060 757 (OopClosure*)&mux :
johnc@2060 758 (OopClosure*)&update_rs_oop_cl));
johnc@1325 759
johnc@1325 760 // Undirty the card.
johnc@1325 761 *card_ptr = CardTableModRefBS::clean_card_val();
johnc@1325 762 // We must complete this write before we do any of the reads below.
johnc@1325 763 OrderAccess::storeload();
johnc@1325 764 // And process it, being careful of unallocated portions of TLAB's.
johnc@2021 765
johnc@2021 766 // The region for the current card may be a young region. The
johnc@2021 767 // current card may have been a card that was evicted from the
johnc@2021 768 // card cache. When the card was inserted into the cache, we had
johnc@2021 769 // determined that its region was non-young. While in the cache,
johnc@2021 770 // the region may have been freed during a cleanup pause, reallocated
johnc@2021 771 // and tagged as young.
johnc@2021 772 //
johnc@2021 773 // We wish to filter out cards for such a region but the current
johnc@2021 774 // thread, if we're running conucrrently, may "see" the young type
johnc@2021 775 // change at any time (so an earlier "is_young" check may pass or
johnc@2021 776 // fail arbitrarily). We tell the iteration code to perform this
johnc@2021 777 // filtering when it has been determined that there has been an actual
johnc@2021 778 // allocation in this region and making it safe to check the young type.
johnc@2021 779 bool filter_young = true;
johnc@2021 780
johnc@1325 781 HeapWord* stop_point =
johnc@1325 782 r->oops_on_card_seq_iterate_careful(dirtyRegion,
johnc@2021 783 &filter_then_update_rs_oop_cl,
johnc@2021 784 filter_young);
johnc@2021 785
johnc@1325 786 // If stop_point is non-null, then we encountered an unallocated region
johnc@1325 787 // (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the
johnc@1325 788 // card and re-enqueue: if we put off the card until a GC pause, then the
johnc@1325 789 // unallocated portion will be filled in. Alternatively, we might try
johnc@1325 790 // the full complexity of the technique used in "regular" precleaning.
johnc@1325 791 if (stop_point != NULL) {
johnc@1325 792 // The card might have gotten re-dirtied and re-enqueued while we
johnc@1325 793 // worked. (In fact, it's pretty likely.)
johnc@1325 794 if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
johnc@1325 795 *card_ptr = CardTableModRefBS::dirty_card_val();
johnc@1325 796 MutexLockerEx x(Shared_DirtyCardQ_lock,
johnc@1325 797 Mutex::_no_safepoint_check_flag);
johnc@1325 798 DirtyCardQueue* sdcq =
johnc@1325 799 JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
johnc@1325 800 sdcq->enqueue(card_ptr);
johnc@1325 801 }
johnc@1325 802 } else {
johnc@1325 803 out_of_histo.add_entry(filter_then_update_rs_oop_cl.out_of_region());
johnc@1325 804 _conc_refine_cards++;
johnc@1325 805 }
johnc@2060 806
johnc@2060 807 return trigger_cl.value();
johnc@1325 808 }
johnc@1325 809
johnc@2216 810 bool G1RemSet::concurrentRefineOneCard(jbyte* card_ptr, int worker_i,
johnc@2060 811 bool check_for_refs_into_cset) {
ysr@777 812 // If the card is no longer dirty, nothing to do.
johnc@2060 813 if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
johnc@2060 814 // No need to return that this card contains refs that point
johnc@2060 815 // into the collection set.
johnc@2060 816 return false;
johnc@2060 817 }
ysr@777 818
ysr@777 819 // Construct the region representing the card.
ysr@777 820 HeapWord* start = _ct_bs->addr_for(card_ptr);
ysr@777 821 // And find the region containing it.
ysr@777 822 HeapRegion* r = _g1->heap_region_containing(start);
ysr@777 823 if (r == NULL) {
ysr@777 824 guarantee(_g1->is_in_permanent(start), "Or else where?");
johnc@2060 825 // Again no need to return that this card contains refs that
johnc@2060 826 // point into the collection set.
johnc@2060 827 return false; // Not in the G1 heap (might be in perm, for example.)
ysr@777 828 }
ysr@777 829 // Why do we have to check here whether a card is on a young region,
ysr@777 830 // given that we dirty young regions and, as a result, the
ysr@777 831 // post-barrier is supposed to filter them out and never to enqueue
ysr@777 832 // them? When we allocate a new region as the "allocation region" we
ysr@777 833 // actually dirty its cards after we release the lock, since card
ysr@777 834 // dirtying while holding the lock was a performance bottleneck. So,
ysr@777 835 // as a result, it is possible for other threads to actually
ysr@777 836 // allocate objects in the region (after the acquire the lock)
ysr@777 837 // before all the cards on the region are dirtied. This is unlikely,
ysr@777 838 // and it doesn't happen often, but it can happen. So, the extra
ysr@777 839 // check below filters out those cards.
iveresov@1072 840 if (r->is_young()) {
johnc@2060 841 return false;
ysr@777 842 }
ysr@777 843 // While we are processing RSet buffers during the collection, we
ysr@777 844 // actually don't want to scan any cards on the collection set,
ysr@777 845 // since we don't want to update remebered sets with entries that
ysr@777 846 // point into the collection set, given that live objects from the
ysr@777 847 // collection set are about to move and such entries will be stale
ysr@777 848 // very soon. This change also deals with a reliability issue which
ysr@777 849 // involves scanning a card in the collection set and coming across
ysr@777 850 // an array that was being chunked and looking malformed. Note,
ysr@777 851 // however, that if evacuation fails, we have to scan any objects
ysr@777 852 // that were not moved and create any missing entries.
ysr@777 853 if (r->in_collection_set()) {
johnc@2060 854 return false;
ysr@777 855 }
ysr@777 856
johnc@1325 857 // Should we defer processing the card?
johnc@1325 858 //
johnc@1325 859 // Previously the result from the insert_cache call would be
johnc@1325 860 // either card_ptr (implying that card_ptr was currently "cold"),
johnc@1325 861 // null (meaning we had inserted the card ptr into the "hot"
johnc@1325 862 // cache, which had some headroom), or a "hot" card ptr
johnc@1325 863 // extracted from the "hot" cache.
johnc@1325 864 //
johnc@1325 865 // Now that the _card_counts cache in the ConcurrentG1Refine
johnc@1325 866 // instance is an evicting hash table, the result we get back
johnc@1325 867 // could be from evicting the card ptr in an already occupied
johnc@1325 868 // bucket (in which case we have replaced the card ptr in the
johnc@1325 869 // bucket with card_ptr and "defer" is set to false). To avoid
johnc@1325 870 // having a data structure (updates to which would need a lock)
johnc@1325 871 // to hold these unprocessed dirty cards, we need to immediately
johnc@1325 872 // process card_ptr. The actions needed to be taken on return
johnc@1325 873 // from cache_insert are summarized in the following table:
johnc@1325 874 //
johnc@1325 875 // res defer action
johnc@1325 876 // --------------------------------------------------------------
johnc@1325 877 // null false card evicted from _card_counts & replaced with
johnc@1325 878 // card_ptr; evicted ptr added to hot cache.
johnc@1325 879 // No need to process res; immediately process card_ptr
johnc@1325 880 //
johnc@1325 881 // null true card not evicted from _card_counts; card_ptr added
johnc@1325 882 // to hot cache.
johnc@1325 883 // Nothing to do.
johnc@1325 884 //
johnc@1325 885 // non-null false card evicted from _card_counts & replaced with
johnc@1325 886 // card_ptr; evicted ptr is currently "cold" or
johnc@1325 887 // caused an eviction from the hot cache.
johnc@1325 888 // Immediately process res; process card_ptr.
johnc@1325 889 //
johnc@1325 890 // non-null true card not evicted from _card_counts; card_ptr is
johnc@1325 891 // currently cold, or caused an eviction from hot
johnc@1325 892 // cache.
johnc@1325 893 // Immediately process res; no need to process card_ptr.
johnc@1325 894
johnc@2060 895
johnc@1325 896 jbyte* res = card_ptr;
johnc@1325 897 bool defer = false;
johnc@2060 898
johnc@2060 899 // This gets set to true if the card being refined has references
johnc@2060 900 // that point into the collection set.
johnc@2060 901 bool oops_into_cset = false;
johnc@2060 902
ysr@777 903 if (_cg1r->use_cache()) {
johnc@1325 904 jbyte* res = _cg1r->cache_insert(card_ptr, &defer);
johnc@1325 905 if (res != NULL && (res != card_ptr || defer)) {
johnc@1325 906 start = _ct_bs->addr_for(res);
johnc@1325 907 r = _g1->heap_region_containing(start);
johnc@1325 908 if (r == NULL) {
johnc@1325 909 assert(_g1->is_in_permanent(start), "Or else where?");
johnc@1325 910 } else {
johnc@2021 911 // Checking whether the region we got back from the cache
johnc@2021 912 // is young here is inappropriate. The region could have been
johnc@2021 913 // freed, reallocated and tagged as young while in the cache.
johnc@2021 914 // Hence we could see its young type change at any time.
johnc@2021 915 //
johnc@2021 916 // Process card pointer we get back from the hot card cache. This
johnc@2021 917 // will check whether the region containing the card is young
johnc@2021 918 // _after_ checking that the region has been allocated from.
johnc@2060 919 oops_into_cset = concurrentRefineOneCard_impl(res, worker_i,
johnc@2060 920 false /* check_for_refs_into_cset */);
johnc@2060 921 // The above call to concurrentRefineOneCard_impl is only
johnc@2060 922 // performed if the hot card cache is enabled. This cache is
johnc@2060 923 // disabled during an evacuation pause - which is the only
johnc@2060 924 // time when we need know if the card contains references
johnc@2060 925 // that point into the collection set. Also when the hot card
johnc@2060 926 // cache is enabled, this code is executed by the concurrent
johnc@2060 927 // refine threads - rather than the GC worker threads - and
johnc@2060 928 // concurrentRefineOneCard_impl will return false.
johnc@2060 929 assert(!oops_into_cset, "should not see true here");
johnc@1325 930 }
ysr@777 931 }
ysr@777 932 }
ysr@777 933
johnc@1325 934 if (!defer) {
johnc@2060 935 oops_into_cset =
johnc@2060 936 concurrentRefineOneCard_impl(card_ptr, worker_i, check_for_refs_into_cset);
johnc@2060 937 // We should only be detecting that the card contains references
johnc@2060 938 // that point into the collection set if the current thread is
johnc@2060 939 // a GC worker thread.
johnc@2060 940 assert(!oops_into_cset || SafepointSynchronize::is_at_safepoint(),
johnc@2060 941 "invalid result at non safepoint");
ysr@777 942 }
johnc@2060 943 return oops_into_cset;
ysr@777 944 }
ysr@777 945
ysr@777 946 class HRRSStatsIter: public HeapRegionClosure {
ysr@777 947 size_t _occupied;
ysr@777 948 size_t _total_mem_sz;
ysr@777 949 size_t _max_mem_sz;
ysr@777 950 HeapRegion* _max_mem_sz_region;
ysr@777 951 public:
ysr@777 952 HRRSStatsIter() :
ysr@777 953 _occupied(0),
ysr@777 954 _total_mem_sz(0),
ysr@777 955 _max_mem_sz(0),
ysr@777 956 _max_mem_sz_region(NULL)
ysr@777 957 {}
ysr@777 958
ysr@777 959 bool doHeapRegion(HeapRegion* r) {
ysr@777 960 if (r->continuesHumongous()) return false;
ysr@777 961 size_t mem_sz = r->rem_set()->mem_size();
ysr@777 962 if (mem_sz > _max_mem_sz) {
ysr@777 963 _max_mem_sz = mem_sz;
ysr@777 964 _max_mem_sz_region = r;
ysr@777 965 }
ysr@777 966 _total_mem_sz += mem_sz;
ysr@777 967 size_t occ = r->rem_set()->occupied();
ysr@777 968 _occupied += occ;
ysr@777 969 return false;
ysr@777 970 }
ysr@777 971 size_t total_mem_sz() { return _total_mem_sz; }
ysr@777 972 size_t max_mem_sz() { return _max_mem_sz; }
ysr@777 973 size_t occupied() { return _occupied; }
ysr@777 974 HeapRegion* max_mem_sz_region() { return _max_mem_sz_region; }
ysr@777 975 };
ysr@777 976
iveresov@1229 977 class PrintRSThreadVTimeClosure : public ThreadClosure {
iveresov@1229 978 public:
iveresov@1229 979 virtual void do_thread(Thread *t) {
iveresov@1229 980 ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t;
iveresov@1229 981 gclog_or_tty->print(" %5.2f", crt->vtime_accum());
iveresov@1229 982 }
iveresov@1229 983 };
iveresov@1229 984
johnc@2216 985 void G1RemSet::print_summary_info() {
ysr@777 986 G1CollectedHeap* g1 = G1CollectedHeap::heap();
ysr@777 987
ysr@777 988 #if CARD_REPEAT_HISTO
ysr@777 989 gclog_or_tty->print_cr("\nG1 card_repeat count histogram: ");
ysr@777 990 gclog_or_tty->print_cr(" # of repeats --> # of cards with that number.");
ysr@777 991 card_repeat_count.print_on(gclog_or_tty);
ysr@777 992 #endif
ysr@777 993
ysr@777 994 if (FILTEROUTOFREGIONCLOSURE_DOHISTOGRAMCOUNT) {
ysr@777 995 gclog_or_tty->print_cr("\nG1 rem-set out-of-region histogram: ");
ysr@777 996 gclog_or_tty->print_cr(" # of CS ptrs --> # of cards with that number.");
ysr@777 997 out_of_histo.print_on(gclog_or_tty);
ysr@777 998 }
iveresov@1229 999 gclog_or_tty->print_cr("\n Concurrent RS processed %d cards",
iveresov@1229 1000 _conc_refine_cards);
ysr@777 1001 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 1002 jint tot_processed_buffers =
ysr@777 1003 dcqs.processed_buffers_mut() + dcqs.processed_buffers_rs_thread();
ysr@777 1004 gclog_or_tty->print_cr(" Of %d completed buffers:", tot_processed_buffers);
iveresov@1229 1005 gclog_or_tty->print_cr(" %8d (%5.1f%%) by conc RS threads.",
ysr@777 1006 dcqs.processed_buffers_rs_thread(),
ysr@777 1007 100.0*(float)dcqs.processed_buffers_rs_thread()/
ysr@777 1008 (float)tot_processed_buffers);
ysr@777 1009 gclog_or_tty->print_cr(" %8d (%5.1f%%) by mutator threads.",
ysr@777 1010 dcqs.processed_buffers_mut(),
ysr@777 1011 100.0*(float)dcqs.processed_buffers_mut()/
ysr@777 1012 (float)tot_processed_buffers);
iveresov@1229 1013 gclog_or_tty->print_cr(" Conc RS threads times(s)");
iveresov@1229 1014 PrintRSThreadVTimeClosure p;
iveresov@1229 1015 gclog_or_tty->print(" ");
iveresov@1229 1016 g1->concurrent_g1_refine()->threads_do(&p);
ysr@777 1017 gclog_or_tty->print_cr("");
iveresov@1229 1018
johnc@2216 1019 HRRSStatsIter blk;
johnc@2216 1020 g1->heap_region_iterate(&blk);
johnc@2216 1021 gclog_or_tty->print_cr(" Total heap region rem set sizes = " SIZE_FORMAT "K."
johnc@2216 1022 " Max = " SIZE_FORMAT "K.",
johnc@2216 1023 blk.total_mem_sz()/K, blk.max_mem_sz()/K);
johnc@2216 1024 gclog_or_tty->print_cr(" Static structures = " SIZE_FORMAT "K,"
johnc@2216 1025 " free_lists = " SIZE_FORMAT "K.",
johnc@2216 1026 HeapRegionRemSet::static_mem_size()/K,
johnc@2216 1027 HeapRegionRemSet::fl_mem_size()/K);
johnc@2216 1028 gclog_or_tty->print_cr(" %d occupied cards represented.",
johnc@2216 1029 blk.occupied());
johnc@2216 1030 gclog_or_tty->print_cr(" Max sz region = [" PTR_FORMAT ", " PTR_FORMAT " )"
johnc@2216 1031 ", cap = " SIZE_FORMAT "K, occ = " SIZE_FORMAT "K.",
johnc@2216 1032 blk.max_mem_sz_region()->bottom(), blk.max_mem_sz_region()->end(),
johnc@2216 1033 (blk.max_mem_sz_region()->rem_set()->mem_size() + K - 1)/K,
johnc@2216 1034 (blk.max_mem_sz_region()->rem_set()->occupied() + K - 1)/K);
johnc@2216 1035 gclog_or_tty->print_cr(" Did %d coarsenings.", HeapRegionRemSet::n_coarsenings());
ysr@777 1036 }
johnc@2060 1037
johnc@2216 1038 void G1RemSet::prepare_for_verify() {
iveresov@1072 1039 if (G1HRRSFlushLogBuffersOnVerify &&
iveresov@1072 1040 (VerifyBeforeGC || VerifyAfterGC)
iveresov@1072 1041 && !_g1->full_collection()) {
ysr@777 1042 cleanupHRRS();
ysr@777 1043 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 1044 if (SafepointSynchronize::is_at_safepoint()) {
ysr@777 1045 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 1046 dcqs.concatenate_logs();
ysr@777 1047 }
ysr@777 1048 bool cg1r_use_cache = _cg1r->use_cache();
ysr@777 1049 _cg1r->set_use_cache(false);
johnc@2060 1050 DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set());
johnc@2060 1051 updateRS(&into_cset_dcq, 0);
johnc@2060 1052 _g1->into_cset_dirty_card_queue_set().clear();
ysr@777 1053 _cg1r->set_use_cache(cg1r_use_cache);
iveresov@1072 1054
iveresov@1072 1055 assert(JavaThread::dirty_card_queue_set().completed_buffers_num() == 0, "All should be consumed");
ysr@777 1056 }
ysr@777 1057 }

mercurial