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

Fri, 06 Mar 2009 13:50:14 -0800

author
iveresov
date
Fri, 06 Mar 2009 13:50:14 -0800
changeset 1051
4f360ec815ba
parent 980
58054a18d735
child 1061
87fa6e083d82
permissions
-rw-r--r--

6720309: G1: don't synchronously update RSet during evacuation pauses
6720334: G1: don't update RSets of collection set regions during an evacuation pause
Summary: Introduced a deferred update mechanism for delaying the rset updates during the collection pause
Reviewed-by: apetrusenko, tonyp

ysr@777 1 /*
ysr@777 2 * Copyright 2001-2007 Sun Microsystems, Inc. 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 *
ysr@777 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
ysr@777 20 * CA 95054 USA or visit www.sun.com if you need additional information or
ysr@777 21 * have any questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
ysr@777 25 #include "incls/_precompiled.incl"
ysr@777 26 #include "incls/_g1RemSet.cpp.incl"
ysr@777 27
ysr@777 28 #define CARD_REPEAT_HISTO 0
ysr@777 29
ysr@777 30 #if CARD_REPEAT_HISTO
ysr@777 31 static size_t ct_freq_sz;
ysr@777 32 static jbyte* ct_freq = NULL;
ysr@777 33
ysr@777 34 void init_ct_freq_table(size_t heap_sz_bytes) {
ysr@777 35 if (ct_freq == NULL) {
ysr@777 36 ct_freq_sz = heap_sz_bytes/CardTableModRefBS::card_size;
ysr@777 37 ct_freq = new jbyte[ct_freq_sz];
ysr@777 38 for (size_t j = 0; j < ct_freq_sz; j++) ct_freq[j] = 0;
ysr@777 39 }
ysr@777 40 }
ysr@777 41
ysr@777 42 void ct_freq_note_card(size_t index) {
ysr@777 43 assert(0 <= index && index < ct_freq_sz, "Bounds error.");
ysr@777 44 if (ct_freq[index] < 100) { ct_freq[index]++; }
ysr@777 45 }
ysr@777 46
ysr@777 47 static IntHistogram card_repeat_count(10, 10);
ysr@777 48
ysr@777 49 void ct_freq_update_histo_and_reset() {
ysr@777 50 for (size_t j = 0; j < ct_freq_sz; j++) {
ysr@777 51 card_repeat_count.add_entry(ct_freq[j]);
ysr@777 52 ct_freq[j] = 0;
ysr@777 53 }
ysr@777 54
ysr@777 55 }
ysr@777 56 #endif
ysr@777 57
ysr@777 58
ysr@777 59 class IntoCSOopClosure: public OopsInHeapRegionClosure {
ysr@777 60 OopsInHeapRegionClosure* _blk;
ysr@777 61 G1CollectedHeap* _g1;
ysr@777 62 public:
ysr@777 63 IntoCSOopClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) :
ysr@777 64 _g1(g1), _blk(blk) {}
ysr@777 65 void set_region(HeapRegion* from) {
ysr@777 66 _blk->set_region(from);
ysr@777 67 }
ysr@777 68 virtual void do_oop(narrowOop* p) {
ysr@777 69 guarantee(false, "NYI");
ysr@777 70 }
ysr@777 71 virtual void do_oop(oop* p) {
ysr@777 72 oop obj = *p;
ysr@777 73 if (_g1->obj_in_cs(obj)) _blk->do_oop(p);
ysr@777 74 }
ysr@777 75 bool apply_to_weak_ref_discovered_field() { return true; }
ysr@777 76 bool idempotent() { return true; }
ysr@777 77 };
ysr@777 78
ysr@777 79 class IntoCSRegionClosure: public HeapRegionClosure {
ysr@777 80 IntoCSOopClosure _blk;
ysr@777 81 G1CollectedHeap* _g1;
ysr@777 82 public:
ysr@777 83 IntoCSRegionClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) :
ysr@777 84 _g1(g1), _blk(g1, blk) {}
ysr@777 85 bool doHeapRegion(HeapRegion* r) {
ysr@777 86 if (!r->in_collection_set()) {
ysr@777 87 _blk.set_region(r);
ysr@777 88 if (r->isHumongous()) {
ysr@777 89 if (r->startsHumongous()) {
ysr@777 90 oop obj = oop(r->bottom());
ysr@777 91 obj->oop_iterate(&_blk);
ysr@777 92 }
ysr@777 93 } else {
ysr@777 94 r->oop_before_save_marks_iterate(&_blk);
ysr@777 95 }
ysr@777 96 }
ysr@777 97 return false;
ysr@777 98 }
ysr@777 99 };
ysr@777 100
ysr@777 101 void
ysr@777 102 StupidG1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc,
ysr@777 103 int worker_i) {
ysr@777 104 IntoCSRegionClosure rc(_g1, oc);
ysr@777 105 _g1->heap_region_iterate(&rc);
ysr@777 106 }
ysr@777 107
ysr@777 108 class UpdateRSOopClosure: public OopClosure {
ysr@777 109 HeapRegion* _from;
ysr@777 110 HRInto_G1RemSet* _rs;
ysr@777 111 int _worker_i;
ysr@777 112 public:
ysr@777 113 UpdateRSOopClosure(HRInto_G1RemSet* rs, int worker_i = 0) :
ysr@777 114 _from(NULL), _rs(rs), _worker_i(worker_i) {
ysr@777 115 guarantee(_rs != NULL, "Requires an HRIntoG1RemSet");
ysr@777 116 }
ysr@777 117
ysr@777 118 void set_from(HeapRegion* from) {
ysr@777 119 assert(from != NULL, "from region must be non-NULL");
ysr@777 120 _from = from;
ysr@777 121 }
ysr@777 122
ysr@777 123 virtual void do_oop(narrowOop* p) {
ysr@777 124 guarantee(false, "NYI");
ysr@777 125 }
ysr@777 126 virtual void do_oop(oop* p) {
ysr@777 127 assert(_from != NULL, "from region must be non-NULL");
ysr@777 128 _rs->par_write_ref(_from, p, _worker_i);
ysr@777 129 }
ysr@777 130 // Override: this closure is idempotent.
ysr@777 131 // bool idempotent() { return true; }
ysr@777 132 bool apply_to_weak_ref_discovered_field() { return true; }
ysr@777 133 };
ysr@777 134
ysr@777 135 class UpdateRSOutOfRegionClosure: public HeapRegionClosure {
ysr@777 136 G1CollectedHeap* _g1h;
ysr@777 137 ModRefBarrierSet* _mr_bs;
ysr@777 138 UpdateRSOopClosure _cl;
ysr@777 139 int _worker_i;
ysr@777 140 public:
ysr@777 141 UpdateRSOutOfRegionClosure(G1CollectedHeap* g1, int worker_i = 0) :
ysr@777 142 _cl(g1->g1_rem_set()->as_HRInto_G1RemSet(), worker_i),
ysr@777 143 _mr_bs(g1->mr_bs()),
ysr@777 144 _worker_i(worker_i),
ysr@777 145 _g1h(g1)
ysr@777 146 {}
ysr@777 147 bool doHeapRegion(HeapRegion* r) {
ysr@777 148 if (!r->in_collection_set() && !r->continuesHumongous()) {
ysr@777 149 _cl.set_from(r);
ysr@777 150 r->set_next_filter_kind(HeapRegionDCTOC::OutOfRegionFilterKind);
ysr@777 151 _mr_bs->mod_oop_in_space_iterate(r, &_cl, true, true);
ysr@777 152 }
ysr@777 153 return false;
ysr@777 154 }
ysr@777 155 };
ysr@777 156
ysr@777 157 class VerifyRSCleanCardOopClosure: public OopClosure {
ysr@777 158 G1CollectedHeap* _g1;
ysr@777 159 public:
ysr@777 160 VerifyRSCleanCardOopClosure(G1CollectedHeap* g1) : _g1(g1) {}
ysr@777 161
ysr@777 162 virtual void do_oop(narrowOop* p) {
ysr@777 163 guarantee(false, "NYI");
ysr@777 164 }
ysr@777 165 virtual void do_oop(oop* p) {
ysr@777 166 oop obj = *p;
ysr@777 167 HeapRegion* to = _g1->heap_region_containing(obj);
ysr@777 168 guarantee(to == NULL || !to->in_collection_set(),
ysr@777 169 "Missed a rem set member.");
ysr@777 170 }
ysr@777 171 };
ysr@777 172
ysr@777 173 HRInto_G1RemSet::HRInto_G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs)
ysr@777 174 : G1RemSet(g1), _ct_bs(ct_bs), _g1p(_g1->g1_policy()),
ysr@777 175 _cg1r(g1->concurrent_g1_refine()),
ysr@777 176 _par_traversal_in_progress(false), _new_refs(NULL),
ysr@777 177 _cards_scanned(NULL), _total_cards_scanned(0)
ysr@777 178 {
ysr@777 179 _seq_task = new SubTasksDone(NumSeqTasks);
iveresov@1051 180 guarantee(n_workers() > 0, "There should be some workers");
iveresov@1051 181 _new_refs = NEW_C_HEAP_ARRAY(GrowableArray<oop*>*, n_workers());
iveresov@1051 182 for (uint i = 0; i < n_workers(); i++) {
iveresov@1051 183 _new_refs[i] = new (ResourceObj::C_HEAP) GrowableArray<oop*>(8192,true);
iveresov@1051 184 }
ysr@777 185 }
ysr@777 186
ysr@777 187 HRInto_G1RemSet::~HRInto_G1RemSet() {
ysr@777 188 delete _seq_task;
iveresov@1051 189 for (uint i = 0; i < n_workers(); i++) {
iveresov@1051 190 delete _new_refs[i];
iveresov@1051 191 }
iveresov@1051 192 FREE_C_HEAP_ARRAY(GrowableArray<oop*>*, _new_refs);
ysr@777 193 }
ysr@777 194
ysr@777 195 void CountNonCleanMemRegionClosure::do_MemRegion(MemRegion mr) {
ysr@777 196 if (_g1->is_in_g1_reserved(mr.start())) {
ysr@777 197 _n += (int) ((mr.byte_size() / CardTableModRefBS::card_size));
ysr@777 198 if (_start_first == NULL) _start_first = mr.start();
ysr@777 199 }
ysr@777 200 }
ysr@777 201
ysr@777 202 class ScanRSClosure : public HeapRegionClosure {
ysr@777 203 size_t _cards_done, _cards;
ysr@777 204 G1CollectedHeap* _g1h;
ysr@777 205 OopsInHeapRegionClosure* _oc;
ysr@777 206 G1BlockOffsetSharedArray* _bot_shared;
ysr@777 207 CardTableModRefBS *_ct_bs;
ysr@777 208 int _worker_i;
ysr@777 209 bool _try_claimed;
ysr@777 210 public:
ysr@777 211 ScanRSClosure(OopsInHeapRegionClosure* oc, int worker_i) :
ysr@777 212 _oc(oc),
ysr@777 213 _cards(0),
ysr@777 214 _cards_done(0),
ysr@777 215 _worker_i(worker_i),
ysr@777 216 _try_claimed(false)
ysr@777 217 {
ysr@777 218 _g1h = G1CollectedHeap::heap();
ysr@777 219 _bot_shared = _g1h->bot_shared();
ysr@777 220 _ct_bs = (CardTableModRefBS*) (_g1h->barrier_set());
ysr@777 221 }
ysr@777 222
ysr@777 223 void set_try_claimed() { _try_claimed = true; }
ysr@777 224
ysr@777 225 void scanCard(size_t index, HeapRegion *r) {
ysr@777 226 _cards_done++;
ysr@777 227 DirtyCardToOopClosure* cl =
ysr@777 228 r->new_dcto_closure(_oc,
ysr@777 229 CardTableModRefBS::Precise,
ysr@777 230 HeapRegionDCTOC::IntoCSFilterKind);
ysr@777 231
ysr@777 232 // Set the "from" region in the closure.
ysr@777 233 _oc->set_region(r);
ysr@777 234 HeapWord* card_start = _bot_shared->address_for_index(index);
ysr@777 235 HeapWord* card_end = card_start + G1BlockOffsetSharedArray::N_words;
ysr@777 236 Space *sp = SharedHeap::heap()->space_containing(card_start);
ysr@777 237 MemRegion sm_region;
ysr@777 238 if (ParallelGCThreads > 0) {
ysr@777 239 // first find the used area
ysr@777 240 sm_region = sp->used_region_at_save_marks();
ysr@777 241 } else {
ysr@777 242 // The closure is not idempotent. We shouldn't look at objects
ysr@777 243 // allocated during the GC.
ysr@777 244 sm_region = sp->used_region_at_save_marks();
ysr@777 245 }
ysr@777 246 MemRegion mr = sm_region.intersection(MemRegion(card_start,card_end));
ysr@777 247 if (!mr.is_empty()) {
ysr@777 248 cl->do_MemRegion(mr);
ysr@777 249 }
ysr@777 250 }
ysr@777 251
ysr@777 252 void printCard(HeapRegion* card_region, size_t card_index,
ysr@777 253 HeapWord* card_start) {
ysr@777 254 gclog_or_tty->print_cr("T %d Region [" PTR_FORMAT ", " PTR_FORMAT ") "
ysr@777 255 "RS names card %p: "
ysr@777 256 "[" PTR_FORMAT ", " PTR_FORMAT ")",
ysr@777 257 _worker_i,
ysr@777 258 card_region->bottom(), card_region->end(),
ysr@777 259 card_index,
ysr@777 260 card_start, card_start + G1BlockOffsetSharedArray::N_words);
ysr@777 261 }
ysr@777 262
ysr@777 263 bool doHeapRegion(HeapRegion* r) {
ysr@777 264 assert(r->in_collection_set(), "should only be called on elements of CS.");
ysr@777 265 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 266 if (hrrs->iter_is_complete()) return false; // All done.
ysr@777 267 if (!_try_claimed && !hrrs->claim_iter()) return false;
ysr@777 268 // If we didn't return above, then
ysr@777 269 // _try_claimed || r->claim_iter()
ysr@777 270 // is true: either we're supposed to work on claimed-but-not-complete
ysr@777 271 // regions, or we successfully claimed the region.
ysr@777 272 HeapRegionRemSetIterator* iter = _g1h->rem_set_iterator(_worker_i);
ysr@777 273 hrrs->init_iterator(iter);
ysr@777 274 size_t card_index;
ysr@777 275 while (iter->has_next(card_index)) {
ysr@777 276 HeapWord* card_start = _g1h->bot_shared()->address_for_index(card_index);
ysr@777 277
ysr@777 278 #if 0
ysr@777 279 gclog_or_tty->print("Rem set iteration yielded card [" PTR_FORMAT ", " PTR_FORMAT ").\n",
ysr@777 280 card_start, card_start + CardTableModRefBS::card_size_in_words);
ysr@777 281 #endif
ysr@777 282
ysr@777 283 HeapRegion* card_region = _g1h->heap_region_containing(card_start);
ysr@777 284 assert(card_region != NULL, "Yielding cards not in the heap?");
ysr@777 285 _cards++;
ysr@777 286
ysr@777 287 if (!card_region->in_collection_set()) {
ysr@777 288 // If the card is dirty, then we will scan it during updateRS.
ysr@777 289 if (!_ct_bs->is_card_claimed(card_index) &&
ysr@777 290 !_ct_bs->is_card_dirty(card_index)) {
ysr@777 291 assert(_ct_bs->is_card_clean(card_index) ||
iveresov@1051 292 _ct_bs->is_card_claimed(card_index) ||
iveresov@1051 293 _ct_bs->is_card_deferred(card_index),
iveresov@1051 294 "Card is either clean, claimed or deferred");
ysr@777 295 if (_ct_bs->claim_card(card_index))
ysr@777 296 scanCard(card_index, card_region);
ysr@777 297 }
ysr@777 298 }
ysr@777 299 }
ysr@777 300 hrrs->set_iter_complete();
ysr@777 301 return false;
ysr@777 302 }
ysr@777 303 // Set all cards back to clean.
ysr@777 304 void cleanup() {_g1h->cleanUpCardTable();}
ysr@777 305 size_t cards_done() { return _cards_done;}
ysr@777 306 size_t cards_looked_up() { return _cards;}
ysr@777 307 };
ysr@777 308
ysr@777 309 // We want the parallel threads to start their scanning at
ysr@777 310 // different collection set regions to avoid contention.
ysr@777 311 // If we have:
ysr@777 312 // n collection set regions
ysr@777 313 // p threads
ysr@777 314 // Then thread t will start at region t * floor (n/p)
ysr@777 315
ysr@777 316 HeapRegion* HRInto_G1RemSet::calculateStartRegion(int worker_i) {
ysr@777 317 HeapRegion* result = _g1p->collection_set();
ysr@777 318 if (ParallelGCThreads > 0) {
ysr@777 319 size_t cs_size = _g1p->collection_set_size();
ysr@777 320 int n_workers = _g1->workers()->total_workers();
ysr@777 321 size_t cs_spans = cs_size / n_workers;
ysr@777 322 size_t ind = cs_spans * worker_i;
ysr@777 323 for (size_t i = 0; i < ind; i++)
ysr@777 324 result = result->next_in_collection_set();
ysr@777 325 }
ysr@777 326 return result;
ysr@777 327 }
ysr@777 328
ysr@777 329 void HRInto_G1RemSet::scanRS(OopsInHeapRegionClosure* oc, int worker_i) {
ysr@777 330 double rs_time_start = os::elapsedTime();
ysr@777 331 HeapRegion *startRegion = calculateStartRegion(worker_i);
ysr@777 332
ysr@777 333 BufferingOopsInHeapRegionClosure boc(oc);
ysr@777 334 ScanRSClosure scanRScl(&boc, worker_i);
ysr@777 335 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 336 scanRScl.set_try_claimed();
ysr@777 337 _g1->collection_set_iterate_from(startRegion, &scanRScl);
ysr@777 338
ysr@777 339 boc.done();
ysr@777 340 double closure_app_time_sec = boc.closure_app_seconds();
ysr@777 341 double scan_rs_time_sec = (os::elapsedTime() - rs_time_start) -
ysr@777 342 closure_app_time_sec;
ysr@777 343 double closure_app_time_ms = closure_app_time_sec * 1000.0;
ysr@777 344
ysr@777 345 assert( _cards_scanned != NULL, "invariant" );
ysr@777 346 _cards_scanned[worker_i] = scanRScl.cards_done();
ysr@777 347
ysr@777 348 _g1p->record_scan_rs_start_time(worker_i, rs_time_start * 1000.0);
ysr@777 349 _g1p->record_scan_rs_time(worker_i, scan_rs_time_sec * 1000.0);
iveresov@1051 350
iveresov@1051 351 double scan_new_refs_time_ms = _g1p->get_scan_new_refs_time(worker_i);
iveresov@1051 352 if (scan_new_refs_time_ms > 0.0) {
iveresov@1051 353 closure_app_time_ms += scan_new_refs_time_ms;
ysr@777 354 }
iveresov@1051 355
ysr@777 356 _g1p->record_obj_copy_time(worker_i, closure_app_time_ms);
ysr@777 357 }
ysr@777 358
ysr@777 359 void HRInto_G1RemSet::updateRS(int worker_i) {
ysr@777 360 ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine();
ysr@777 361
ysr@777 362 double start = os::elapsedTime();
ysr@777 363 _g1p->record_update_rs_start_time(worker_i, start * 1000.0);
ysr@777 364
ysr@777 365 if (G1RSBarrierUseQueue && !cg1r->do_traversal()) {
ysr@777 366 // Apply the appropriate closure to all remaining log entries.
ysr@777 367 _g1->iterate_dirty_card_closure(false, worker_i);
ysr@777 368 // Now there should be no dirty cards.
ysr@777 369 if (G1RSLogCheckCardTable) {
ysr@777 370 CountNonCleanMemRegionClosure cl(_g1);
ysr@777 371 _ct_bs->mod_card_iterate(&cl);
ysr@777 372 // XXX This isn't true any more: keeping cards of young regions
ysr@777 373 // marked dirty broke it. Need some reasonable fix.
ysr@777 374 guarantee(cl.n() == 0, "Card table should be clean.");
ysr@777 375 }
ysr@777 376 } else {
ysr@777 377 UpdateRSOutOfRegionClosure update_rs(_g1, worker_i);
ysr@777 378 _g1->heap_region_iterate(&update_rs);
ysr@777 379 // We did a traversal; no further one is necessary.
ysr@777 380 if (G1RSBarrierUseQueue) {
ysr@777 381 assert(cg1r->do_traversal(), "Or we shouldn't have gotten here.");
ysr@777 382 cg1r->set_pya_cancel();
ysr@777 383 }
ysr@777 384 if (_cg1r->use_cache()) {
ysr@777 385 _cg1r->clear_and_record_card_counts();
ysr@777 386 _cg1r->clear_hot_cache();
ysr@777 387 }
ysr@777 388 }
ysr@777 389 _g1p->record_update_rs_time(worker_i, (os::elapsedTime() - start) * 1000.0);
ysr@777 390 }
ysr@777 391
ysr@777 392 #ifndef PRODUCT
ysr@777 393 class PrintRSClosure : public HeapRegionClosure {
ysr@777 394 int _count;
ysr@777 395 public:
ysr@777 396 PrintRSClosure() : _count(0) {}
ysr@777 397 bool doHeapRegion(HeapRegion* r) {
ysr@777 398 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 399 _count += (int) hrrs->occupied();
ysr@777 400 if (hrrs->occupied() == 0) {
ysr@777 401 gclog_or_tty->print("Heap Region [" PTR_FORMAT ", " PTR_FORMAT ") "
ysr@777 402 "has no remset entries\n",
ysr@777 403 r->bottom(), r->end());
ysr@777 404 } else {
ysr@777 405 gclog_or_tty->print("Printing rem set for heap region [" PTR_FORMAT ", " PTR_FORMAT ")\n",
ysr@777 406 r->bottom(), r->end());
ysr@777 407 r->print();
ysr@777 408 hrrs->print();
ysr@777 409 gclog_or_tty->print("\nDone printing rem set\n");
ysr@777 410 }
ysr@777 411 return false;
ysr@777 412 }
ysr@777 413 int occupied() {return _count;}
ysr@777 414 };
ysr@777 415 #endif
ysr@777 416
ysr@777 417 class CountRSSizeClosure: public HeapRegionClosure {
ysr@777 418 size_t _n;
ysr@777 419 size_t _tot;
ysr@777 420 size_t _max;
ysr@777 421 HeapRegion* _max_r;
ysr@777 422 enum {
ysr@777 423 N = 20,
ysr@777 424 MIN = 6
ysr@777 425 };
ysr@777 426 int _histo[N];
ysr@777 427 public:
ysr@777 428 CountRSSizeClosure() : _n(0), _tot(0), _max(0), _max_r(NULL) {
ysr@777 429 for (int i = 0; i < N; i++) _histo[i] = 0;
ysr@777 430 }
ysr@777 431 bool doHeapRegion(HeapRegion* r) {
ysr@777 432 if (!r->continuesHumongous()) {
ysr@777 433 size_t occ = r->rem_set()->occupied();
ysr@777 434 _n++;
ysr@777 435 _tot += occ;
ysr@777 436 if (occ > _max) {
ysr@777 437 _max = occ;
ysr@777 438 _max_r = r;
ysr@777 439 }
ysr@777 440 // Fit it into a histo bin.
ysr@777 441 int s = 1 << MIN;
ysr@777 442 int i = 0;
ysr@777 443 while (occ > (size_t) s && i < (N-1)) {
ysr@777 444 s = s << 1;
ysr@777 445 i++;
ysr@777 446 }
ysr@777 447 _histo[i]++;
ysr@777 448 }
ysr@777 449 return false;
ysr@777 450 }
ysr@777 451 size_t n() { return _n; }
ysr@777 452 size_t tot() { return _tot; }
ysr@777 453 size_t mx() { return _max; }
ysr@777 454 HeapRegion* mxr() { return _max_r; }
ysr@777 455 void print_histo() {
ysr@777 456 int mx = N;
ysr@777 457 while (mx >= 0) {
ysr@777 458 if (_histo[mx-1] > 0) break;
ysr@777 459 mx--;
ysr@777 460 }
ysr@777 461 gclog_or_tty->print_cr("Number of regions with given RS sizes:");
ysr@777 462 gclog_or_tty->print_cr(" <= %8d %8d", 1 << MIN, _histo[0]);
ysr@777 463 for (int i = 1; i < mx-1; i++) {
ysr@777 464 gclog_or_tty->print_cr(" %8d - %8d %8d",
ysr@777 465 (1 << (MIN + i - 1)) + 1,
ysr@777 466 1 << (MIN + i),
ysr@777 467 _histo[i]);
ysr@777 468 }
ysr@777 469 gclog_or_tty->print_cr(" > %8d %8d", (1 << (MIN+mx-2))+1, _histo[mx-1]);
ysr@777 470 }
ysr@777 471 };
ysr@777 472
ysr@777 473 void
ysr@777 474 HRInto_G1RemSet::scanNewRefsRS(OopsInHeapRegionClosure* oc,
ysr@777 475 int worker_i) {
ysr@777 476 double scan_new_refs_start_sec = os::elapsedTime();
ysr@777 477 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@777 478 CardTableModRefBS* ct_bs = (CardTableModRefBS*) (g1h->barrier_set());
iveresov@1051 479 for (int i = 0; i < _new_refs[worker_i]->length(); i++) {
iveresov@1051 480 oop* p = _new_refs[worker_i]->at(i);
ysr@777 481 oop obj = *p;
ysr@777 482 // *p was in the collection set when p was pushed on "_new_refs", but
ysr@777 483 // another thread may have processed this location from an RS, so it
ysr@777 484 // might not point into the CS any longer. If so, it's obviously been
ysr@777 485 // processed, and we don't need to do anything further.
ysr@777 486 if (g1h->obj_in_cs(obj)) {
ysr@777 487 HeapRegion* r = g1h->heap_region_containing(p);
ysr@777 488
ysr@777 489 DEBUG_ONLY(HeapRegion* to = g1h->heap_region_containing(obj));
ysr@777 490 oc->set_region(r);
ysr@777 491 // If "p" has already been processed concurrently, this is
ysr@777 492 // idempotent.
ysr@777 493 oc->do_oop(p);
ysr@777 494 }
ysr@777 495 }
ysr@777 496 _g1p->record_scan_new_refs_time(worker_i,
ysr@777 497 (os::elapsedTime() - scan_new_refs_start_sec)
ysr@777 498 * 1000.0);
ysr@777 499 }
ysr@777 500
ysr@777 501 void HRInto_G1RemSet::set_par_traversal(bool b) {
ysr@777 502 _par_traversal_in_progress = b;
ysr@777 503 HeapRegionRemSet::set_par_traversal(b);
ysr@777 504 }
ysr@777 505
ysr@777 506 void HRInto_G1RemSet::cleanupHRRS() {
ysr@777 507 HeapRegionRemSet::cleanup();
ysr@777 508 }
ysr@777 509
ysr@777 510 void
ysr@777 511 HRInto_G1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc,
ysr@777 512 int worker_i) {
ysr@777 513 #if CARD_REPEAT_HISTO
ysr@777 514 ct_freq_update_histo_and_reset();
ysr@777 515 #endif
ysr@777 516 if (worker_i == 0) {
ysr@777 517 _cg1r->clear_and_record_card_counts();
ysr@777 518 }
ysr@777 519
ysr@777 520 // Make this into a command-line flag...
ysr@777 521 if (G1RSCountHisto && (ParallelGCThreads == 0 || worker_i == 0)) {
ysr@777 522 CountRSSizeClosure count_cl;
ysr@777 523 _g1->heap_region_iterate(&count_cl);
ysr@777 524 gclog_or_tty->print_cr("Avg of %d RS counts is %f, max is %d, "
ysr@777 525 "max region is " PTR_FORMAT,
ysr@777 526 count_cl.n(), (float)count_cl.tot()/(float)count_cl.n(),
ysr@777 527 count_cl.mx(), count_cl.mxr());
ysr@777 528 count_cl.print_histo();
ysr@777 529 }
ysr@777 530
ysr@777 531 if (ParallelGCThreads > 0) {
ysr@777 532 // This is a temporary change to serialize the update and scanning
ysr@777 533 // of remembered sets. There are some race conditions when this is
ysr@777 534 // done in parallel and they are causing failures. When we resolve
ysr@777 535 // said race conditions, we'll revert back to parallel remembered
ysr@777 536 // set updating and scanning. See CRs 6677707 and 6677708.
ysr@777 537 if (worker_i == 0) {
ysr@777 538 updateRS(worker_i);
ysr@777 539 scanNewRefsRS(oc, worker_i);
ysr@777 540 scanRS(oc, worker_i);
ysr@777 541 }
ysr@777 542 } else {
ysr@777 543 assert(worker_i == 0, "invariant");
ysr@777 544 updateRS(0);
iveresov@1051 545 scanNewRefsRS(oc, 0);
ysr@777 546 scanRS(oc, 0);
ysr@777 547 }
ysr@777 548 }
ysr@777 549
ysr@777 550 void HRInto_G1RemSet::
ysr@777 551 prepare_for_oops_into_collection_set_do() {
ysr@777 552 #if G1_REM_SET_LOGGING
ysr@777 553 PrintRSClosure cl;
ysr@777 554 _g1->collection_set_iterate(&cl);
ysr@777 555 #endif
ysr@777 556 cleanupHRRS();
ysr@777 557 ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine();
ysr@777 558 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 559 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 560 dcqs.concatenate_logs();
ysr@777 561
ysr@777 562 assert(!_par_traversal_in_progress, "Invariant between iterations.");
ysr@777 563 if (ParallelGCThreads > 0) {
ysr@777 564 set_par_traversal(true);
iveresov@1051 565 _seq_task->set_par_threads((int)n_workers());
ysr@777 566 if (cg1r->do_traversal()) {
ysr@777 567 updateRS(0);
ysr@777 568 // Have to do this again after updaters
ysr@777 569 cleanupHRRS();
ysr@777 570 }
ysr@777 571 }
ysr@777 572 guarantee( _cards_scanned == NULL, "invariant" );
ysr@777 573 _cards_scanned = NEW_C_HEAP_ARRAY(size_t, n_workers());
apetrusenko@980 574 for (uint i = 0; i < n_workers(); ++i) {
apetrusenko@980 575 _cards_scanned[i] = 0;
apetrusenko@980 576 }
ysr@777 577 _total_cards_scanned = 0;
ysr@777 578 }
ysr@777 579
ysr@777 580
ysr@777 581 class cleanUpIteratorsClosure : public HeapRegionClosure {
ysr@777 582 bool doHeapRegion(HeapRegion *r) {
ysr@777 583 HeapRegionRemSet* hrrs = r->rem_set();
ysr@777 584 hrrs->init_for_par_iteration();
ysr@777 585 return false;
ysr@777 586 }
ysr@777 587 };
ysr@777 588
iveresov@1051 589 class UpdateRSetOopsIntoCSImmediate : public OopClosure {
iveresov@1051 590 G1CollectedHeap* _g1;
iveresov@1051 591 public:
iveresov@1051 592 UpdateRSetOopsIntoCSImmediate(G1CollectedHeap* g1) : _g1(g1) { }
iveresov@1051 593 virtual void do_oop(narrowOop* p) {
iveresov@1051 594 guarantee(false, "NYI");
iveresov@1051 595 }
iveresov@1051 596 virtual void do_oop(oop* p) {
iveresov@1051 597 HeapRegion* to = _g1->heap_region_containing(*p);
iveresov@1051 598 if (to->in_collection_set()) {
iveresov@1051 599 if (to->rem_set()->add_reference(p, 0)) {
iveresov@1051 600 _g1->schedule_popular_region_evac(to);
iveresov@1051 601 }
iveresov@1051 602 }
iveresov@1051 603 }
iveresov@1051 604 };
iveresov@1051 605
iveresov@1051 606 class UpdateRSetOopsIntoCSDeferred : public OopClosure {
iveresov@1051 607 G1CollectedHeap* _g1;
iveresov@1051 608 CardTableModRefBS* _ct_bs;
iveresov@1051 609 DirtyCardQueue* _dcq;
iveresov@1051 610 public:
iveresov@1051 611 UpdateRSetOopsIntoCSDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) :
iveresov@1051 612 _g1(g1), _ct_bs((CardTableModRefBS*)_g1->barrier_set()), _dcq(dcq) { }
iveresov@1051 613 virtual void do_oop(narrowOop* p) {
iveresov@1051 614 guarantee(false, "NYI");
iveresov@1051 615 }
iveresov@1051 616 virtual void do_oop(oop* p) {
iveresov@1051 617 oop obj = *p;
iveresov@1051 618 if (_g1->obj_in_cs(obj)) {
iveresov@1051 619 size_t card_index = _ct_bs->index_for(p);
iveresov@1051 620 if (_ct_bs->mark_card_deferred(card_index)) {
iveresov@1051 621 _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));
iveresov@1051 622 }
iveresov@1051 623 }
iveresov@1051 624 }
iveresov@1051 625 };
iveresov@1051 626
iveresov@1051 627 void HRInto_G1RemSet::new_refs_iterate(OopClosure* cl) {
iveresov@1051 628 for (size_t i = 0; i < n_workers(); i++) {
iveresov@1051 629 for (int j = 0; j < _new_refs[i]->length(); j++) {
iveresov@1051 630 oop* p = _new_refs[i]->at(j);
iveresov@1051 631 cl->do_oop(p);
iveresov@1051 632 }
iveresov@1051 633 }
iveresov@1051 634 }
iveresov@1051 635
ysr@777 636 void HRInto_G1RemSet::cleanup_after_oops_into_collection_set_do() {
ysr@777 637 guarantee( _cards_scanned != NULL, "invariant" );
ysr@777 638 _total_cards_scanned = 0;
ysr@777 639 for (uint i = 0; i < n_workers(); ++i)
ysr@777 640 _total_cards_scanned += _cards_scanned[i];
ysr@777 641 FREE_C_HEAP_ARRAY(size_t, _cards_scanned);
ysr@777 642 _cards_scanned = NULL;
ysr@777 643 // Cleanup after copy
ysr@777 644 #if G1_REM_SET_LOGGING
ysr@777 645 PrintRSClosure cl;
ysr@777 646 _g1->heap_region_iterate(&cl);
ysr@777 647 #endif
ysr@777 648 _g1->set_refine_cte_cl_concurrency(true);
ysr@777 649 cleanUpIteratorsClosure iterClosure;
ysr@777 650 _g1->collection_set_iterate(&iterClosure);
ysr@777 651 // Set all cards back to clean.
ysr@777 652 _g1->cleanUpCardTable();
ysr@777 653 if (ParallelGCThreads > 0) {
ysr@777 654 ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine();
ysr@777 655 if (cg1r->do_traversal()) {
ysr@777 656 cg1r->cg1rThread()->set_do_traversal(false);
ysr@777 657 }
ysr@777 658 set_par_traversal(false);
ysr@777 659 }
iveresov@1051 660
iveresov@1051 661 if (_g1->evacuation_failed()) {
iveresov@1051 662 // Restore remembered sets for the regions pointing into
iveresov@1051 663 // the collection set.
iveresov@1051 664 if (G1DeferredRSUpdate) {
iveresov@1051 665 DirtyCardQueue dcq(&_g1->dirty_card_queue_set());
iveresov@1051 666 UpdateRSetOopsIntoCSDeferred deferred_update(_g1, &dcq);
iveresov@1051 667 new_refs_iterate(&deferred_update);
iveresov@1051 668 } else {
iveresov@1051 669 UpdateRSetOopsIntoCSImmediate immediate_update(_g1);
iveresov@1051 670 new_refs_iterate(&immediate_update);
iveresov@1051 671 }
iveresov@1051 672 }
iveresov@1051 673 for (uint i = 0; i < n_workers(); i++) {
iveresov@1051 674 _new_refs[i]->clear();
iveresov@1051 675 }
iveresov@1051 676
ysr@777 677 assert(!_par_traversal_in_progress, "Invariant between iterations.");
ysr@777 678 }
ysr@777 679
ysr@777 680 class UpdateRSObjectClosure: public ObjectClosure {
ysr@777 681 UpdateRSOopClosure* _update_rs_oop_cl;
ysr@777 682 public:
ysr@777 683 UpdateRSObjectClosure(UpdateRSOopClosure* update_rs_oop_cl) :
ysr@777 684 _update_rs_oop_cl(update_rs_oop_cl) {}
ysr@777 685 void do_object(oop obj) {
ysr@777 686 obj->oop_iterate(_update_rs_oop_cl);
ysr@777 687 }
ysr@777 688
ysr@777 689 };
ysr@777 690
ysr@777 691 class ScrubRSClosure: public HeapRegionClosure {
ysr@777 692 G1CollectedHeap* _g1h;
ysr@777 693 BitMap* _region_bm;
ysr@777 694 BitMap* _card_bm;
ysr@777 695 CardTableModRefBS* _ctbs;
ysr@777 696 public:
ysr@777 697 ScrubRSClosure(BitMap* region_bm, BitMap* card_bm) :
ysr@777 698 _g1h(G1CollectedHeap::heap()),
ysr@777 699 _region_bm(region_bm), _card_bm(card_bm),
ysr@777 700 _ctbs(NULL)
ysr@777 701 {
ysr@777 702 ModRefBarrierSet* bs = _g1h->mr_bs();
ysr@777 703 guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition");
ysr@777 704 _ctbs = (CardTableModRefBS*)bs;
ysr@777 705 }
ysr@777 706
ysr@777 707 bool doHeapRegion(HeapRegion* r) {
ysr@777 708 if (!r->continuesHumongous()) {
ysr@777 709 r->rem_set()->scrub(_ctbs, _region_bm, _card_bm);
ysr@777 710 }
ysr@777 711 return false;
ysr@777 712 }
ysr@777 713 };
ysr@777 714
ysr@777 715 void HRInto_G1RemSet::scrub(BitMap* region_bm, BitMap* card_bm) {
ysr@777 716 ScrubRSClosure scrub_cl(region_bm, card_bm);
ysr@777 717 _g1->heap_region_iterate(&scrub_cl);
ysr@777 718 }
ysr@777 719
ysr@777 720 void HRInto_G1RemSet::scrub_par(BitMap* region_bm, BitMap* card_bm,
ysr@777 721 int worker_num, int claim_val) {
ysr@777 722 ScrubRSClosure scrub_cl(region_bm, card_bm);
ysr@777 723 _g1->heap_region_par_iterate_chunked(&scrub_cl, worker_num, claim_val);
ysr@777 724 }
ysr@777 725
ysr@777 726
ysr@777 727 class ConcRefineRegionClosure: public HeapRegionClosure {
ysr@777 728 G1CollectedHeap* _g1h;
ysr@777 729 CardTableModRefBS* _ctbs;
ysr@777 730 ConcurrentGCThread* _cgc_thrd;
ysr@777 731 ConcurrentG1Refine* _cg1r;
ysr@777 732 unsigned _cards_processed;
ysr@777 733 UpdateRSOopClosure _update_rs_oop_cl;
ysr@777 734 public:
ysr@777 735 ConcRefineRegionClosure(CardTableModRefBS* ctbs,
ysr@777 736 ConcurrentG1Refine* cg1r,
ysr@777 737 HRInto_G1RemSet* g1rs) :
ysr@777 738 _ctbs(ctbs), _cg1r(cg1r), _cgc_thrd(cg1r->cg1rThread()),
ysr@777 739 _update_rs_oop_cl(g1rs), _cards_processed(0),
ysr@777 740 _g1h(G1CollectedHeap::heap())
ysr@777 741 {}
ysr@777 742
ysr@777 743 bool doHeapRegion(HeapRegion* r) {
ysr@777 744 if (!r->in_collection_set() &&
ysr@777 745 !r->continuesHumongous() &&
iveresov@1051 746 !r->is_young() &&
iveresov@1051 747 !r->is_survivor()) {
ysr@777 748 _update_rs_oop_cl.set_from(r);
ysr@777 749 UpdateRSObjectClosure update_rs_obj_cl(&_update_rs_oop_cl);
ysr@777 750
ysr@777 751 // For each run of dirty card in the region:
ysr@777 752 // 1) Clear the cards.
ysr@777 753 // 2) Process the range corresponding to the run, adding any
ysr@777 754 // necessary RS entries.
ysr@777 755 // 1 must precede 2, so that a concurrent modification redirties the
ysr@777 756 // card. If a processing attempt does not succeed, because it runs
ysr@777 757 // into an unparseable region, we will do binary search to find the
ysr@777 758 // beginning of the next parseable region.
ysr@777 759 HeapWord* startAddr = r->bottom();
ysr@777 760 HeapWord* endAddr = r->used_region().end();
ysr@777 761 HeapWord* lastAddr;
ysr@777 762 HeapWord* nextAddr;
ysr@777 763
ysr@777 764 for (nextAddr = lastAddr = startAddr;
ysr@777 765 nextAddr < endAddr;
ysr@777 766 nextAddr = lastAddr) {
ysr@777 767 MemRegion dirtyRegion;
ysr@777 768
ysr@777 769 // Get and clear dirty region from card table
ysr@777 770 MemRegion next_mr(nextAddr, endAddr);
ysr@777 771 dirtyRegion =
ysr@777 772 _ctbs->dirty_card_range_after_reset(
ysr@777 773 next_mr,
ysr@777 774 true, CardTableModRefBS::clean_card_val());
ysr@777 775 assert(dirtyRegion.start() >= nextAddr,
ysr@777 776 "returned region inconsistent?");
ysr@777 777
ysr@777 778 if (!dirtyRegion.is_empty()) {
ysr@777 779 HeapWord* stop_point =
ysr@777 780 r->object_iterate_mem_careful(dirtyRegion,
ysr@777 781 &update_rs_obj_cl);
ysr@777 782 if (stop_point == NULL) {
ysr@777 783 lastAddr = dirtyRegion.end();
ysr@777 784 _cards_processed +=
ysr@777 785 (int) (dirtyRegion.word_size() / CardTableModRefBS::card_size_in_words);
ysr@777 786 } else {
ysr@777 787 // We're going to skip one or more cards that we can't parse.
ysr@777 788 HeapWord* next_parseable_card =
ysr@777 789 r->next_block_start_careful(stop_point);
ysr@777 790 // Round this up to a card boundary.
ysr@777 791 next_parseable_card =
ysr@777 792 _ctbs->addr_for(_ctbs->byte_after_const(next_parseable_card));
ysr@777 793 // Now we invalidate the intervening cards so we'll see them
ysr@777 794 // again.
ysr@777 795 MemRegion remaining_dirty =
ysr@777 796 MemRegion(stop_point, dirtyRegion.end());
ysr@777 797 MemRegion skipped =
ysr@777 798 MemRegion(stop_point, next_parseable_card);
ysr@777 799 _ctbs->invalidate(skipped.intersection(remaining_dirty));
ysr@777 800
ysr@777 801 // Now start up again where we can parse.
ysr@777 802 lastAddr = next_parseable_card;
ysr@777 803
ysr@777 804 // Count how many we did completely.
ysr@777 805 _cards_processed +=
ysr@777 806 (stop_point - dirtyRegion.start()) /
ysr@777 807 CardTableModRefBS::card_size_in_words;
ysr@777 808 }
ysr@777 809 // Allow interruption at regular intervals.
ysr@777 810 // (Might need to make them more regular, if we get big
ysr@777 811 // dirty regions.)
ysr@777 812 if (_cgc_thrd != NULL) {
ysr@777 813 if (_cgc_thrd->should_yield()) {
ysr@777 814 _cgc_thrd->yield();
ysr@777 815 switch (_cg1r->get_pya()) {
ysr@777 816 case PYA_continue:
ysr@777 817 // This may have changed: re-read.
ysr@777 818 endAddr = r->used_region().end();
ysr@777 819 continue;
ysr@777 820 case PYA_restart: case PYA_cancel:
ysr@777 821 return true;
ysr@777 822 }
ysr@777 823 }
ysr@777 824 }
ysr@777 825 } else {
ysr@777 826 break;
ysr@777 827 }
ysr@777 828 }
ysr@777 829 }
ysr@777 830 // A good yield opportunity.
ysr@777 831 if (_cgc_thrd != NULL) {
ysr@777 832 if (_cgc_thrd->should_yield()) {
ysr@777 833 _cgc_thrd->yield();
ysr@777 834 switch (_cg1r->get_pya()) {
ysr@777 835 case PYA_restart: case PYA_cancel:
ysr@777 836 return true;
ysr@777 837 default:
ysr@777 838 break;
ysr@777 839 }
ysr@777 840
ysr@777 841 }
ysr@777 842 }
ysr@777 843 return false;
ysr@777 844 }
ysr@777 845
ysr@777 846 unsigned cards_processed() { return _cards_processed; }
ysr@777 847 };
ysr@777 848
ysr@777 849
ysr@777 850 void HRInto_G1RemSet::concurrentRefinementPass(ConcurrentG1Refine* cg1r) {
ysr@777 851 ConcRefineRegionClosure cr_cl(ct_bs(), cg1r, this);
ysr@777 852 _g1->heap_region_iterate(&cr_cl);
ysr@777 853 _conc_refine_traversals++;
ysr@777 854 _conc_refine_cards += cr_cl.cards_processed();
ysr@777 855 }
ysr@777 856
ysr@777 857 static IntHistogram out_of_histo(50, 50);
ysr@777 858
ysr@777 859
ysr@777 860
ysr@777 861 void HRInto_G1RemSet::concurrentRefineOneCard(jbyte* card_ptr, int worker_i) {
ysr@777 862 // If the card is no longer dirty, nothing to do.
ysr@777 863 if (*card_ptr != CardTableModRefBS::dirty_card_val()) return;
ysr@777 864
ysr@777 865 // Construct the region representing the card.
ysr@777 866 HeapWord* start = _ct_bs->addr_for(card_ptr);
ysr@777 867 // And find the region containing it.
ysr@777 868 HeapRegion* r = _g1->heap_region_containing(start);
ysr@777 869 if (r == NULL) {
ysr@777 870 guarantee(_g1->is_in_permanent(start), "Or else where?");
ysr@777 871 return; // Not in the G1 heap (might be in perm, for example.)
ysr@777 872 }
ysr@777 873 // Why do we have to check here whether a card is on a young region,
ysr@777 874 // given that we dirty young regions and, as a result, the
ysr@777 875 // post-barrier is supposed to filter them out and never to enqueue
ysr@777 876 // them? When we allocate a new region as the "allocation region" we
ysr@777 877 // actually dirty its cards after we release the lock, since card
ysr@777 878 // dirtying while holding the lock was a performance bottleneck. So,
ysr@777 879 // as a result, it is possible for other threads to actually
ysr@777 880 // allocate objects in the region (after the acquire the lock)
ysr@777 881 // before all the cards on the region are dirtied. This is unlikely,
ysr@777 882 // and it doesn't happen often, but it can happen. So, the extra
ysr@777 883 // check below filters out those cards.
iveresov@1051 884 if (r->is_young() || r->is_survivor()) {
ysr@777 885 return;
ysr@777 886 }
ysr@777 887 // While we are processing RSet buffers during the collection, we
ysr@777 888 // actually don't want to scan any cards on the collection set,
ysr@777 889 // since we don't want to update remebered sets with entries that
ysr@777 890 // point into the collection set, given that live objects from the
ysr@777 891 // collection set are about to move and such entries will be stale
ysr@777 892 // very soon. This change also deals with a reliability issue which
ysr@777 893 // involves scanning a card in the collection set and coming across
ysr@777 894 // an array that was being chunked and looking malformed. Note,
ysr@777 895 // however, that if evacuation fails, we have to scan any objects
ysr@777 896 // that were not moved and create any missing entries.
ysr@777 897 if (r->in_collection_set()) {
ysr@777 898 return;
ysr@777 899 }
ysr@777 900
ysr@777 901 // Should we defer it?
ysr@777 902 if (_cg1r->use_cache()) {
ysr@777 903 card_ptr = _cg1r->cache_insert(card_ptr);
ysr@777 904 // If it was not an eviction, nothing to do.
ysr@777 905 if (card_ptr == NULL) return;
ysr@777 906
ysr@777 907 // OK, we have to reset the card start, region, etc.
ysr@777 908 start = _ct_bs->addr_for(card_ptr);
ysr@777 909 r = _g1->heap_region_containing(start);
ysr@777 910 if (r == NULL) {
ysr@777 911 guarantee(_g1->is_in_permanent(start), "Or else where?");
ysr@777 912 return; // Not in the G1 heap (might be in perm, for example.)
ysr@777 913 }
ysr@777 914 guarantee(!r->is_young(), "It was evicted in the current minor cycle.");
ysr@777 915 }
ysr@777 916
ysr@777 917 HeapWord* end = _ct_bs->addr_for(card_ptr + 1);
ysr@777 918 MemRegion dirtyRegion(start, end);
ysr@777 919
ysr@777 920 #if CARD_REPEAT_HISTO
ysr@777 921 init_ct_freq_table(_g1->g1_reserved_obj_bytes());
ysr@777 922 ct_freq_note_card(_ct_bs->index_for(start));
ysr@777 923 #endif
ysr@777 924
ysr@777 925 UpdateRSOopClosure update_rs_oop_cl(this, worker_i);
ysr@777 926 update_rs_oop_cl.set_from(r);
ysr@777 927 FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r, &update_rs_oop_cl);
ysr@777 928
ysr@777 929 // Undirty the card.
ysr@777 930 *card_ptr = CardTableModRefBS::clean_card_val();
ysr@777 931 // We must complete this write before we do any of the reads below.
ysr@777 932 OrderAccess::storeload();
ysr@777 933 // And process it, being careful of unallocated portions of TLAB's.
ysr@777 934 HeapWord* stop_point =
ysr@777 935 r->oops_on_card_seq_iterate_careful(dirtyRegion,
ysr@777 936 &filter_then_update_rs_oop_cl);
ysr@777 937 // If stop_point is non-null, then we encountered an unallocated region
ysr@777 938 // (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the
ysr@777 939 // card and re-enqueue: if we put off the card until a GC pause, then the
ysr@777 940 // unallocated portion will be filled in. Alternatively, we might try
ysr@777 941 // the full complexity of the technique used in "regular" precleaning.
ysr@777 942 if (stop_point != NULL) {
ysr@777 943 // The card might have gotten re-dirtied and re-enqueued while we
ysr@777 944 // worked. (In fact, it's pretty likely.)
ysr@777 945 if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
ysr@777 946 *card_ptr = CardTableModRefBS::dirty_card_val();
ysr@777 947 MutexLockerEx x(Shared_DirtyCardQ_lock,
ysr@777 948 Mutex::_no_safepoint_check_flag);
ysr@777 949 DirtyCardQueue* sdcq =
ysr@777 950 JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
ysr@777 951 sdcq->enqueue(card_ptr);
ysr@777 952 }
ysr@777 953 } else {
ysr@777 954 out_of_histo.add_entry(filter_then_update_rs_oop_cl.out_of_region());
ysr@777 955 _conc_refine_cards++;
ysr@777 956 }
ysr@777 957 }
ysr@777 958
ysr@777 959 class HRRSStatsIter: public HeapRegionClosure {
ysr@777 960 size_t _occupied;
ysr@777 961 size_t _total_mem_sz;
ysr@777 962 size_t _max_mem_sz;
ysr@777 963 HeapRegion* _max_mem_sz_region;
ysr@777 964 public:
ysr@777 965 HRRSStatsIter() :
ysr@777 966 _occupied(0),
ysr@777 967 _total_mem_sz(0),
ysr@777 968 _max_mem_sz(0),
ysr@777 969 _max_mem_sz_region(NULL)
ysr@777 970 {}
ysr@777 971
ysr@777 972 bool doHeapRegion(HeapRegion* r) {
ysr@777 973 if (r->continuesHumongous()) return false;
ysr@777 974 size_t mem_sz = r->rem_set()->mem_size();
ysr@777 975 if (mem_sz > _max_mem_sz) {
ysr@777 976 _max_mem_sz = mem_sz;
ysr@777 977 _max_mem_sz_region = r;
ysr@777 978 }
ysr@777 979 _total_mem_sz += mem_sz;
ysr@777 980 size_t occ = r->rem_set()->occupied();
ysr@777 981 _occupied += occ;
ysr@777 982 return false;
ysr@777 983 }
ysr@777 984 size_t total_mem_sz() { return _total_mem_sz; }
ysr@777 985 size_t max_mem_sz() { return _max_mem_sz; }
ysr@777 986 size_t occupied() { return _occupied; }
ysr@777 987 HeapRegion* max_mem_sz_region() { return _max_mem_sz_region; }
ysr@777 988 };
ysr@777 989
ysr@777 990 void HRInto_G1RemSet::print_summary_info() {
ysr@777 991 G1CollectedHeap* g1 = G1CollectedHeap::heap();
ysr@777 992 ConcurrentG1RefineThread* cg1r_thrd =
ysr@777 993 g1->concurrent_g1_refine()->cg1rThread();
ysr@777 994
ysr@777 995 #if CARD_REPEAT_HISTO
ysr@777 996 gclog_or_tty->print_cr("\nG1 card_repeat count histogram: ");
ysr@777 997 gclog_or_tty->print_cr(" # of repeats --> # of cards with that number.");
ysr@777 998 card_repeat_count.print_on(gclog_or_tty);
ysr@777 999 #endif
ysr@777 1000
ysr@777 1001 if (FILTEROUTOFREGIONCLOSURE_DOHISTOGRAMCOUNT) {
ysr@777 1002 gclog_or_tty->print_cr("\nG1 rem-set out-of-region histogram: ");
ysr@777 1003 gclog_or_tty->print_cr(" # of CS ptrs --> # of cards with that number.");
ysr@777 1004 out_of_histo.print_on(gclog_or_tty);
ysr@777 1005 }
ysr@777 1006 gclog_or_tty->print_cr("\n Concurrent RS processed %d cards in "
ysr@777 1007 "%5.2fs.",
ysr@777 1008 _conc_refine_cards, cg1r_thrd->vtime_accum());
ysr@777 1009
ysr@777 1010 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 1011 jint tot_processed_buffers =
ysr@777 1012 dcqs.processed_buffers_mut() + dcqs.processed_buffers_rs_thread();
ysr@777 1013 gclog_or_tty->print_cr(" Of %d completed buffers:", tot_processed_buffers);
ysr@777 1014 gclog_or_tty->print_cr(" %8d (%5.1f%%) by conc RS thread.",
ysr@777 1015 dcqs.processed_buffers_rs_thread(),
ysr@777 1016 100.0*(float)dcqs.processed_buffers_rs_thread()/
ysr@777 1017 (float)tot_processed_buffers);
ysr@777 1018 gclog_or_tty->print_cr(" %8d (%5.1f%%) by mutator threads.",
ysr@777 1019 dcqs.processed_buffers_mut(),
ysr@777 1020 100.0*(float)dcqs.processed_buffers_mut()/
ysr@777 1021 (float)tot_processed_buffers);
ysr@777 1022 gclog_or_tty->print_cr(" Did %d concurrent refinement traversals.",
ysr@777 1023 _conc_refine_traversals);
ysr@777 1024 if (!G1RSBarrierUseQueue) {
ysr@777 1025 gclog_or_tty->print_cr(" Scanned %8.2f cards/traversal.",
ysr@777 1026 _conc_refine_traversals > 0 ?
ysr@777 1027 (float)_conc_refine_cards/(float)_conc_refine_traversals :
ysr@777 1028 0);
ysr@777 1029 }
ysr@777 1030 gclog_or_tty->print_cr("");
ysr@777 1031 if (G1UseHRIntoRS) {
ysr@777 1032 HRRSStatsIter blk;
ysr@777 1033 g1->heap_region_iterate(&blk);
ysr@777 1034 gclog_or_tty->print_cr(" Total heap region rem set sizes = " SIZE_FORMAT "K."
ysr@777 1035 " Max = " SIZE_FORMAT "K.",
ysr@777 1036 blk.total_mem_sz()/K, blk.max_mem_sz()/K);
ysr@777 1037 gclog_or_tty->print_cr(" Static structures = " SIZE_FORMAT "K,"
ysr@777 1038 " free_lists = " SIZE_FORMAT "K.",
ysr@777 1039 HeapRegionRemSet::static_mem_size()/K,
ysr@777 1040 HeapRegionRemSet::fl_mem_size()/K);
ysr@777 1041 gclog_or_tty->print_cr(" %d occupied cards represented.",
ysr@777 1042 blk.occupied());
ysr@777 1043 gclog_or_tty->print_cr(" Max sz region = [" PTR_FORMAT ", " PTR_FORMAT " )"
ysr@777 1044 " %s, cap = " SIZE_FORMAT "K, occ = " SIZE_FORMAT "K.",
ysr@777 1045 blk.max_mem_sz_region()->bottom(), blk.max_mem_sz_region()->end(),
ysr@777 1046 (blk.max_mem_sz_region()->popular() ? "POP" : ""),
ysr@777 1047 (blk.max_mem_sz_region()->rem_set()->mem_size() + K - 1)/K,
ysr@777 1048 (blk.max_mem_sz_region()->rem_set()->occupied() + K - 1)/K);
ysr@777 1049 gclog_or_tty->print_cr(" Did %d coarsenings.",
ysr@777 1050 HeapRegionRemSet::n_coarsenings());
ysr@777 1051
ysr@777 1052 }
ysr@777 1053 }
ysr@777 1054 void HRInto_G1RemSet::prepare_for_verify() {
ysr@777 1055 if (G1HRRSFlushLogBuffersOnVerify && VerifyBeforeGC && !_g1->full_collection()) {
ysr@777 1056 cleanupHRRS();
ysr@777 1057 _g1->set_refine_cte_cl_concurrency(false);
ysr@777 1058 if (SafepointSynchronize::is_at_safepoint()) {
ysr@777 1059 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
ysr@777 1060 dcqs.concatenate_logs();
ysr@777 1061 }
ysr@777 1062 bool cg1r_use_cache = _cg1r->use_cache();
ysr@777 1063 _cg1r->set_use_cache(false);
ysr@777 1064 updateRS(0);
ysr@777 1065 _cg1r->set_use_cache(cg1r_use_cache);
ysr@777 1066 }
ysr@777 1067 }

mercurial