1 /* 2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/g1/g1BarrierSet.hpp" 27 #include "gc/g1/g1BlockOffsetTable.inline.hpp" 28 #include "gc/g1/g1CardTable.inline.hpp" 29 #include "gc/g1/g1CardTableEntryClosure.hpp" 30 #include "gc/g1/g1CollectedHeap.inline.hpp" 31 #include "gc/g1/g1ConcurrentRefine.hpp" 32 #include "gc/g1/g1DirtyCardQueue.hpp" 33 #include "gc/g1/g1FromCardCache.hpp" 34 #include "gc/g1/g1GCPhaseTimes.hpp" 35 #include "gc/g1/g1HotCardCache.hpp" 36 #include "gc/g1/g1OopClosures.inline.hpp" 37 #include "gc/g1/g1RootClosures.hpp" 38 #include "gc/g1/g1RemSet.hpp" 39 #include "gc/g1/g1SharedDirtyCardQueue.hpp" 40 #include "gc/g1/heapRegion.inline.hpp" 41 #include "gc/g1/heapRegionManager.inline.hpp" 42 #include "gc/g1/heapRegionRemSet.inline.hpp" 43 #include "gc/g1/sparsePRT.hpp" 44 #include "gc/shared/gcTraceTime.inline.hpp" 45 #include "gc/shared/ptrQueue.hpp" 46 #include "gc/shared/suspendibleThreadSet.hpp" 47 #include "jfr/jfrEvents.hpp" 48 #include "memory/iterator.hpp" 49 #include "memory/resourceArea.hpp" 50 #include "oops/access.inline.hpp" 51 #include "oops/oop.inline.hpp" 52 #include "runtime/os.hpp" 53 #include "utilities/align.hpp" 54 #include "utilities/globalDefinitions.hpp" 55 #include "utilities/stack.inline.hpp" 56 #include "utilities/ticks.hpp" 57 58 // Collects information about the overall heap root scan progress during an evacuation. 59 // 60 // Scanning the remembered sets works by first merging all sources of cards to be 61 // scanned (log buffers, hcc, remembered sets) into a single data structure to remove 62 // duplicates and simplify work distribution. 63 // 64 // During the following card scanning we not only scan this combined set of cards, but 65 // also remember that these were completely scanned. The following evacuation passes 66 // do not scan these cards again, and so need to be preserved across increments. 67 // 68 // The representation for all the cards to scan is the card table: cards can have 69 // one of three states during GC: 70 // - clean: these cards will not be scanned in this pass 71 // - dirty: these cards will be scanned in this pass 72 // - scanned: these cards have already been scanned in a previous pass 73 // 74 // After all evacuation is done, we reset the card table to clean. 75 // 76 // Work distribution occurs on "chunk" basis, i.e. contiguous ranges of cards. As an 77 // additional optimization, during card merging we remember which regions and which 78 // chunks actually contain cards to be scanned. Threads iterate only across these 79 // regions, and only compete for chunks containing any cards. 80 // 81 // Within these chunks, a worker scans the card table on "blocks" of cards, i.e. 82 // contiguous ranges of dirty cards to be scanned. These blocks are converted to actual 83 // memory ranges and then passed on to actual scanning. 84 class G1RemSetScanState : public CHeapObj<mtGC> { 85 class G1DirtyRegions; 86 87 size_t _max_regions; 88 89 // Has this region that is part of the regions in the collection set been processed yet. 90 typedef bool G1RemsetIterState; 91 92 G1RemsetIterState volatile* _collection_set_iter_state; 93 94 // Card table iteration claim for each heap region, from 0 (completely unscanned) 95 // to (>=) HeapRegion::CardsPerRegion (completely scanned). 96 uint volatile* _card_table_scan_state; 97 98 // Return "optimal" number of chunks per region we want to use for claiming areas 99 // within a region to claim. Dependent on the region size as proxy for the heap 100 // size, we limit the total number of chunks to limit memory usage and maintenance 101 // effort of that table vs. granularity of distributing scanning work. 102 // Testing showed that 8 for 1M/2M region, 16 for 4M/8M regions, 32 for 16/32M regions 103 // seems to be such a good trade-off. 104 static uint get_chunks_per_region(uint log_region_size) { 105 // Limit the expected input values to current known possible values of the 106 // (log) region size. Adjust as necessary after testing if changing the permissible 107 // values for region size. 108 assert(log_region_size >= 20 && log_region_size <= 25, 109 "expected value in [20,25], but got %u", log_region_size); 110 return 1u << (log_region_size / 2 - 7); 111 } 112 113 uint _scan_chunks_per_region; // Number of chunks per region. 114 uint8_t _log_scan_chunks_per_region; // Log of number of chunks per region. 115 bool* _region_scan_chunks; 116 size_t _num_total_scan_chunks; // Total number of elements in _region_scan_chunks. 117 uint8_t _scan_chunks_shift; // For conversion between card index and chunk index. 118 public: 119 uint scan_chunk_size() const { return (uint)1 << _scan_chunks_shift; } 120 121 // Returns whether the chunk corresponding to the given region/card in region contain a 122 // dirty card, i.e. actually needs scanning. 123 bool chunk_needs_scan(uint const region_idx, uint const card_in_region) const { 124 size_t const idx = ((size_t)region_idx << _log_scan_chunks_per_region) + (card_in_region >> _scan_chunks_shift); 125 assert(idx < _num_total_scan_chunks, "Index " SIZE_FORMAT " out of bounds " SIZE_FORMAT, 126 idx, _num_total_scan_chunks); 127 return _region_scan_chunks[idx]; 128 } 129 130 private: 131 // The complete set of regions which card table needs to be cleared at the end of GC because 132 // we scribbled all over them. 133 G1DirtyRegions* _all_dirty_regions; 134 // The set of regions which card table needs to be scanned for new dirty cards 135 // in the current evacuation pass. 136 G1DirtyRegions* _next_dirty_regions; 137 138 // Set of (unique) regions that can be added to concurrently. 139 class G1DirtyRegions : public CHeapObj<mtGC> { 140 uint* _buffer; 141 uint _cur_idx; 142 size_t _max_regions; 143 144 bool* _contains; 145 146 public: 147 G1DirtyRegions(size_t max_regions) : 148 _buffer(NEW_C_HEAP_ARRAY(uint, max_regions, mtGC)), 149 _cur_idx(0), 150 _max_regions(max_regions), 151 _contains(NEW_C_HEAP_ARRAY(bool, max_regions, mtGC)) { 152 153 reset(); 154 } 155 156 static size_t chunk_size() { return M; } 157 158 ~G1DirtyRegions() { 159 FREE_C_HEAP_ARRAY(uint, _buffer); 160 FREE_C_HEAP_ARRAY(bool, _contains); 161 } 162 163 void reset() { 164 _cur_idx = 0; 165 ::memset(_contains, false, _max_regions * sizeof(bool)); 166 } 167 168 uint size() const { return _cur_idx; } 169 170 uint at(uint idx) const { 171 assert(idx < _cur_idx, "Index %u beyond valid regions", idx); 172 return _buffer[idx]; 173 } 174 175 void add_dirty_region(uint region) { 176 if (_contains[region]) { 177 return; 178 } 179 180 bool marked_as_dirty = Atomic::cmpxchg(true, &_contains[region], false) == false; 181 if (marked_as_dirty) { 182 uint allocated = Atomic::add(1u, &_cur_idx) - 1; 183 _buffer[allocated] = region; 184 } 185 } 186 187 // Creates the union of this and the other G1DirtyRegions. 188 void merge(const G1DirtyRegions* other) { 189 for (uint i = 0; i < other->size(); i++) { 190 uint region = other->at(i); 191 if (!_contains[region]) { 192 _buffer[_cur_idx++] = region; 193 _contains[region] = true; 194 } 195 } 196 } 197 }; 198 199 // Creates a snapshot of the current _top values at the start of collection to 200 // filter out card marks that we do not want to scan. 201 class G1ResetScanTopClosure : public HeapRegionClosure { 202 G1RemSetScanState* _scan_state; 203 204 public: 205 G1ResetScanTopClosure(G1RemSetScanState* scan_state) : _scan_state(scan_state) { } 206 207 virtual bool do_heap_region(HeapRegion* r) { 208 uint hrm_index = r->hrm_index(); 209 if (r->in_collection_set()) { 210 // Young regions had their card table marked as young at their allocation; 211 // we need to make sure that these marks are cleared at the end of GC, *but* 212 // they should not be scanned for cards. 213 // So directly add them to the "all_dirty_regions". 214 // Same for regions in the (initial) collection set: they may contain cards from 215 // the log buffers, make sure they are cleaned. 216 _scan_state->add_all_dirty_region(hrm_index); 217 } else if (r->is_old_or_humongous_or_archive()) { 218 _scan_state->set_scan_top(hrm_index, r->top()); 219 } 220 return false; 221 } 222 }; 223 // For each region, contains the maximum top() value to be used during this garbage 224 // collection. Subsumes common checks like filtering out everything but old and 225 // humongous regions outside the collection set. 226 // This is valid because we are not interested in scanning stray remembered set 227 // entries from free or archive regions. 228 HeapWord** _scan_top; 229 230 class G1ClearCardTableTask : public AbstractGangTask { 231 G1CollectedHeap* _g1h; 232 G1DirtyRegions* _regions; 233 uint _chunk_length; 234 235 uint volatile _cur_dirty_regions; 236 237 G1RemSetScanState* _scan_state; 238 239 public: 240 G1ClearCardTableTask(G1CollectedHeap* g1h, 241 G1DirtyRegions* regions, 242 uint chunk_length, 243 G1RemSetScanState* scan_state) : 244 AbstractGangTask("G1 Clear Card Table Task"), 245 _g1h(g1h), 246 _regions(regions), 247 _chunk_length(chunk_length), 248 _cur_dirty_regions(0), 249 _scan_state(scan_state) { 250 251 assert(chunk_length > 0, "must be"); 252 } 253 254 static uint chunk_size() { return M; } 255 256 void work(uint worker_id) { 257 while (_cur_dirty_regions < _regions->size()) { 258 uint next = Atomic::add(_chunk_length, &_cur_dirty_regions) - _chunk_length; 259 uint max = MIN2(next + _chunk_length, _regions->size()); 260 261 for (uint i = next; i < max; i++) { 262 HeapRegion* r = _g1h->region_at(_regions->at(i)); 263 if (!r->is_survivor()) { 264 r->clear_cardtable(); 265 } 266 } 267 } 268 } 269 }; 270 271 // Clear the card table of "dirty" regions. 272 void clear_card_table(WorkGang* workers) { 273 uint num_regions = _all_dirty_regions->size(); 274 275 if (num_regions == 0) { 276 return; 277 } 278 279 uint const num_chunks = (uint)(align_up((size_t)num_regions << HeapRegion::LogCardsPerRegion, G1ClearCardTableTask::chunk_size()) / G1ClearCardTableTask::chunk_size()); 280 uint const num_workers = MIN2(num_chunks, workers->active_workers()); 281 uint const chunk_length = G1ClearCardTableTask::chunk_size() / (uint)HeapRegion::CardsPerRegion; 282 283 // Iterate over the dirty cards region list. 284 G1ClearCardTableTask cl(G1CollectedHeap::heap(), _all_dirty_regions, chunk_length, this); 285 286 log_debug(gc, ergo)("Running %s using %u workers for %u " 287 "units of work for %u regions.", 288 cl.name(), num_workers, num_chunks, num_regions); 289 workers->run_task(&cl, num_workers); 290 291 #ifndef PRODUCT 292 G1CollectedHeap::heap()->verifier()->verify_card_table_cleanup(); 293 #endif 294 } 295 296 public: 297 G1RemSetScanState() : 298 _max_regions(0), 299 _collection_set_iter_state(NULL), 300 _card_table_scan_state(NULL), 301 _scan_chunks_per_region(get_chunks_per_region(HeapRegion::LogOfHRGrainBytes)), 302 _log_scan_chunks_per_region(log2_uint(_scan_chunks_per_region)), 303 _region_scan_chunks(NULL), 304 _num_total_scan_chunks(0), 305 _scan_chunks_shift(0), 306 _all_dirty_regions(NULL), 307 _next_dirty_regions(NULL), 308 _scan_top(NULL) { 309 } 310 311 ~G1RemSetScanState() { 312 FREE_C_HEAP_ARRAY(G1RemsetIterState, _collection_set_iter_state); 313 FREE_C_HEAP_ARRAY(uint, _card_table_scan_state); 314 FREE_C_HEAP_ARRAY(bool, _region_scan_chunks); 315 FREE_C_HEAP_ARRAY(HeapWord*, _scan_top); 316 } 317 318 void initialize(size_t max_regions) { 319 assert(_collection_set_iter_state == NULL, "Must not be initialized twice"); 320 _max_regions = max_regions; 321 _collection_set_iter_state = NEW_C_HEAP_ARRAY(G1RemsetIterState, max_regions, mtGC); 322 _card_table_scan_state = NEW_C_HEAP_ARRAY(uint, max_regions, mtGC); 323 _num_total_scan_chunks = max_regions * _scan_chunks_per_region; 324 _region_scan_chunks = NEW_C_HEAP_ARRAY(bool, _num_total_scan_chunks, mtGC); 325 326 _scan_chunks_shift = (uint8_t)log2_intptr(HeapRegion::CardsPerRegion / _scan_chunks_per_region); 327 _scan_top = NEW_C_HEAP_ARRAY(HeapWord*, max_regions, mtGC); 328 } 329 330 void prepare() { 331 for (size_t i = 0; i < _max_regions; i++) { 332 _collection_set_iter_state[i] = false; 333 clear_scan_top((uint)i); 334 } 335 336 _all_dirty_regions = new G1DirtyRegions(_max_regions); 337 _next_dirty_regions = new G1DirtyRegions(_max_regions); 338 339 G1ResetScanTopClosure cl(this); 340 G1CollectedHeap::heap()->heap_region_iterate(&cl); 341 } 342 343 void prepare_for_merge_heap_roots() { 344 _all_dirty_regions->merge(_next_dirty_regions); 345 346 _next_dirty_regions->reset(); 347 for (size_t i = 0; i < _max_regions; i++) { 348 _card_table_scan_state[i] = 0; 349 } 350 351 ::memset(_region_scan_chunks, false, _num_total_scan_chunks * sizeof(*_region_scan_chunks)); 352 } 353 354 // Returns whether the given region contains cards we need to scan. The remembered 355 // set and other sources may contain cards that 356 // - are in uncommitted regions 357 // - are located in the collection set 358 // - are located in free regions 359 // as we do not clean up remembered sets before merging heap roots. 360 bool contains_cards_to_process(uint const region_idx) const { 361 HeapRegion* hr = G1CollectedHeap::heap()->region_at_or_null(region_idx); 362 return (hr != NULL && !hr->in_collection_set() && hr->is_old_or_humongous_or_archive()); 363 } 364 365 size_t num_visited_cards() const { 366 size_t result = 0; 367 for (uint i = 0; i < _num_total_scan_chunks; i++) { 368 if (_region_scan_chunks[i]) { 369 result++; 370 } 371 } 372 return result * (HeapRegion::CardsPerRegion / _scan_chunks_per_region); 373 } 374 375 size_t num_cards_in_dirty_regions() const { 376 return _next_dirty_regions->size() * HeapRegion::CardsPerRegion; 377 } 378 379 void set_chunk_region_dirty(size_t const region_card_idx) { 380 size_t chunk_idx = region_card_idx >> _scan_chunks_shift; 381 for (uint i = 0; i < _scan_chunks_per_region; i++) { 382 _region_scan_chunks[chunk_idx++] = true; 383 } 384 } 385 386 void set_chunk_dirty(size_t const card_idx) { 387 assert((card_idx >> _scan_chunks_shift) < _num_total_scan_chunks, 388 "Trying to access index " SIZE_FORMAT " out of bounds " SIZE_FORMAT, 389 card_idx >> _scan_chunks_shift, _num_total_scan_chunks); 390 size_t const chunk_idx = card_idx >> _scan_chunks_shift; 391 if (!_region_scan_chunks[chunk_idx]) { 392 _region_scan_chunks[chunk_idx] = true; 393 } 394 } 395 396 void cleanup(WorkGang* workers) { 397 _all_dirty_regions->merge(_next_dirty_regions); 398 399 clear_card_table(workers); 400 401 delete _all_dirty_regions; 402 _all_dirty_regions = NULL; 403 404 delete _next_dirty_regions; 405 _next_dirty_regions = NULL; 406 } 407 408 void iterate_dirty_regions_from(HeapRegionClosure* cl, uint worker_id) { 409 uint num_regions = _next_dirty_regions->size(); 410 411 if (num_regions == 0) { 412 return; 413 } 414 415 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 416 417 WorkGang* workers = g1h->workers(); 418 uint const max_workers = workers->active_workers(); 419 420 uint const start_pos = num_regions * worker_id / max_workers; 421 uint cur = start_pos; 422 423 do { 424 bool result = cl->do_heap_region(g1h->region_at(_next_dirty_regions->at(cur))); 425 guarantee(!result, "Not allowed to ask for early termination."); 426 cur++; 427 if (cur == _next_dirty_regions->size()) { 428 cur = 0; 429 } 430 } while (cur != start_pos); 431 } 432 433 // Attempt to claim the given region in the collection set for iteration. Returns true 434 // if this call caused the transition from Unclaimed to Claimed. 435 inline bool claim_collection_set_region(uint region) { 436 assert(region < _max_regions, "Tried to access invalid region %u", region); 437 if (_collection_set_iter_state[region]) { 438 return false; 439 } 440 return !Atomic::cmpxchg(true, &_collection_set_iter_state[region], false); 441 } 442 443 bool has_cards_to_scan(uint region) { 444 assert(region < _max_regions, "Tried to access invalid region %u", region); 445 return _card_table_scan_state[region] < HeapRegion::CardsPerRegion; 446 } 447 448 uint claim_cards_to_scan(uint region, uint increment) { 449 assert(region < _max_regions, "Tried to access invalid region %u", region); 450 return Atomic::add(increment, &_card_table_scan_state[region]) - increment; 451 } 452 453 void add_dirty_region(uint const region) { 454 #ifdef ASSERT 455 HeapRegion* hr = G1CollectedHeap::heap()->region_at(region); 456 assert(!hr->in_collection_set() && hr->is_old_or_humongous_or_archive(), 457 "Region %u is not suitable for scanning, is %sin collection set or %s", 458 hr->hrm_index(), hr->in_collection_set() ? "" : "not ", hr->get_short_type_str()); 459 #endif 460 _next_dirty_regions->add_dirty_region(region); 461 } 462 463 void add_all_dirty_region(uint region) { 464 #ifdef ASSERT 465 HeapRegion* hr = G1CollectedHeap::heap()->region_at(region); 466 assert(hr->in_collection_set(), 467 "Only add young regions to all dirty regions directly but %u is %s", 468 hr->hrm_index(), hr->get_short_type_str()); 469 #endif 470 _all_dirty_regions->add_dirty_region(region); 471 } 472 473 void set_scan_top(uint region_idx, HeapWord* value) { 474 _scan_top[region_idx] = value; 475 } 476 477 HeapWord* scan_top(uint region_idx) const { 478 return _scan_top[region_idx]; 479 } 480 481 void clear_scan_top(uint region_idx) { 482 set_scan_top(region_idx, NULL); 483 } 484 }; 485 486 G1RemSet::G1RemSet(G1CollectedHeap* g1h, 487 G1CardTable* ct, 488 G1HotCardCache* hot_card_cache) : 489 _scan_state(new G1RemSetScanState()), 490 _prev_period_summary(false), 491 _g1h(g1h), 492 _ct(ct), 493 _g1p(_g1h->policy()), 494 _hot_card_cache(hot_card_cache) { 495 } 496 497 G1RemSet::~G1RemSet() { 498 delete _scan_state; 499 } 500 501 uint G1RemSet::num_par_rem_sets() { 502 return G1DirtyCardQueueSet::num_par_ids() + G1ConcurrentRefine::max_num_threads() + MAX2(ConcGCThreads, ParallelGCThreads); 503 } 504 505 void G1RemSet::initialize(size_t capacity, uint max_regions) { 506 G1FromCardCache::initialize(num_par_rem_sets(), max_regions); 507 _scan_state->initialize(max_regions); 508 } 509 510 // Helper class to scan and detect ranges of cards that need to be scanned on the 511 // card table. 512 class G1CardTableScanner : public StackObj { 513 public: 514 typedef CardTable::CardValue CardValue; 515 516 private: 517 CardValue* const _base_addr; 518 519 CardValue* _cur_addr; 520 CardValue* const _end_addr; 521 522 static const size_t ToScanMask = G1CardTable::g1_card_already_scanned; 523 static const size_t ExpandedToScanMask = G1CardTable::WordAlreadyScanned; 524 525 bool cur_addr_aligned() const { 526 return ((uintptr_t)_cur_addr) % sizeof(size_t) == 0; 527 } 528 529 bool cur_card_is_dirty() const { 530 CardValue value = *_cur_addr; 531 return (value & ToScanMask) == 0; 532 } 533 534 bool cur_word_of_cards_contains_any_dirty_card() const { 535 assert(cur_addr_aligned(), "Current address should be aligned"); 536 size_t const value = *(size_t*)_cur_addr; 537 return (~value & ExpandedToScanMask) != 0; 538 } 539 540 bool cur_word_of_cards_all_dirty_cards() const { 541 size_t const value = *(size_t*)_cur_addr; 542 return value == G1CardTable::WordAllDirty; 543 } 544 545 size_t get_and_advance_pos() { 546 _cur_addr++; 547 return pointer_delta(_cur_addr, _base_addr, sizeof(CardValue)) - 1; 548 } 549 550 public: 551 G1CardTableScanner(CardValue* start_card, size_t size) : 552 _base_addr(start_card), 553 _cur_addr(start_card), 554 _end_addr(start_card + size) { 555 556 assert(is_aligned(start_card, sizeof(size_t)), "Unaligned start addr " PTR_FORMAT, p2i(start_card)); 557 assert(is_aligned(size, sizeof(size_t)), "Unaligned size " SIZE_FORMAT, size); 558 } 559 560 size_t find_next_dirty() { 561 while (!cur_addr_aligned()) { 562 if (cur_card_is_dirty()) { 563 return get_and_advance_pos(); 564 } 565 _cur_addr++; 566 } 567 568 assert(cur_addr_aligned(), "Current address should be aligned now."); 569 while (_cur_addr != _end_addr) { 570 if (cur_word_of_cards_contains_any_dirty_card()) { 571 for (size_t i = 0; i < sizeof(size_t); i++) { 572 if (cur_card_is_dirty()) { 573 return get_and_advance_pos(); 574 } 575 _cur_addr++; 576 } 577 assert(false, "Should not reach here given we detected a dirty card in the word."); 578 } 579 _cur_addr += sizeof(size_t); 580 } 581 return get_and_advance_pos(); 582 } 583 584 size_t find_next_non_dirty() { 585 assert(_cur_addr <= _end_addr, "Not allowed to search for marks after area."); 586 587 while (!cur_addr_aligned()) { 588 if (!cur_card_is_dirty()) { 589 return get_and_advance_pos(); 590 } 591 _cur_addr++; 592 } 593 594 assert(cur_addr_aligned(), "Current address should be aligned now."); 595 while (_cur_addr != _end_addr) { 596 if (!cur_word_of_cards_all_dirty_cards()) { 597 for (size_t i = 0; i < sizeof(size_t); i++) { 598 if (!cur_card_is_dirty()) { 599 return get_and_advance_pos(); 600 } 601 _cur_addr++; 602 } 603 assert(false, "Should not reach here given we detected a non-dirty card in the word."); 604 } 605 _cur_addr += sizeof(size_t); 606 } 607 return get_and_advance_pos(); 608 } 609 }; 610 611 // Helper class to claim dirty chunks within the card table. 612 class G1CardTableChunkClaimer { 613 G1RemSetScanState* _scan_state; 614 uint _region_idx; 615 uint _cur_claim; 616 617 public: 618 G1CardTableChunkClaimer(G1RemSetScanState* scan_state, uint region_idx) : 619 _scan_state(scan_state), 620 _region_idx(region_idx), 621 _cur_claim(0) { 622 guarantee(size() <= HeapRegion::CardsPerRegion, "Should not claim more space than possible."); 623 } 624 625 bool has_next() { 626 while (true) { 627 _cur_claim = _scan_state->claim_cards_to_scan(_region_idx, size()); 628 if (_cur_claim >= HeapRegion::CardsPerRegion) { 629 return false; 630 } 631 if (_scan_state->chunk_needs_scan(_region_idx, _cur_claim)) { 632 return true; 633 } 634 } 635 } 636 637 uint value() const { return _cur_claim; } 638 uint size() const { return _scan_state->scan_chunk_size(); } 639 }; 640 641 // Scans a heap region for dirty cards. 642 class G1ScanHRForRegionClosure : public HeapRegionClosure { 643 G1CollectedHeap* _g1h; 644 G1CardTable* _ct; 645 G1BlockOffsetTable* _bot; 646 647 G1ParScanThreadState* _pss; 648 649 G1RemSetScanState* _scan_state; 650 651 G1GCPhaseTimes::GCParPhases _phase; 652 653 uint _worker_id; 654 655 size_t _cards_scanned; 656 size_t _blocks_scanned; 657 size_t _chunks_claimed; 658 659 Tickspan _rem_set_root_scan_time; 660 Tickspan _rem_set_trim_partially_time; 661 662 // The address to which this thread already scanned (walked the heap) up to during 663 // card scanning (exclusive). 664 HeapWord* _scanned_to; 665 666 HeapWord* scan_memregion(uint region_idx_for_card, MemRegion mr) { 667 HeapRegion* const card_region = _g1h->region_at(region_idx_for_card); 668 G1ScanCardClosure card_cl(_g1h, _pss); 669 670 HeapWord* const scanned_to = card_region->oops_on_memregion_seq_iterate_careful<true>(mr, &card_cl); 671 assert(scanned_to != NULL, "Should be able to scan range"); 672 assert(scanned_to >= mr.end(), "Scanned to " PTR_FORMAT " less than range " PTR_FORMAT, p2i(scanned_to), p2i(mr.end())); 673 674 _pss->trim_queue_partially(); 675 return scanned_to; 676 } 677 678 void do_claimed_block(uint const region_idx_for_card, size_t const first_card, size_t const num_cards) { 679 HeapWord* const card_start = _bot->address_for_index_raw(first_card); 680 #ifdef ASSERT 681 HeapRegion* hr = _g1h->region_at_or_null(region_idx_for_card); 682 assert(hr == NULL || hr->is_in_reserved(card_start), 683 "Card start " PTR_FORMAT " to scan outside of region %u", p2i(card_start), _g1h->region_at(region_idx_for_card)->hrm_index()); 684 #endif 685 HeapWord* const top = _scan_state->scan_top(region_idx_for_card); 686 if (card_start >= top) { 687 return; 688 } 689 690 HeapWord* scan_end = MIN2(card_start + (num_cards << BOTConstants::LogN_words), top); 691 if (_scanned_to >= scan_end) { 692 return; 693 } 694 MemRegion mr(MAX2(card_start, _scanned_to), scan_end); 695 _scanned_to = scan_memregion(region_idx_for_card, mr); 696 697 _cards_scanned += num_cards; 698 } 699 700 ALWAYSINLINE void do_card_block(uint const region_idx, size_t const first_card, size_t const num_cards) { 701 _ct->mark_as_scanned(first_card, num_cards); 702 do_claimed_block(region_idx, first_card, num_cards); 703 _blocks_scanned++; 704 } 705 706 void scan_heap_roots(HeapRegion* r) { 707 EventGCPhaseParallel event; 708 uint const region_idx = r->hrm_index(); 709 710 ResourceMark rm; 711 712 G1CardTableChunkClaimer claim(_scan_state, region_idx); 713 714 // Set the current scan "finger" to NULL for every heap region to scan. Since 715 // the claim value is monotonically increasing, the check to not scan below this 716 // will filter out objects spanning chunks within the region too then, as opposed 717 // to resetting this value for every claim. 718 _scanned_to = NULL; 719 720 while (claim.has_next()) { 721 size_t const region_card_base_idx = ((size_t)region_idx << HeapRegion::LogCardsPerRegion) + claim.value(); 722 CardTable::CardValue* const base_addr = _ct->byte_for_index(region_card_base_idx); 723 724 G1CardTableScanner scan(base_addr, claim.size()); 725 726 size_t first_scan_idx = scan.find_next_dirty(); 727 while (first_scan_idx != claim.size()) { 728 assert(*_ct->byte_for_index(region_card_base_idx + first_scan_idx) <= 0x1, "is %d at region %u idx " SIZE_FORMAT, *_ct->byte_for_index(region_card_base_idx + first_scan_idx), region_idx, first_scan_idx); 729 730 size_t const last_scan_idx = scan.find_next_non_dirty(); 731 size_t const len = last_scan_idx - first_scan_idx; 732 733 do_card_block(region_idx, region_card_base_idx + first_scan_idx, len); 734 735 if (last_scan_idx == claim.size()) { 736 break; 737 } 738 739 first_scan_idx = scan.find_next_dirty(); 740 } 741 _chunks_claimed++; 742 } 743 744 event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(G1GCPhaseTimes::ScanHR)); 745 } 746 747 public: 748 G1ScanHRForRegionClosure(G1RemSetScanState* scan_state, 749 G1ParScanThreadState* pss, 750 uint worker_id, 751 G1GCPhaseTimes::GCParPhases phase) : 752 _g1h(G1CollectedHeap::heap()), 753 _ct(_g1h->card_table()), 754 _bot(_g1h->bot()), 755 _pss(pss), 756 _scan_state(scan_state), 757 _phase(phase), 758 _worker_id(worker_id), 759 _cards_scanned(0), 760 _blocks_scanned(0), 761 _chunks_claimed(0), 762 _rem_set_root_scan_time(), 763 _rem_set_trim_partially_time(), 764 _scanned_to(NULL) { 765 } 766 767 bool do_heap_region(HeapRegion* r) { 768 assert(!r->in_collection_set() && r->is_old_or_humongous_or_archive(), 769 "Should only be called on old gen non-collection set regions but region %u is not.", 770 r->hrm_index()); 771 uint const region_idx = r->hrm_index(); 772 773 if (_scan_state->has_cards_to_scan(region_idx)) { 774 G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_root_scan_time, _rem_set_trim_partially_time); 775 scan_heap_roots(r); 776 } 777 return false; 778 } 779 780 Tickspan rem_set_root_scan_time() const { return _rem_set_root_scan_time; } 781 Tickspan rem_set_trim_partially_time() const { return _rem_set_trim_partially_time; } 782 783 size_t cards_scanned() const { return _cards_scanned; } 784 size_t blocks_scanned() const { return _blocks_scanned; } 785 size_t chunks_claimed() const { return _chunks_claimed; } 786 }; 787 788 void G1RemSet::scan_heap_roots(G1ParScanThreadState* pss, 789 uint worker_id, 790 G1GCPhaseTimes::GCParPhases scan_phase, 791 G1GCPhaseTimes::GCParPhases objcopy_phase) { 792 G1ScanHRForRegionClosure cl(_scan_state, pss, worker_id, scan_phase); 793 _scan_state->iterate_dirty_regions_from(&cl, worker_id); 794 795 G1GCPhaseTimes* p = _g1p->phase_times(); 796 797 p->record_or_add_time_secs(objcopy_phase, worker_id, cl.rem_set_trim_partially_time().seconds()); 798 799 p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_root_scan_time().seconds()); 800 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.cards_scanned(), G1GCPhaseTimes::ScanHRScannedCards); 801 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.blocks_scanned(), G1GCPhaseTimes::ScanHRScannedBlocks); 802 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.chunks_claimed(), G1GCPhaseTimes::ScanHRClaimedChunks); 803 } 804 805 // Heap region closure to be applied to all regions in the current collection set 806 // increment to fix up non-card related roots. 807 class G1ScanCollectionSetRegionClosure : public HeapRegionClosure { 808 G1ParScanThreadState* _pss; 809 G1RemSetScanState* _scan_state; 810 811 G1GCPhaseTimes::GCParPhases _scan_phase; 812 G1GCPhaseTimes::GCParPhases _code_roots_phase; 813 814 uint _worker_id; 815 816 size_t _opt_refs_scanned; 817 size_t _opt_refs_memory_used; 818 819 Tickspan _strong_code_root_scan_time; 820 Tickspan _strong_code_trim_partially_time; 821 822 Tickspan _rem_set_opt_root_scan_time; 823 Tickspan _rem_set_opt_trim_partially_time; 824 825 void scan_opt_rem_set_roots(HeapRegion* r) { 826 EventGCPhaseParallel event; 827 828 G1OopStarChunkedList* opt_rem_set_list = _pss->oops_into_optional_region(r); 829 830 G1ScanCardClosure scan_cl(G1CollectedHeap::heap(), _pss); 831 G1ScanRSForOptionalClosure cl(G1CollectedHeap::heap(), &scan_cl); 832 _opt_refs_scanned += opt_rem_set_list->oops_do(&cl, _pss->closures()->strong_oops()); 833 _opt_refs_memory_used += opt_rem_set_list->used_memory(); 834 835 event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_scan_phase)); 836 } 837 838 public: 839 G1ScanCollectionSetRegionClosure(G1RemSetScanState* scan_state, 840 G1ParScanThreadState* pss, 841 uint worker_id, 842 G1GCPhaseTimes::GCParPhases scan_phase, 843 G1GCPhaseTimes::GCParPhases code_roots_phase) : 844 _pss(pss), 845 _scan_state(scan_state), 846 _scan_phase(scan_phase), 847 _code_roots_phase(code_roots_phase), 848 _worker_id(worker_id), 849 _opt_refs_scanned(0), 850 _opt_refs_memory_used(0), 851 _strong_code_root_scan_time(), 852 _strong_code_trim_partially_time(), 853 _rem_set_opt_root_scan_time(), 854 _rem_set_opt_trim_partially_time() { } 855 856 bool do_heap_region(HeapRegion* r) { 857 uint const region_idx = r->hrm_index(); 858 859 // The individual references for the optional remembered set are per-worker, so we 860 // always need to scan them. 861 if (r->has_index_in_opt_cset()) { 862 G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_opt_root_scan_time, _rem_set_opt_trim_partially_time); 863 scan_opt_rem_set_roots(r); 864 } 865 866 if (_scan_state->claim_collection_set_region(region_idx)) { 867 EventGCPhaseParallel event; 868 869 G1EvacPhaseWithTrimTimeTracker timer(_pss, _strong_code_root_scan_time, _strong_code_trim_partially_time); 870 // Scan the strong code root list attached to the current region 871 r->strong_code_roots_do(_pss->closures()->weak_codeblobs()); 872 873 event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_code_roots_phase)); 874 } 875 876 return false; 877 } 878 879 Tickspan strong_code_root_scan_time() const { return _strong_code_root_scan_time; } 880 Tickspan strong_code_root_trim_partially_time() const { return _strong_code_trim_partially_time; } 881 882 Tickspan rem_set_opt_root_scan_time() const { return _rem_set_opt_root_scan_time; } 883 Tickspan rem_set_opt_trim_partially_time() const { return _rem_set_opt_trim_partially_time; } 884 885 size_t opt_refs_scanned() const { return _opt_refs_scanned; } 886 size_t opt_refs_memory_used() const { return _opt_refs_memory_used; } 887 }; 888 889 void G1RemSet::scan_collection_set_regions(G1ParScanThreadState* pss, 890 uint worker_id, 891 G1GCPhaseTimes::GCParPhases scan_phase, 892 G1GCPhaseTimes::GCParPhases coderoots_phase, 893 G1GCPhaseTimes::GCParPhases objcopy_phase) { 894 G1ScanCollectionSetRegionClosure cl(_scan_state, pss, worker_id, scan_phase, coderoots_phase); 895 _g1h->collection_set_iterate_increment_from(&cl, worker_id); 896 897 G1GCPhaseTimes* p = _g1h->phase_times(); 898 899 p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_root_scan_time().seconds()); 900 p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_trim_partially_time().seconds()); 901 902 p->record_or_add_time_secs(coderoots_phase, worker_id, cl.strong_code_root_scan_time().seconds()); 903 p->add_time_secs(objcopy_phase, worker_id, cl.strong_code_root_trim_partially_time().seconds()); 904 905 // At this time we record some metrics only for the evacuations after the initial one. 906 if (scan_phase == G1GCPhaseTimes::OptScanHR) { 907 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs); 908 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory); 909 } 910 } 911 912 void G1RemSet::prepare_for_scan_heap_roots() { 913 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set(); 914 dcqs.concatenate_logs(); 915 916 _scan_state->prepare(); 917 } 918 919 class G1MergeHeapRootsTask : public AbstractGangTask { 920 921 // Visitor for remembered sets, dropping entries onto the card table. 922 class G1MergeCardSetClosure : public HeapRegionClosure { 923 G1RemSetScanState* _scan_state; 924 G1CardTable* _ct; 925 926 uint _merged_sparse; 927 uint _merged_fine; 928 uint _merged_coarse; 929 930 size_t _cards_dirty; 931 932 // Returns if the region contains cards we need to scan. If so, remember that 933 // region in the current set of dirty regions. 934 bool remember_if_interesting(uint const region_idx) { 935 if (!_scan_state->contains_cards_to_process(region_idx)) { 936 return false; 937 } 938 _scan_state->add_dirty_region(region_idx); 939 return true; 940 } 941 public: 942 G1MergeCardSetClosure(G1RemSetScanState* scan_state) : 943 _scan_state(scan_state), 944 _ct(G1CollectedHeap::heap()->card_table()), 945 _merged_sparse(0), 946 _merged_fine(0), 947 _merged_coarse(0), 948 _cards_dirty(0) { } 949 950 void next_coarse_prt(uint const region_idx) { 951 if (!remember_if_interesting(region_idx)) { 952 return; 953 } 954 955 _merged_coarse++; 956 957 size_t region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion; 958 _cards_dirty += _ct->mark_region_dirty(region_base_idx, HeapRegion::CardsPerRegion); 959 _scan_state->set_chunk_region_dirty(region_base_idx); 960 } 961 962 void next_fine_prt(uint const region_idx, BitMap* bm) { 963 if (!remember_if_interesting(region_idx)) { 964 return; 965 } 966 967 _merged_fine++; 968 969 size_t const region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion; 970 BitMap::idx_t cur = bm->get_next_one_offset(0); 971 while (cur != bm->size()) { 972 _cards_dirty += _ct->mark_clean_as_dirty(region_base_idx + cur); 973 _scan_state->set_chunk_dirty(region_base_idx + cur); 974 cur = bm->get_next_one_offset(cur + 1); 975 } 976 } 977 978 void next_sparse_prt(uint const region_idx, SparsePRTEntry::card_elem_t* cards, uint const num_cards) { 979 if (!remember_if_interesting(region_idx)) { 980 return; 981 } 982 983 _merged_sparse++; 984 985 size_t const region_base_idx = (size_t)region_idx << HeapRegion::LogCardsPerRegion; 986 for (uint i = 0; i < num_cards; i++) { 987 size_t card_idx = region_base_idx + cards[i]; 988 _cards_dirty += _ct->mark_clean_as_dirty(card_idx); 989 _scan_state->set_chunk_dirty(card_idx); 990 } 991 } 992 993 virtual bool do_heap_region(HeapRegion* r) { 994 assert(r->in_collection_set() || r->is_starts_humongous(), "must be"); 995 996 HeapRegionRemSet* rem_set = r->rem_set(); 997 if (!rem_set->is_empty()) { 998 rem_set->iterate_prts(*this); 999 } 1000 1001 return false; 1002 } 1003 1004 size_t merged_sparse() const { return _merged_sparse; } 1005 size_t merged_fine() const { return _merged_fine; } 1006 size_t merged_coarse() const { return _merged_coarse; } 1007 1008 size_t cards_dirty() const { return _cards_dirty; } 1009 }; 1010 1011 // Visitor for the remembered sets of humongous candidate regions to merge their 1012 // remembered set into the card table. 1013 class G1FlushHumongousCandidateRemSets : public HeapRegionClosure { 1014 G1MergeCardSetClosure _cl; 1015 1016 public: 1017 G1FlushHumongousCandidateRemSets(G1RemSetScanState* scan_state) : _cl(scan_state) { } 1018 1019 virtual bool do_heap_region(HeapRegion* r) { 1020 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1021 1022 if (!r->is_starts_humongous() || 1023 !g1h->region_attr(r->hrm_index()).is_humongous() || 1024 r->rem_set()->is_empty()) { 1025 return false; 1026 } 1027 1028 guarantee(r->rem_set()->occupancy_less_or_equal_than(G1RSetSparseRegionEntries), 1029 "Found a not-small remembered set here. This is inconsistent with previous assumptions."); 1030 1031 _cl.do_heap_region(r); 1032 1033 // We should only clear the card based remembered set here as we will not 1034 // implicitly rebuild anything else during eager reclaim. Note that at the moment 1035 // (and probably never) we do not enter this path if there are other kind of 1036 // remembered sets for this region. 1037 r->rem_set()->clear_locked(true /* only_cardset */); 1038 // Clear_locked() above sets the state to Empty. However we want to continue 1039 // collecting remembered set entries for humongous regions that were not 1040 // reclaimed. 1041 r->rem_set()->set_state_complete(); 1042 #ifdef ASSERT 1043 G1HeapRegionAttr region_attr = g1h->region_attr(r->hrm_index()); 1044 assert(region_attr.needs_remset_update(), "must be"); 1045 #endif 1046 assert(r->rem_set()->is_empty(), "At this point any humongous candidate remembered set must be empty."); 1047 1048 return false; 1049 } 1050 1051 size_t merged_sparse() const { return _cl.merged_sparse(); } 1052 size_t merged_fine() const { return _cl.merged_fine(); } 1053 size_t merged_coarse() const { return _cl.merged_coarse(); } 1054 1055 size_t cards_dirty() const { return _cl.cards_dirty(); } 1056 }; 1057 1058 // Visitor for the log buffer entries to merge them into the card table. 1059 class G1MergeLogBufferCardsClosure : public G1CardTableEntryClosure { 1060 G1RemSetScanState* _scan_state; 1061 G1CardTable* _ct; 1062 1063 size_t _cards_dirty; 1064 size_t _cards_skipped; 1065 public: 1066 G1MergeLogBufferCardsClosure(G1CollectedHeap* g1h, G1RemSetScanState* scan_state) : 1067 _scan_state(scan_state), _ct(g1h->card_table()), _cards_dirty(0), _cards_skipped(0) 1068 {} 1069 1070 void do_card_ptr(CardValue* card_ptr, uint worker_id) { 1071 // The only time we care about recording cards that 1072 // contain references that point into the collection set 1073 // is during RSet updating within an evacuation pause. 1074 // In this case worker_id should be the id of a GC worker thread. 1075 assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause"); 1076 1077 uint const region_idx = _ct->region_idx_for(card_ptr); 1078 1079 // The second clause must come after - the log buffers might contain cards to uncommited 1080 // regions. 1081 // This code may count duplicate entries in the log buffers (even if rare) multiple 1082 // times. 1083 if (_scan_state->contains_cards_to_process(region_idx) && (*card_ptr == G1CardTable::dirty_card_val())) { 1084 _scan_state->add_dirty_region(region_idx); 1085 _scan_state->set_chunk_dirty(_ct->index_for_cardvalue(card_ptr)); 1086 _cards_dirty++; 1087 } else { 1088 // We may have had dirty cards in the (initial) collection set (or the 1089 // young regions which are always in the initial collection set). We do 1090 // not fix their cards here: we already added these regions to the set of 1091 // regions to clear the card table at the end during the prepare() phase. 1092 _cards_skipped++; 1093 } 1094 } 1095 1096 size_t cards_dirty() const { return _cards_dirty; } 1097 size_t cards_skipped() const { return _cards_skipped; } 1098 }; 1099 1100 HeapRegionClaimer _hr_claimer; 1101 G1RemSetScanState* _scan_state; 1102 BufferNode::Stack _dirty_card_buffers; 1103 bool _initial_evacuation; 1104 1105 volatile bool _fast_reclaim_handled; 1106 1107 void apply_closure_to_dirty_card_buffers(G1MergeLogBufferCardsClosure* cl, uint worker_id) { 1108 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set(); 1109 size_t buffer_size = dcqs.buffer_size(); 1110 while (BufferNode* node = _dirty_card_buffers.pop()) { 1111 cl->apply_to_buffer(node, buffer_size, worker_id); 1112 dcqs.deallocate_buffer(node); 1113 } 1114 } 1115 1116 public: 1117 G1MergeHeapRootsTask(G1RemSetScanState* scan_state, uint num_workers, bool initial_evacuation) : 1118 AbstractGangTask("G1 Merge Heap Roots"), 1119 _hr_claimer(num_workers), 1120 _scan_state(scan_state), 1121 _dirty_card_buffers(), 1122 _initial_evacuation(initial_evacuation), 1123 _fast_reclaim_handled(false) 1124 { 1125 if (initial_evacuation) { 1126 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set(); 1127 G1BufferNodeList buffers = dcqs.take_all_completed_buffers(); 1128 if (buffers._entry_count != 0) { 1129 _dirty_card_buffers.prepend(*buffers._head, *buffers._tail); 1130 } 1131 } 1132 } 1133 1134 virtual void work(uint worker_id) { 1135 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1136 G1GCPhaseTimes* p = g1h->phase_times(); 1137 1138 G1GCPhaseTimes::GCParPhases merge_remset_phase = _initial_evacuation ? 1139 G1GCPhaseTimes::MergeRS : 1140 G1GCPhaseTimes::OptMergeRS; 1141 1142 // We schedule flushing the remembered sets of humongous fast reclaim candidates 1143 // onto the card table first to allow the remaining parallelized tasks hide it. 1144 if (_initial_evacuation && 1145 p->fast_reclaim_humongous_candidates() > 0 && 1146 !_fast_reclaim_handled && 1147 !Atomic::cmpxchg(true, &_fast_reclaim_handled, false)) { 1148 1149 G1GCParPhaseTimesTracker x(p, G1GCPhaseTimes::MergeER, worker_id); 1150 1151 G1FlushHumongousCandidateRemSets cl(_scan_state); 1152 g1h->heap_region_iterate(&cl); 1153 1154 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_sparse(), G1GCPhaseTimes::MergeRSMergedSparse); 1155 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_fine(), G1GCPhaseTimes::MergeRSMergedFine); 1156 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_coarse(), G1GCPhaseTimes::MergeRSMergedCoarse); 1157 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.cards_dirty(), G1GCPhaseTimes::MergeRSDirtyCards); 1158 } 1159 1160 // Merge remembered sets of current candidates. 1161 { 1162 G1GCParPhaseTimesTracker x(p, merge_remset_phase, worker_id, _initial_evacuation /* must_record */); 1163 G1MergeCardSetClosure cl(_scan_state); 1164 g1h->collection_set_iterate_increment_from(&cl, &_hr_claimer, worker_id); 1165 1166 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_sparse(), G1GCPhaseTimes::MergeRSMergedSparse); 1167 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_fine(), G1GCPhaseTimes::MergeRSMergedFine); 1168 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.merged_coarse(), G1GCPhaseTimes::MergeRSMergedCoarse); 1169 p->record_or_add_thread_work_item(merge_remset_phase, worker_id, cl.cards_dirty(), G1GCPhaseTimes::MergeRSDirtyCards); 1170 } 1171 1172 // Apply closure to log entries in the HCC. 1173 if (_initial_evacuation && G1HotCardCache::default_use_cache()) { 1174 assert(merge_remset_phase == G1GCPhaseTimes::MergeRS, "Wrong merge phase"); 1175 G1GCParPhaseTimesTracker x(p, G1GCPhaseTimes::MergeHCC, worker_id); 1176 G1MergeLogBufferCardsClosure cl(g1h, _scan_state); 1177 g1h->iterate_hcc_closure(&cl, worker_id); 1178 1179 p->record_thread_work_item(G1GCPhaseTimes::MergeHCC, worker_id, cl.cards_dirty(), G1GCPhaseTimes::MergeHCCDirtyCards); 1180 p->record_thread_work_item(G1GCPhaseTimes::MergeHCC, worker_id, cl.cards_skipped(), G1GCPhaseTimes::MergeHCCSkippedCards); 1181 } 1182 1183 // Now apply the closure to all remaining log entries. 1184 if (_initial_evacuation) { 1185 assert(merge_remset_phase == G1GCPhaseTimes::MergeRS, "Wrong merge phase"); 1186 G1GCParPhaseTimesTracker x(p, G1GCPhaseTimes::MergeLB, worker_id); 1187 1188 G1MergeLogBufferCardsClosure cl(g1h, _scan_state); 1189 apply_closure_to_dirty_card_buffers(&cl, worker_id); 1190 1191 p->record_thread_work_item(G1GCPhaseTimes::MergeLB, worker_id, cl.cards_dirty(), G1GCPhaseTimes::MergeLBDirtyCards); 1192 p->record_thread_work_item(G1GCPhaseTimes::MergeLB, worker_id, cl.cards_skipped(), G1GCPhaseTimes::MergeLBSkippedCards); 1193 } 1194 } 1195 }; 1196 1197 void G1RemSet::print_merge_heap_roots_stats() { 1198 size_t num_visited_cards = _scan_state->num_visited_cards(); 1199 1200 size_t total_dirty_region_cards = _scan_state->num_cards_in_dirty_regions(); 1201 1202 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1203 size_t total_old_region_cards = 1204 (g1h->num_regions() - (g1h->num_free_regions() - g1h->collection_set()->cur_length())) * HeapRegion::CardsPerRegion; 1205 1206 log_debug(gc,remset)("Visited cards " SIZE_FORMAT " Total dirty " SIZE_FORMAT " (%.2lf%%) Total old " SIZE_FORMAT " (%.2lf%%)", 1207 num_visited_cards, 1208 total_dirty_region_cards, 1209 percent_of(num_visited_cards, total_dirty_region_cards), 1210 total_old_region_cards, 1211 percent_of(num_visited_cards, total_old_region_cards)); 1212 } 1213 1214 void G1RemSet::merge_heap_roots(bool initial_evacuation) { 1215 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1216 1217 { 1218 Ticks start = Ticks::now(); 1219 1220 _scan_state->prepare_for_merge_heap_roots(); 1221 1222 Tickspan total = Ticks::now() - start; 1223 if (initial_evacuation) { 1224 g1h->phase_times()->record_prepare_merge_heap_roots_time(total.seconds() * 1000.0); 1225 } else { 1226 g1h->phase_times()->record_or_add_optional_prepare_merge_heap_roots_time(total.seconds() * 1000.0); 1227 } 1228 } 1229 1230 WorkGang* workers = g1h->workers(); 1231 size_t const increment_length = g1h->collection_set()->increment_length(); 1232 1233 uint const num_workers = initial_evacuation ? workers->active_workers() : 1234 MIN2(workers->active_workers(), (uint)increment_length); 1235 1236 { 1237 G1MergeHeapRootsTask cl(_scan_state, num_workers, initial_evacuation); 1238 log_debug(gc, ergo)("Running %s using %u workers for " SIZE_FORMAT " regions", 1239 cl.name(), num_workers, increment_length); 1240 workers->run_task(&cl, num_workers); 1241 } 1242 1243 if (log_is_enabled(Debug, gc, remset)) { 1244 print_merge_heap_roots_stats(); 1245 } 1246 } 1247 1248 void G1RemSet::prepare_for_scan_heap_roots(uint region_idx) { 1249 _scan_state->clear_scan_top(region_idx); 1250 } 1251 1252 void G1RemSet::cleanup_after_scan_heap_roots() { 1253 G1GCPhaseTimes* phase_times = _g1h->phase_times(); 1254 1255 // Set all cards back to clean. 1256 double start = os::elapsedTime(); 1257 _scan_state->cleanup(_g1h->workers()); 1258 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0); 1259 } 1260 1261 inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) { 1262 #ifdef ASSERT 1263 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1264 assert(g1h->is_in_exact(ct->addr_for(card_ptr)), 1265 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap", 1266 p2i(card_ptr), 1267 ct->index_for(ct->addr_for(card_ptr)), 1268 p2i(ct->addr_for(card_ptr)), 1269 g1h->addr_to_region(ct->addr_for(card_ptr))); 1270 #endif 1271 } 1272 1273 void G1RemSet::refine_card_concurrently(CardValue* card_ptr, 1274 uint worker_id) { 1275 assert(!_g1h->is_gc_active(), "Only call concurrently"); 1276 1277 // Construct the region representing the card. 1278 HeapWord* start = _ct->addr_for(card_ptr); 1279 // And find the region containing it. 1280 HeapRegion* r = _g1h->heap_region_containing_or_null(start); 1281 1282 // If this is a (stale) card into an uncommitted region, exit. 1283 if (r == NULL) { 1284 return; 1285 } 1286 1287 check_card_ptr(card_ptr, _ct); 1288 1289 // If the card is no longer dirty, nothing to do. 1290 if (*card_ptr != G1CardTable::dirty_card_val()) { 1291 return; 1292 } 1293 1294 // This check is needed for some uncommon cases where we should 1295 // ignore the card. 1296 // 1297 // The region could be young. Cards for young regions are 1298 // distinctly marked (set to g1_young_gen), so the post-barrier will 1299 // filter them out. However, that marking is performed 1300 // concurrently. A write to a young object could occur before the 1301 // card has been marked young, slipping past the filter. 1302 // 1303 // The card could be stale, because the region has been freed since 1304 // the card was recorded. In this case the region type could be 1305 // anything. If (still) free or (reallocated) young, just ignore 1306 // it. If (reallocated) old or humongous, the later card trimming 1307 // and additional checks in iteration may detect staleness. At 1308 // worst, we end up processing a stale card unnecessarily. 1309 // 1310 // In the normal (non-stale) case, the synchronization between the 1311 // enqueueing of the card and processing it here will have ensured 1312 // we see the up-to-date region type here. 1313 if (!r->is_old_or_humongous_or_archive()) { 1314 return; 1315 } 1316 1317 // The result from the hot card cache insert call is either: 1318 // * pointer to the current card 1319 // (implying that the current card is not 'hot'), 1320 // * null 1321 // (meaning we had inserted the card ptr into the "hot" card cache, 1322 // which had some headroom), 1323 // * a pointer to a "hot" card that was evicted from the "hot" cache. 1324 // 1325 1326 if (_hot_card_cache->use_cache()) { 1327 assert(!SafepointSynchronize::is_at_safepoint(), "sanity"); 1328 1329 const CardValue* orig_card_ptr = card_ptr; 1330 card_ptr = _hot_card_cache->insert(card_ptr); 1331 if (card_ptr == NULL) { 1332 // There was no eviction. Nothing to do. 1333 return; 1334 } else if (card_ptr != orig_card_ptr) { 1335 // Original card was inserted and an old card was evicted. 1336 start = _ct->addr_for(card_ptr); 1337 r = _g1h->heap_region_containing(start); 1338 1339 // Check whether the region formerly in the cache should be 1340 // ignored, as discussed earlier for the original card. The 1341 // region could have been freed while in the cache. 1342 if (!r->is_old_or_humongous_or_archive()) { 1343 return; 1344 } 1345 } // Else we still have the original card. 1346 } 1347 1348 // Trim the region designated by the card to what's been allocated 1349 // in the region. The card could be stale, or the card could cover 1350 // (part of) an object at the end of the allocated space and extend 1351 // beyond the end of allocation. 1352 1353 // Non-humongous objects are only allocated in the old-gen during 1354 // GC, so if region is old then top is stable. Humongous object 1355 // allocation sets top last; if top has not yet been set, this is 1356 // a stale card and we'll end up with an empty intersection. If 1357 // this is not a stale card, the synchronization between the 1358 // enqueuing of the card and processing it here will have ensured 1359 // we see the up-to-date top here. 1360 HeapWord* scan_limit = r->top(); 1361 1362 if (scan_limit <= start) { 1363 // If the trimmed region is empty, the card must be stale. 1364 return; 1365 } 1366 1367 // Okay to clean and process the card now. There are still some 1368 // stale card cases that may be detected by iteration and dealt with 1369 // as iteration failure. 1370 *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val(); 1371 1372 // This fence serves two purposes. First, the card must be cleaned 1373 // before processing the contents. Second, we can't proceed with 1374 // processing until after the read of top, for synchronization with 1375 // possibly concurrent humongous object allocation. It's okay that 1376 // reading top and reading type were racy wrto each other. We need 1377 // both set, in any order, to proceed. 1378 OrderAccess::fence(); 1379 1380 // Don't use addr_for(card_ptr + 1) which can ask for 1381 // a card beyond the heap. 1382 HeapWord* end = start + G1CardTable::card_size_in_words; 1383 MemRegion dirty_region(start, MIN2(scan_limit, end)); 1384 assert(!dirty_region.is_empty(), "sanity"); 1385 1386 G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_id); 1387 if (r->oops_on_memregion_seq_iterate_careful<false>(dirty_region, &conc_refine_cl) != NULL) { 1388 return; 1389 } 1390 1391 // If unable to process the card then we encountered an unparsable 1392 // part of the heap (e.g. a partially allocated object, so only 1393 // temporarily a problem) while processing a stale card. Despite 1394 // the card being stale, we can't simply ignore it, because we've 1395 // already marked the card cleaned, so taken responsibility for 1396 // ensuring the card gets scanned. 1397 // 1398 // However, the card might have gotten re-dirtied and re-enqueued 1399 // while we worked. (In fact, it's pretty likely.) 1400 if (*card_ptr == G1CardTable::dirty_card_val()) { 1401 return; 1402 } 1403 1404 // Re-dirty the card and enqueue in the *shared* queue. Can't use 1405 // the thread-local queue, because that might be the queue that is 1406 // being processed by us; we could be a Java thread conscripted to 1407 // perform refinement on our queue's current buffer. 1408 *card_ptr = G1CardTable::dirty_card_val(); 1409 G1BarrierSet::shared_dirty_card_queue().enqueue(card_ptr); 1410 } 1411 1412 void G1RemSet::print_periodic_summary_info(const char* header, uint period_count) { 1413 if ((G1SummarizeRSetStatsPeriod > 0) && log_is_enabled(Trace, gc, remset) && 1414 (period_count % G1SummarizeRSetStatsPeriod == 0)) { 1415 1416 G1RemSetSummary current; 1417 _prev_period_summary.subtract_from(¤t); 1418 1419 Log(gc, remset) log; 1420 log.trace("%s", header); 1421 ResourceMark rm; 1422 LogStream ls(log.trace()); 1423 _prev_period_summary.print_on(&ls); 1424 1425 _prev_period_summary.set(¤t); 1426 } 1427 } 1428 1429 void G1RemSet::print_summary_info() { 1430 Log(gc, remset, exit) log; 1431 if (log.is_trace()) { 1432 log.trace(" Cumulative RS summary"); 1433 G1RemSetSummary current; 1434 ResourceMark rm; 1435 LogStream ls(log.trace()); 1436 current.print_on(&ls); 1437 } 1438 } 1439 1440 class G1RebuildRemSetTask: public AbstractGangTask { 1441 // Aggregate the counting data that was constructed concurrently 1442 // with marking. 1443 class G1RebuildRemSetHeapRegionClosure : public HeapRegionClosure { 1444 G1ConcurrentMark* _cm; 1445 G1RebuildRemSetClosure _update_cl; 1446 1447 // Applies _update_cl to the references of the given object, limiting objArrays 1448 // to the given MemRegion. Returns the amount of words actually scanned. 1449 size_t scan_for_references(oop const obj, MemRegion mr) { 1450 size_t const obj_size = obj->size(); 1451 // All non-objArrays and objArrays completely within the mr 1452 // can be scanned without passing the mr. 1453 if (!obj->is_objArray() || mr.contains(MemRegion((HeapWord*)obj, obj_size))) { 1454 obj->oop_iterate(&_update_cl); 1455 return obj_size; 1456 } 1457 // This path is for objArrays crossing the given MemRegion. Only scan the 1458 // area within the MemRegion. 1459 obj->oop_iterate(&_update_cl, mr); 1460 return mr.intersection(MemRegion((HeapWord*)obj, obj_size)).word_size(); 1461 } 1462 1463 // A humongous object is live (with respect to the scanning) either 1464 // a) it is marked on the bitmap as such 1465 // b) its TARS is larger than TAMS, i.e. has been allocated during marking. 1466 bool is_humongous_live(oop const humongous_obj, const G1CMBitMap* const bitmap, HeapWord* tams, HeapWord* tars) const { 1467 return bitmap->is_marked(humongous_obj) || (tars > tams); 1468 } 1469 1470 // Iterator over the live objects within the given MemRegion. 1471 class LiveObjIterator : public StackObj { 1472 const G1CMBitMap* const _bitmap; 1473 const HeapWord* _tams; 1474 const MemRegion _mr; 1475 HeapWord* _current; 1476 1477 bool is_below_tams() const { 1478 return _current < _tams; 1479 } 1480 1481 bool is_live(HeapWord* obj) const { 1482 return !is_below_tams() || _bitmap->is_marked(obj); 1483 } 1484 1485 HeapWord* bitmap_limit() const { 1486 return MIN2(const_cast<HeapWord*>(_tams), _mr.end()); 1487 } 1488 1489 void move_if_below_tams() { 1490 if (is_below_tams() && has_next()) { 1491 _current = _bitmap->get_next_marked_addr(_current, bitmap_limit()); 1492 } 1493 } 1494 public: 1495 LiveObjIterator(const G1CMBitMap* const bitmap, const HeapWord* tams, const MemRegion mr, HeapWord* first_oop_into_mr) : 1496 _bitmap(bitmap), 1497 _tams(tams), 1498 _mr(mr), 1499 _current(first_oop_into_mr) { 1500 1501 assert(_current <= _mr.start(), 1502 "First oop " PTR_FORMAT " should extend into mr [" PTR_FORMAT ", " PTR_FORMAT ")", 1503 p2i(first_oop_into_mr), p2i(mr.start()), p2i(mr.end())); 1504 1505 // Step to the next live object within the MemRegion if needed. 1506 if (is_live(_current)) { 1507 // Non-objArrays were scanned by the previous part of that region. 1508 if (_current < mr.start() && !oop(_current)->is_objArray()) { 1509 _current += oop(_current)->size(); 1510 // We might have positioned _current on a non-live object. Reposition to the next 1511 // live one if needed. 1512 move_if_below_tams(); 1513 } 1514 } else { 1515 // The object at _current can only be dead if below TAMS, so we can use the bitmap. 1516 // immediately. 1517 _current = _bitmap->get_next_marked_addr(_current, bitmap_limit()); 1518 assert(_current == _mr.end() || is_live(_current), 1519 "Current " PTR_FORMAT " should be live (%s) or beyond the end of the MemRegion (" PTR_FORMAT ")", 1520 p2i(_current), BOOL_TO_STR(is_live(_current)), p2i(_mr.end())); 1521 } 1522 } 1523 1524 void move_to_next() { 1525 _current += next()->size(); 1526 move_if_below_tams(); 1527 } 1528 1529 oop next() const { 1530 oop result = oop(_current); 1531 assert(is_live(_current), 1532 "Object " PTR_FORMAT " must be live TAMS " PTR_FORMAT " below %d mr " PTR_FORMAT " " PTR_FORMAT " outside %d", 1533 p2i(_current), p2i(_tams), _tams > _current, p2i(_mr.start()), p2i(_mr.end()), _mr.contains(result)); 1534 return result; 1535 } 1536 1537 bool has_next() const { 1538 return _current < _mr.end(); 1539 } 1540 }; 1541 1542 // Rebuild remembered sets in the part of the region specified by mr and hr. 1543 // Objects between the bottom of the region and the TAMS are checked for liveness 1544 // using the given bitmap. Objects between TAMS and TARS are assumed to be live. 1545 // Returns the number of live words between bottom and TAMS. 1546 size_t rebuild_rem_set_in_region(const G1CMBitMap* const bitmap, 1547 HeapWord* const top_at_mark_start, 1548 HeapWord* const top_at_rebuild_start, 1549 HeapRegion* hr, 1550 MemRegion mr) { 1551 size_t marked_words = 0; 1552 1553 if (hr->is_humongous()) { 1554 oop const humongous_obj = oop(hr->humongous_start_region()->bottom()); 1555 if (is_humongous_live(humongous_obj, bitmap, top_at_mark_start, top_at_rebuild_start)) { 1556 // We need to scan both [bottom, TAMS) and [TAMS, top_at_rebuild_start); 1557 // however in case of humongous objects it is sufficient to scan the encompassing 1558 // area (top_at_rebuild_start is always larger or equal to TAMS) as one of the 1559 // two areas will be zero sized. I.e. TAMS is either 1560 // the same as bottom or top(_at_rebuild_start). There is no way TAMS has a different 1561 // value: this would mean that TAMS points somewhere into the object. 1562 assert(hr->top() == top_at_mark_start || hr->top() == top_at_rebuild_start, 1563 "More than one object in the humongous region?"); 1564 humongous_obj->oop_iterate(&_update_cl, mr); 1565 return top_at_mark_start != hr->bottom() ? mr.intersection(MemRegion((HeapWord*)humongous_obj, humongous_obj->size())).byte_size() : 0; 1566 } else { 1567 return 0; 1568 } 1569 } 1570 1571 for (LiveObjIterator it(bitmap, top_at_mark_start, mr, hr->block_start(mr.start())); it.has_next(); it.move_to_next()) { 1572 oop obj = it.next(); 1573 size_t scanned_size = scan_for_references(obj, mr); 1574 if ((HeapWord*)obj < top_at_mark_start) { 1575 marked_words += scanned_size; 1576 } 1577 } 1578 1579 return marked_words * HeapWordSize; 1580 } 1581 public: 1582 G1RebuildRemSetHeapRegionClosure(G1CollectedHeap* g1h, 1583 G1ConcurrentMark* cm, 1584 uint worker_id) : 1585 HeapRegionClosure(), 1586 _cm(cm), 1587 _update_cl(g1h, worker_id) { } 1588 1589 bool do_heap_region(HeapRegion* hr) { 1590 if (_cm->has_aborted()) { 1591 return true; 1592 } 1593 1594 uint const region_idx = hr->hrm_index(); 1595 DEBUG_ONLY(HeapWord* const top_at_rebuild_start_check = _cm->top_at_rebuild_start(region_idx);) 1596 assert(top_at_rebuild_start_check == NULL || 1597 top_at_rebuild_start_check > hr->bottom(), 1598 "A TARS (" PTR_FORMAT ") == bottom() (" PTR_FORMAT ") indicates the old region %u is empty (%s)", 1599 p2i(top_at_rebuild_start_check), p2i(hr->bottom()), region_idx, hr->get_type_str()); 1600 1601 size_t total_marked_bytes = 0; 1602 size_t const chunk_size_in_words = G1RebuildRemSetChunkSize / HeapWordSize; 1603 1604 HeapWord* const top_at_mark_start = hr->prev_top_at_mark_start(); 1605 1606 HeapWord* cur = hr->bottom(); 1607 while (cur < hr->end()) { 1608 // After every iteration (yield point) we need to check whether the region's 1609 // TARS changed due to e.g. eager reclaim. 1610 HeapWord* const top_at_rebuild_start = _cm->top_at_rebuild_start(region_idx); 1611 if (top_at_rebuild_start == NULL) { 1612 return false; 1613 } 1614 1615 MemRegion next_chunk = MemRegion(hr->bottom(), top_at_rebuild_start).intersection(MemRegion(cur, chunk_size_in_words)); 1616 if (next_chunk.is_empty()) { 1617 break; 1618 } 1619 1620 const Ticks start = Ticks::now(); 1621 size_t marked_bytes = rebuild_rem_set_in_region(_cm->prev_mark_bitmap(), 1622 top_at_mark_start, 1623 top_at_rebuild_start, 1624 hr, 1625 next_chunk); 1626 Tickspan time = Ticks::now() - start; 1627 1628 log_trace(gc, remset, tracking)("Rebuilt region %u " 1629 "live " SIZE_FORMAT " " 1630 "time %.3fms " 1631 "marked bytes " SIZE_FORMAT " " 1632 "bot " PTR_FORMAT " " 1633 "TAMS " PTR_FORMAT " " 1634 "TARS " PTR_FORMAT, 1635 region_idx, 1636 _cm->liveness(region_idx) * HeapWordSize, 1637 time.seconds() * 1000.0, 1638 marked_bytes, 1639 p2i(hr->bottom()), 1640 p2i(top_at_mark_start), 1641 p2i(top_at_rebuild_start)); 1642 1643 if (marked_bytes > 0) { 1644 total_marked_bytes += marked_bytes; 1645 } 1646 cur += chunk_size_in_words; 1647 1648 _cm->do_yield_check(); 1649 if (_cm->has_aborted()) { 1650 return true; 1651 } 1652 } 1653 // In the final iteration of the loop the region might have been eagerly reclaimed. 1654 // Simply filter out those regions. We can not just use region type because there 1655 // might have already been new allocations into these regions. 1656 DEBUG_ONLY(HeapWord* const top_at_rebuild_start = _cm->top_at_rebuild_start(region_idx);) 1657 assert(top_at_rebuild_start == NULL || 1658 total_marked_bytes == hr->marked_bytes(), 1659 "Marked bytes " SIZE_FORMAT " for region %u (%s) in [bottom, TAMS) do not match calculated marked bytes " SIZE_FORMAT " " 1660 "(" PTR_FORMAT " " PTR_FORMAT " " PTR_FORMAT ")", 1661 total_marked_bytes, hr->hrm_index(), hr->get_type_str(), hr->marked_bytes(), 1662 p2i(hr->bottom()), p2i(top_at_mark_start), p2i(top_at_rebuild_start)); 1663 // Abort state may have changed after the yield check. 1664 return _cm->has_aborted(); 1665 } 1666 }; 1667 1668 HeapRegionClaimer _hr_claimer; 1669 G1ConcurrentMark* _cm; 1670 1671 uint _worker_id_offset; 1672 public: 1673 G1RebuildRemSetTask(G1ConcurrentMark* cm, 1674 uint n_workers, 1675 uint worker_id_offset) : 1676 AbstractGangTask("G1 Rebuild Remembered Set"), 1677 _hr_claimer(n_workers), 1678 _cm(cm), 1679 _worker_id_offset(worker_id_offset) { 1680 } 1681 1682 void work(uint worker_id) { 1683 SuspendibleThreadSetJoiner sts_join; 1684 1685 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1686 1687 G1RebuildRemSetHeapRegionClosure cl(g1h, _cm, _worker_id_offset + worker_id); 1688 g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hr_claimer, worker_id); 1689 } 1690 }; 1691 1692 void G1RemSet::rebuild_rem_set(G1ConcurrentMark* cm, 1693 WorkGang* workers, 1694 uint worker_id_offset) { 1695 uint num_workers = workers->active_workers(); 1696 1697 G1RebuildRemSetTask cl(cm, 1698 num_workers, 1699 worker_id_offset); 1700 workers->run_task(&cl, num_workers); 1701 }