annotate src/share/vm/gc_implementation/g1/g1RemSet.cpp @ 2076:c33825b68624

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