< prev index next >

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

Print this page
rev 13131 : imported patch 8178148-more-detailed-scan-rs-logging
rev 13135 : imported patch 8175554-improve-g1updatersorpushrefclosure
rev 13138 : [mq]: 8175554-erikd-review3


 310 }
 311 
 312 uint G1RemSet::num_par_rem_sets() {
 313   return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
 314 }
 315 
 316 void G1RemSet::initialize(size_t capacity, uint max_regions) {
 317   G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
 318   _scan_state->initialize(max_regions);
 319   {
 320     GCTraceTime(Debug, gc, marking)("Initialize Card Live Data");
 321     _card_live_data.initialize(capacity, max_regions);
 322   }
 323   if (G1PretouchAuxiliaryMemory) {
 324     GCTraceTime(Debug, gc, marking)("Pre-Touch Card Live Data");
 325     _card_live_data.pretouch();
 326   }
 327 }
 328 
 329 G1ScanRSClosure::G1ScanRSClosure(G1RemSetScanState* scan_state,
 330                                  G1ParPushHeapRSClosure* push_heap_cl,
 331                                  CodeBlobClosure* code_root_cl,
 332                                  uint worker_i) :
 333   _scan_state(scan_state),
 334   _push_heap_cl(push_heap_cl),
 335   _code_root_cl(code_root_cl),
 336   _strong_code_root_scan_time_sec(0.0),
 337   _cards_claimed(0),
 338   _cards_scanned(0),
 339   _cards_skipped(0),
 340   _worker_i(worker_i) {
 341   _g1h = G1CollectedHeap::heap();
 342   _bot = _g1h->bot();
 343   _ct_bs = _g1h->g1_barrier_set();
 344   _block_size = MAX2<size_t>(G1RSetScanBlockSize, 1);
 345 }
 346 
 347 void G1ScanRSClosure::scan_card(size_t index, HeapWord* card_start, HeapRegion *r) {
 348   MemRegion card_region(card_start, BOTConstants::N_words);
 349   MemRegion pre_gc_allocated(r->bottom(), _scan_state->scan_top(r->hrm_index()));
 350   MemRegion mr = pre_gc_allocated.intersection(card_region);
 351   if (!mr.is_empty() && !_ct_bs->is_card_claimed(index)) {
 352     // We make the card as "claimed" lazily (so races are possible
 353     // but they're benign), which reduces the number of duplicate
 354     // scans (the rsets of the regions in the cset can intersect).
 355     _ct_bs->set_card_claimed(index);
 356     _push_heap_cl->set_region(r);
 357     r->oops_on_card_seq_iterate_careful<true>(mr, _push_heap_cl);
 358     _cards_scanned++;
 359   }
 360 }
 361 
 362 void G1ScanRSClosure::scan_strong_code_roots(HeapRegion* r) {
 363   double scan_start = os::elapsedTime();
 364   r->strong_code_roots_do(_code_root_cl);
 365   _strong_code_root_scan_time_sec += (os::elapsedTime() - scan_start);
 366 }
 367 
 368 bool G1ScanRSClosure::doHeapRegion(HeapRegion* r) {
 369   assert(r->in_collection_set(), "should only be called on elements of CS.");
 370   uint region_idx = r->hrm_index();
 371 
 372   if (_scan_state->iter_is_complete(region_idx)) {
 373     return false;
 374   }
 375   if (_scan_state->claim_iter(region_idx)) {
 376     // If we ever free the collection set concurrently, we should also
 377     // clear the card table concurrently therefore we won't need to


 396     HeapWord* card_start = _g1h->bot()->address_for_index(card_index);
 397 
 398     HeapRegion* card_region = _g1h->heap_region_containing(card_start);
 399     _cards_claimed++;
 400 
 401     _scan_state->add_dirty_region(card_region->hrm_index());
 402 
 403     // If the card is dirty, then we will scan it during updateRS.
 404     if (!card_region->in_collection_set() &&
 405         !_ct_bs->is_card_dirty(card_index)) {
 406       scan_card(card_index, card_start, card_region);
 407     }
 408   }
 409   if (_scan_state->set_iter_complete(region_idx)) {
 410     // Scan the strong code root list attached to the current region
 411     scan_strong_code_roots(r);
 412   }
 413   return false;
 414 }
 415 
 416 void G1RemSet::scan_rem_set(G1ParPushHeapRSClosure* oops_in_heap_closure,
 417                             CodeBlobClosure* heap_region_codeblobs,
 418                             uint worker_i) {
 419   double rs_time_start = os::elapsedTime();
 420 
 421   G1ScanRSClosure cl(_scan_state, oops_in_heap_closure, heap_region_codeblobs, worker_i);
 422   _g1->collection_set_iterate_from(&cl, worker_i);
 423 
 424   double scan_rs_time_sec = (os::elapsedTime() - rs_time_start) -
 425                              cl.strong_code_root_scan_time_sec();
 426 
 427   G1GCPhaseTimes* p = _g1p->phase_times();
 428 
 429   p->record_time_secs(G1GCPhaseTimes::ScanRS, worker_i, scan_rs_time_sec);
 430   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_scanned(), G1GCPhaseTimes::ScannedCards);
 431   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_claimed(), G1GCPhaseTimes::ClaimedCards);
 432   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_skipped(), G1GCPhaseTimes::SkippedCards);
 433   
 434   p->record_time_secs(G1GCPhaseTimes::CodeRoots, worker_i, cl.strong_code_root_scan_time_sec());  
 435 }
 436 
 437 // Closure used for updating RSets and recording references that
 438 // point into the collection set. Only called during an
 439 // evacuation pause.
 440 
 441 class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure {
 442   G1RemSet* _g1rs;
 443   DirtyCardQueue* _into_cset_dcq;
 444   G1ParPushHeapRSClosure* _cl;
 445 public:
 446   RefineRecordRefsIntoCSCardTableEntryClosure(G1CollectedHeap* g1h,
 447                                               DirtyCardQueue* into_cset_dcq,
 448                                               G1ParPushHeapRSClosure* cl) :
 449     _g1rs(g1h->g1_rem_set()), _into_cset_dcq(into_cset_dcq), _cl(cl)
 450   {}
 451 
 452   bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
 453     // The only time we care about recording cards that
 454     // contain references that point into the collection set
 455     // is during RSet updating within an evacuation pause.
 456     // In this case worker_i should be the id of a GC worker thread.
 457     assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");
 458     assert(worker_i < ParallelGCThreads, "should be a GC worker");
 459 
 460     if (_g1rs->refine_card_during_gc(card_ptr, worker_i, _cl)) {
 461       // 'card_ptr' contains references that point into the collection
 462       // set. We need to record the card in the DCQS
 463       // (_into_cset_dirty_card_queue_set)
 464       // that's used for that purpose.
 465       //
 466       // Enqueue the card
 467       _into_cset_dcq->enqueue(card_ptr);
 468     }
 469     return true;
 470   }
 471 };
 472 
 473 void G1RemSet::update_rem_set(DirtyCardQueue* into_cset_dcq,
 474                               G1ParPushHeapRSClosure* oops_in_heap_closure,
 475                               uint worker_i) {
 476   RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq, oops_in_heap_closure);
 477 
 478   G1GCParPhaseTimesTracker x(_g1p->phase_times(), G1GCPhaseTimes::UpdateRS, worker_i);
 479   if (G1HotCardCache::default_use_cache()) {
 480     // Apply the closure to the entries of the hot card cache.
 481     G1GCParPhaseTimesTracker y(_g1p->phase_times(), G1GCPhaseTimes::ScanHCC, worker_i);
 482     _g1->iterate_hcc_closure(&into_cset_update_rs_cl, worker_i);
 483   }
 484   // Apply the closure to all remaining log entries.
 485   _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, worker_i);
 486 }
 487 
 488 void G1RemSet::cleanupHRRS() {
 489   HeapRegionRemSet::cleanup();
 490 }
 491 
 492 void G1RemSet::oops_into_collection_set_do(G1ParPushHeapRSClosure* cl,
 493                                            CodeBlobClosure* heap_region_codeblobs,
 494                                            uint worker_i) {
 495   // A DirtyCardQueue that is used to hold cards containing references
 496   // that point into the collection set. This DCQ is associated with a
 497   // special DirtyCardQueueSet (see g1CollectedHeap.hpp).  Under normal
 498   // circumstances (i.e. the pause successfully completes), these cards
 499   // are just discarded (there's no need to update the RSets of regions
 500   // that were in the collection set - after the pause these regions
 501   // are wholly 'free' of live objects. In the event of an evacuation
 502   // failure the cards/buffers in this queue set are passed to the
 503   // DirtyCardQueueSet that is used to manage RSet updates
 504   DirtyCardQueue into_cset_dcq(&_into_cset_dirty_card_queue_set);
 505 
 506   update_rem_set(&into_cset_dcq, cl, worker_i);
 507   scan_rem_set(cl, heap_region_codeblobs, worker_i);;






 508 }
 509 
 510 void G1RemSet::prepare_for_oops_into_collection_set_do() {
 511   _g1->set_refine_cte_cl_concurrency(false);
 512   DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 513   dcqs.concatenate_logs();
 514 
 515   _scan_state->reset();
 516 }
 517 
 518 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
 519   G1GCPhaseTimes* phase_times = _g1->g1_policy()->phase_times();
 520   // Cleanup after copy
 521   _g1->set_refine_cte_cl_concurrency(true);
 522 
 523   // Set all cards back to clean.
 524   double start = os::elapsedTime();
 525   _scan_state->clear_card_table(_g1->workers());
 526   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
 527 


 562   }
 563 };
 564 
 565 void G1RemSet::scrub(uint worker_num, HeapRegionClaimer *hrclaimer) {
 566   G1ScrubRSClosure scrub_cl(&_card_live_data);
 567   _g1->heap_region_par_iterate(&scrub_cl, worker_num, hrclaimer);
 568 }
 569 
 570 inline void check_card_ptr(jbyte* card_ptr, CardTableModRefBS* ct_bs) {
 571 #ifdef ASSERT
 572   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 573   assert(g1->is_in_exact(ct_bs->addr_for(card_ptr)),
 574          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
 575          p2i(card_ptr),
 576          ct_bs->index_for(ct_bs->addr_for(card_ptr)),
 577          p2i(ct_bs->addr_for(card_ptr)),
 578          g1->addr_to_region(ct_bs->addr_for(card_ptr)));
 579 #endif
 580 }
 581 
 582 G1UpdateRSOrPushRefOopClosure::G1UpdateRSOrPushRefOopClosure(G1CollectedHeap* g1h,
 583                                                              G1ParPushHeapRSClosure* push_ref_cl,
 584                                                              bool record_refs_into_cset,
 585                                                              uint worker_i) :
 586   _g1(g1h),
 587   _from(NULL),
 588   _record_refs_into_cset(record_refs_into_cset),
 589   _has_refs_into_cset(false),
 590   _push_ref_cl(push_ref_cl),
 591   _worker_i(worker_i) { }
 592 
 593 void G1RemSet::refine_card_concurrently(jbyte* card_ptr,
 594                                         uint worker_i) {
 595   assert(!_g1->is_gc_active(), "Only call concurrently");
 596 
 597   check_card_ptr(card_ptr, _ct_bs);
 598 
 599   // If the card is no longer dirty, nothing to do.
 600   if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 601     return;
 602   }
 603 
 604   // Construct the region representing the card.
 605   HeapWord* start = _ct_bs->addr_for(card_ptr);
 606   // And find the region containing it.
 607   HeapRegion* r = _g1->heap_region_containing(start);
 608 
 609   // This check is needed for some uncommon cases where we should
 610   // ignore the card.
 611   //
 612   // The region could be young.  Cards for young regions are


 723   // processing a stale card.  Despite the card being stale, redirty
 724   // and re-enqueue, because we've already cleaned the card.  Without
 725   // this we could incorrectly discard a non-stale card.
 726   if (!card_processed) {
 727     // The card might have gotten re-dirtied and re-enqueued while we
 728     // worked.  (In fact, it's pretty likely.)
 729     if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 730       *card_ptr = CardTableModRefBS::dirty_card_val();
 731       MutexLockerEx x(Shared_DirtyCardQ_lock,
 732                       Mutex::_no_safepoint_check_flag);
 733       DirtyCardQueue* sdcq =
 734         JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
 735       sdcq->enqueue(card_ptr);
 736     }
 737   } else {
 738     _conc_refine_cards++;
 739   }
 740 }
 741 
 742 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
 743                                      uint worker_i,
 744                                      G1ParPushHeapRSClosure*  oops_in_heap_closure) {
 745   assert(_g1->is_gc_active(), "Only call during GC");
 746 
 747   check_card_ptr(card_ptr, _ct_bs);
 748 
 749   // If the card is no longer dirty, nothing to do. This covers cards that were already
 750   // scanned as parts of the remembered sets.
 751   if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 752     // No need to return that this card contains refs that point
 753     // into the collection set.
 754     return false;
 755   }
 756 
 757   // During GC we can immediately clean the card since we will not re-enqueue stale
 758   // cards as we know they can be disregarded.
 759   *card_ptr = CardTableModRefBS::clean_card_val();
 760 
 761   // Construct the region representing the card.
 762   HeapWord* card_start = _ct_bs->addr_for(card_ptr);
 763   // And find the region containing it.
 764   HeapRegion* r = _g1->heap_region_containing(card_start);
 765 
 766   HeapWord* scan_limit = _scan_state->scan_top(r->hrm_index());
 767   if (scan_limit <= card_start) {
 768     // If the card starts above the area in the region containing objects to scan, skip it.
 769     return false;
 770   }
 771 
 772   // Don't use addr_for(card_ptr + 1) which can ask for
 773   // a card beyond the heap.
 774   HeapWord* card_end = card_start + CardTableModRefBS::card_size_in_words;
 775   MemRegion dirty_region(card_start, MIN2(scan_limit, card_end));
 776   assert(!dirty_region.is_empty(), "sanity");
 777 
 778   G1UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
 779                                                  oops_in_heap_closure,
 780                                                  true,
 781                                                  worker_i);
 782   update_rs_oop_cl.set_from(r);
 783 
 784   bool card_processed =
 785     r->oops_on_card_seq_iterate_careful<true>(dirty_region,
 786                                               &update_rs_oop_cl);
 787   assert(card_processed, "must be");
 788   _conc_refine_cards++;
 789 
 790   return update_rs_oop_cl.has_refs_into_cset();
 791 }
 792 
 793 void G1RemSet::print_periodic_summary_info(const char* header, uint period_count) {
 794   if ((G1SummarizeRSetStatsPeriod > 0) && log_is_enabled(Trace, gc, remset) &&
 795       (period_count % G1SummarizeRSetStatsPeriod == 0)) {
 796 
 797     if (!_prev_period_summary.initialized()) {
 798       _prev_period_summary.initialize(this);
 799     }
 800 
 801     G1RemSetSummary current;
 802     current.initialize(this);
 803     _prev_period_summary.subtract_from(&current);
 804 
 805     Log(gc, remset) log;
 806     log.trace("%s", header);
 807     ResourceMark rm;
 808     _prev_period_summary.print_on(log.trace_stream());
 809 
 810     _prev_period_summary.set(&current);




 310 }
 311 
 312 uint G1RemSet::num_par_rem_sets() {
 313   return MAX2(DirtyCardQueueSet::num_par_ids() + ConcurrentG1Refine::thread_num(), ParallelGCThreads);
 314 }
 315 
 316 void G1RemSet::initialize(size_t capacity, uint max_regions) {
 317   G1FromCardCache::initialize(num_par_rem_sets(), max_regions);
 318   _scan_state->initialize(max_regions);
 319   {
 320     GCTraceTime(Debug, gc, marking)("Initialize Card Live Data");
 321     _card_live_data.initialize(capacity, max_regions);
 322   }
 323   if (G1PretouchAuxiliaryMemory) {
 324     GCTraceTime(Debug, gc, marking)("Pre-Touch Card Live Data");
 325     _card_live_data.pretouch();
 326   }
 327 }
 328 
 329 G1ScanRSClosure::G1ScanRSClosure(G1RemSetScanState* scan_state,
 330                                  G1ScanObjsDuringScanRSClosure* scan_obj_on_card,
 331                                  CodeBlobClosure* code_root_cl,
 332                                  uint worker_i) :
 333   _scan_state(scan_state),
 334   _scan_objs_on_card_cl(scan_obj_on_card),
 335   _code_root_cl(code_root_cl),
 336   _strong_code_root_scan_time_sec(0.0),
 337   _cards_claimed(0),
 338   _cards_scanned(0),
 339   _cards_skipped(0),
 340   _worker_i(worker_i) {
 341   _g1h = G1CollectedHeap::heap();
 342   _bot = _g1h->bot();
 343   _ct_bs = _g1h->g1_barrier_set();
 344   _block_size = MAX2<size_t>(G1RSetScanBlockSize, 1);
 345 }
 346 
 347 void G1ScanRSClosure::scan_card(size_t index, HeapWord* card_start, HeapRegion *r) {
 348   MemRegion card_region(card_start, BOTConstants::N_words);
 349   MemRegion pre_gc_allocated(r->bottom(), _scan_state->scan_top(r->hrm_index()));
 350   MemRegion mr = pre_gc_allocated.intersection(card_region);
 351   if (!mr.is_empty() && !_ct_bs->is_card_claimed(index)) {
 352     // We make the card as "claimed" lazily (so races are possible
 353     // but they're benign), which reduces the number of duplicate
 354     // scans (the rsets of the regions in the cset can intersect).
 355     _ct_bs->set_card_claimed(index);
 356     _scan_objs_on_card_cl->set_region(r);
 357     r->oops_on_card_seq_iterate_careful<true>(mr, _scan_objs_on_card_cl);
 358     _cards_scanned++;
 359   }
 360 }
 361 
 362 void G1ScanRSClosure::scan_strong_code_roots(HeapRegion* r) {
 363   double scan_start = os::elapsedTime();
 364   r->strong_code_roots_do(_code_root_cl);
 365   _strong_code_root_scan_time_sec += (os::elapsedTime() - scan_start);
 366 }
 367 
 368 bool G1ScanRSClosure::doHeapRegion(HeapRegion* r) {
 369   assert(r->in_collection_set(), "should only be called on elements of CS.");
 370   uint region_idx = r->hrm_index();
 371 
 372   if (_scan_state->iter_is_complete(region_idx)) {
 373     return false;
 374   }
 375   if (_scan_state->claim_iter(region_idx)) {
 376     // If we ever free the collection set concurrently, we should also
 377     // clear the card table concurrently therefore we won't need to


 396     HeapWord* card_start = _g1h->bot()->address_for_index(card_index);
 397 
 398     HeapRegion* card_region = _g1h->heap_region_containing(card_start);
 399     _cards_claimed++;
 400 
 401     _scan_state->add_dirty_region(card_region->hrm_index());
 402 
 403     // If the card is dirty, then we will scan it during updateRS.
 404     if (!card_region->in_collection_set() &&
 405         !_ct_bs->is_card_dirty(card_index)) {
 406       scan_card(card_index, card_start, card_region);
 407     }
 408   }
 409   if (_scan_state->set_iter_complete(region_idx)) {
 410     // Scan the strong code root list attached to the current region
 411     scan_strong_code_roots(r);
 412   }
 413   return false;
 414 }
 415 
 416 void G1RemSet::scan_rem_set(G1ScanObjsDuringScanRSClosure* oops_in_heap_closure,
 417                             CodeBlobClosure* heap_region_codeblobs,
 418                             uint worker_i) {
 419   double rs_time_start = os::elapsedTime();
 420 
 421   G1ScanRSClosure cl(_scan_state, oops_in_heap_closure, heap_region_codeblobs, worker_i);
 422   _g1->collection_set_iterate_from(&cl, worker_i);
 423 
 424   double scan_rs_time_sec = (os::elapsedTime() - rs_time_start) -
 425                              cl.strong_code_root_scan_time_sec();
 426 
 427   G1GCPhaseTimes* p = _g1p->phase_times();
 428 
 429   p->record_time_secs(G1GCPhaseTimes::ScanRS, worker_i, scan_rs_time_sec);
 430   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_scanned(), G1GCPhaseTimes::ScannedCards);
 431   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_claimed(), G1GCPhaseTimes::ClaimedCards);
 432   p->record_thread_work_item(G1GCPhaseTimes::ScanRS, worker_i, cl.cards_skipped(), G1GCPhaseTimes::SkippedCards);
 433   
 434   p->record_time_secs(G1GCPhaseTimes::CodeRoots, worker_i, cl.strong_code_root_scan_time_sec());  
 435 }
 436 
 437 // Closure used for updating RSets and recording references that
 438 // point into the collection set. Only called during an
 439 // evacuation pause.
 440 
 441 class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure {
 442   G1RemSet* _g1rs;
 443   DirtyCardQueue* _into_cset_dcq;
 444   G1ScanObjsDuringUpdateRSClosure* _cl;
 445 public:
 446   RefineRecordRefsIntoCSCardTableEntryClosure(G1CollectedHeap* g1h,
 447                                               DirtyCardQueue* into_cset_dcq,
 448                                               G1ScanObjsDuringUpdateRSClosure* cl) :
 449     _g1rs(g1h->g1_rem_set()), _into_cset_dcq(into_cset_dcq), _cl(cl)
 450   {}
 451 
 452   bool do_card_ptr(jbyte* card_ptr, uint worker_i) {
 453     // The only time we care about recording cards that
 454     // contain references that point into the collection set
 455     // is during RSet updating within an evacuation pause.
 456     // In this case worker_i should be the id of a GC worker thread.
 457     assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause");

 458 
 459     if (_g1rs->refine_card_during_gc(card_ptr, _cl)) {
 460       // 'card_ptr' contains references that point into the collection
 461       // set. We need to record the card in the DCQS
 462       // (_into_cset_dirty_card_queue_set)
 463       // that's used for that purpose.
 464       //
 465       // Enqueue the card
 466       _into_cset_dcq->enqueue(card_ptr);
 467     }
 468     return true;
 469   }
 470 };
 471 
 472 void G1RemSet::update_rem_set(DirtyCardQueue* into_cset_dcq,
 473                               G1ScanObjsDuringUpdateRSClosure* oops_in_heap_closure,
 474                               uint worker_i) {
 475   RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq, oops_in_heap_closure);
 476 
 477   G1GCParPhaseTimesTracker x(_g1p->phase_times(), G1GCPhaseTimes::UpdateRS, worker_i);
 478   if (G1HotCardCache::default_use_cache()) {
 479     // Apply the closure to the entries of the hot card cache.
 480     G1GCParPhaseTimesTracker y(_g1p->phase_times(), G1GCPhaseTimes::ScanHCC, worker_i);
 481     _g1->iterate_hcc_closure(&into_cset_update_rs_cl, worker_i);
 482   }
 483   // Apply the closure to all remaining log entries.
 484   _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, worker_i);
 485 }
 486 
 487 void G1RemSet::cleanupHRRS() {
 488   HeapRegionRemSet::cleanup();
 489 }
 490 
 491 void G1RemSet::oops_into_collection_set_do(G1ParScanThreadState* pss,
 492                                            CodeBlobClosure* heap_region_codeblobs,
 493                                            uint worker_i) {
 494   // A DirtyCardQueue that is used to hold cards containing references
 495   // that point into the collection set. This DCQ is associated with a
 496   // special DirtyCardQueueSet (see g1CollectedHeap.hpp).  Under normal
 497   // circumstances (i.e. the pause successfully completes), these cards
 498   // are just discarded (there's no need to update the RSets of regions
 499   // that were in the collection set - after the pause these regions
 500   // are wholly 'free' of live objects. In the event of an evacuation
 501   // failure the cards/buffers in this queue set are passed to the
 502   // DirtyCardQueueSet that is used to manage RSet updates
 503   DirtyCardQueue into_cset_dcq(&_into_cset_dirty_card_queue_set);
 504 
 505   {
 506     G1ScanObjsDuringUpdateRSClosure cl(_g1, pss, worker_i);
 507     update_rem_set(&into_cset_dcq, &cl, worker_i);
 508   }
 509   {
 510     G1ScanObjsDuringScanRSClosure cl(_g1, pss);
 511     scan_rem_set(&cl, heap_region_codeblobs, worker_i);;
 512   }
 513 }
 514 
 515 void G1RemSet::prepare_for_oops_into_collection_set_do() {
 516   _g1->set_refine_cte_cl_concurrency(false);
 517   DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
 518   dcqs.concatenate_logs();
 519 
 520   _scan_state->reset();
 521 }
 522 
 523 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
 524   G1GCPhaseTimes* phase_times = _g1->g1_policy()->phase_times();
 525   // Cleanup after copy
 526   _g1->set_refine_cte_cl_concurrency(true);
 527 
 528   // Set all cards back to clean.
 529   double start = os::elapsedTime();
 530   _scan_state->clear_card_table(_g1->workers());
 531   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
 532 


 567   }
 568 };
 569 
 570 void G1RemSet::scrub(uint worker_num, HeapRegionClaimer *hrclaimer) {
 571   G1ScrubRSClosure scrub_cl(&_card_live_data);
 572   _g1->heap_region_par_iterate(&scrub_cl, worker_num, hrclaimer);
 573 }
 574 
 575 inline void check_card_ptr(jbyte* card_ptr, CardTableModRefBS* ct_bs) {
 576 #ifdef ASSERT
 577   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 578   assert(g1->is_in_exact(ct_bs->addr_for(card_ptr)),
 579          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
 580          p2i(card_ptr),
 581          ct_bs->index_for(ct_bs->addr_for(card_ptr)),
 582          p2i(ct_bs->addr_for(card_ptr)),
 583          g1->addr_to_region(ct_bs->addr_for(card_ptr)));
 584 #endif
 585 }
 586 











 587 void G1RemSet::refine_card_concurrently(jbyte* card_ptr,
 588                                         uint worker_i) {
 589   assert(!_g1->is_gc_active(), "Only call concurrently");
 590 
 591   check_card_ptr(card_ptr, _ct_bs);
 592 
 593   // If the card is no longer dirty, nothing to do.
 594   if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 595     return;
 596   }
 597 
 598   // Construct the region representing the card.
 599   HeapWord* start = _ct_bs->addr_for(card_ptr);
 600   // And find the region containing it.
 601   HeapRegion* r = _g1->heap_region_containing(start);
 602 
 603   // This check is needed for some uncommon cases where we should
 604   // ignore the card.
 605   //
 606   // The region could be young.  Cards for young regions are


 717   // processing a stale card.  Despite the card being stale, redirty
 718   // and re-enqueue, because we've already cleaned the card.  Without
 719   // this we could incorrectly discard a non-stale card.
 720   if (!card_processed) {
 721     // The card might have gotten re-dirtied and re-enqueued while we
 722     // worked.  (In fact, it's pretty likely.)
 723     if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 724       *card_ptr = CardTableModRefBS::dirty_card_val();
 725       MutexLockerEx x(Shared_DirtyCardQ_lock,
 726                       Mutex::_no_safepoint_check_flag);
 727       DirtyCardQueue* sdcq =
 728         JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
 729       sdcq->enqueue(card_ptr);
 730     }
 731   } else {
 732     _conc_refine_cards++;
 733   }
 734 }
 735 
 736 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
 737                                      G1ScanObjsDuringUpdateRSClosure* oops_in_heap_closure) {

 738   assert(_g1->is_gc_active(), "Only call during GC");
 739 
 740   check_card_ptr(card_ptr, _ct_bs);
 741 
 742   // If the card is no longer dirty, nothing to do. This covers cards that were already
 743   // scanned as parts of the remembered sets.
 744   if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
 745     // No need to return that this card contains refs that point
 746     // into the collection set.
 747     return false;
 748   }
 749 
 750   // During GC we can immediately clean the card since we will not re-enqueue stale
 751   // cards as we know they can be disregarded.
 752   *card_ptr = CardTableModRefBS::clean_card_val();
 753 
 754   // Construct the region representing the card.
 755   HeapWord* card_start = _ct_bs->addr_for(card_ptr);
 756   // And find the region containing it.
 757   HeapRegion* r = _g1->heap_region_containing(card_start);
 758 
 759   HeapWord* scan_limit = _scan_state->scan_top(r->hrm_index());
 760   if (scan_limit <= card_start) {
 761     // If the card starts above the area in the region containing objects to scan, skip it.
 762     return false;
 763   }
 764 
 765   // Don't use addr_for(card_ptr + 1) which can ask for
 766   // a card beyond the heap.
 767   HeapWord* card_end = card_start + CardTableModRefBS::card_size_in_words;
 768   MemRegion dirty_region(card_start, MIN2(scan_limit, card_end));
 769   assert(!dirty_region.is_empty(), "sanity");
 770 
 771   oops_in_heap_closure->set_region(r);
 772   oops_in_heap_closure->reset_has_refs_into_cset();



 773 
 774   bool card_processed = r->oops_on_card_seq_iterate_careful<true>(dirty_region, oops_in_heap_closure);


 775   assert(card_processed, "must be");
 776   _conc_refine_cards++;
 777 
 778   return oops_in_heap_closure->has_refs_into_cset();
 779 }
 780 
 781 void G1RemSet::print_periodic_summary_info(const char* header, uint period_count) {
 782   if ((G1SummarizeRSetStatsPeriod > 0) && log_is_enabled(Trace, gc, remset) &&
 783       (period_count % G1SummarizeRSetStatsPeriod == 0)) {
 784 
 785     if (!_prev_period_summary.initialized()) {
 786       _prev_period_summary.initialize(this);
 787     }
 788 
 789     G1RemSetSummary current;
 790     current.initialize(this);
 791     _prev_period_summary.subtract_from(&current);
 792 
 793     Log(gc, remset) log;
 794     log.trace("%s", header);
 795     ResourceMark rm;
 796     _prev_period_summary.print_on(log.trace_stream());
 797 
 798     _prev_period_summary.set(&current);


< prev index next >