< prev index next >

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

Print this page
rev 54044 : [mq]: new_shared_dcq


  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/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/g1ConcurrentRefine.hpp"
  31 #include "gc/g1/g1DirtyCardQueue.hpp"
  32 #include "gc/g1/g1FromCardCache.hpp"
  33 #include "gc/g1/g1GCPhaseTimes.hpp"
  34 #include "gc/g1/g1HotCardCache.hpp"
  35 #include "gc/g1/g1OopClosures.inline.hpp"
  36 #include "gc/g1/g1RootClosures.hpp"
  37 #include "gc/g1/g1RemSet.hpp"

  38 #include "gc/g1/heapRegion.inline.hpp"
  39 #include "gc/g1/heapRegionManager.inline.hpp"
  40 #include "gc/g1/heapRegionRemSet.hpp"
  41 #include "gc/shared/gcTraceTime.inline.hpp"
  42 #include "gc/shared/suspendibleThreadSet.hpp"
  43 #include "jfr/jfrEvents.hpp"
  44 #include "memory/iterator.hpp"
  45 #include "memory/resourceArea.hpp"
  46 #include "oops/access.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "runtime/os.hpp"
  49 #include "utilities/align.hpp"
  50 #include "utilities/globalDefinitions.hpp"
  51 #include "utilities/stack.inline.hpp"
  52 #include "utilities/ticks.hpp"
  53 
  54 // Collects information about the overall remembered set scan progress during an evacuation.
  55 class G1RemSetScanState : public CHeapObj<mtGC> {
  56 private:
  57   class G1ClearCardTableTask : public AbstractGangTask {


 506 
 507   // Now apply the closure to all remaining log entries.
 508   {
 509     G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::UpdateRS, worker_i);
 510 
 511     G1ScanObjsDuringUpdateRSClosure update_rs_cl(_g1h, pss);
 512     G1RefineCardClosure refine_card_cl(_g1h, &update_rs_cl);
 513     _g1h->iterate_dirty_card_closure(&refine_card_cl, worker_i);
 514 
 515     p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_scanned(), G1GCPhaseTimes::UpdateRSScannedCards);
 516     p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_skipped(), G1GCPhaseTimes::UpdateRSSkippedCards);
 517   }
 518 }
 519 
 520 void G1RemSet::oops_into_collection_set_do(G1ParScanThreadState* pss, uint worker_i) {
 521   update_rem_set(pss, worker_i);
 522   scan_rem_set(pss, worker_i);;
 523 }
 524 
 525 void G1RemSet::prepare_for_oops_into_collection_set_do() {
 526   G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
 527   dcqs.concatenate_logs();
 528 
 529   _scan_state->reset();
 530 }
 531 
 532 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
 533   G1GCPhaseTimes* phase_times = _g1h->phase_times();
 534 
 535   // Set all cards back to clean.
 536   double start = os::elapsedTime();
 537   _scan_state->clear_card_table(_g1h->workers());
 538   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
 539 }
 540 
 541 inline void check_card_ptr(jbyte* card_ptr, G1CardTable* ct) {
 542 #ifdef ASSERT
 543   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 544   assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
 545          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
 546          p2i(card_ptr),
 547          ct->index_for(ct->addr_for(card_ptr)),
 548          p2i(ct->addr_for(card_ptr)),


 647   // Okay to clean and process the card now.  There are still some
 648   // stale card cases that may be detected by iteration and dealt with
 649   // as iteration failure.
 650   *const_cast<volatile jbyte*>(card_ptr) = G1CardTable::clean_card_val();
 651 
 652   // This fence serves two purposes.  First, the card must be cleaned
 653   // before processing the contents.  Second, we can't proceed with
 654   // processing until after the read of top, for synchronization with
 655   // possibly concurrent humongous object allocation.  It's okay that
 656   // reading top and reading type were racy wrto each other.  We need
 657   // both set, in any order, to proceed.
 658   OrderAccess::fence();
 659 
 660   // Don't use addr_for(card_ptr + 1) which can ask for
 661   // a card beyond the heap.
 662   HeapWord* end = start + G1CardTable::card_size_in_words;
 663   MemRegion dirty_region(start, MIN2(scan_limit, end));
 664   assert(!dirty_region.is_empty(), "sanity");
 665 
 666   G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
 667 
 668   bool card_processed =
 669     r->oops_on_card_seq_iterate_careful<false>(dirty_region, &conc_refine_cl);

 670 
 671   // If unable to process the card then we encountered an unparsable
 672   // part of the heap (e.g. a partially allocated object) while
 673   // processing a stale card.  Despite the card being stale, redirty
 674   // and re-enqueue, because we've already cleaned the card.  Without
 675   // this we could incorrectly discard a non-stale card.
 676   if (!card_processed) {
 677     // The card might have gotten re-dirtied and re-enqueued while we
 678     // worked.  (In fact, it's pretty likely.)
 679     if (*card_ptr != G1CardTable::dirty_card_val()) {
 680       *card_ptr = G1CardTable::dirty_card_val();
 681       MutexLockerEx x(Shared_DirtyCardQ_lock,
 682                       Mutex::_no_safepoint_check_flag);
 683       G1DirtyCardQueue* sdcq =
 684         G1BarrierSet::dirty_card_queue_set().shared_dirty_card_queue();
 685       sdcq->enqueue(card_ptr);
 686     }
 687   } else {
 688     _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
 689   }







 690 }
 691 
 692 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
 693                                      G1ScanObjsDuringUpdateRSClosure* update_rs_cl) {
 694   assert(_g1h->is_gc_active(), "Only call during GC");
 695 
 696   // Construct the region representing the card.
 697   HeapWord* card_start = _ct->addr_for(card_ptr);
 698   // And find the region containing it.
 699   uint const card_region_idx = _g1h->addr_to_region(card_start);
 700 
 701   HeapWord* scan_limit = _scan_state->scan_top(card_region_idx);
 702   if (scan_limit == NULL) {
 703     // This is a card into an uncommitted region. We need to bail out early as we
 704     // should not access the corresponding card table entry.
 705     return false;
 706   }
 707 
 708   check_card_ptr(card_ptr, _ct);
 709 




  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/g1CollectedHeap.inline.hpp"
  30 #include "gc/g1/g1ConcurrentRefine.hpp"
  31 #include "gc/g1/g1DirtyCardQueue.hpp"
  32 #include "gc/g1/g1FromCardCache.hpp"
  33 #include "gc/g1/g1GCPhaseTimes.hpp"
  34 #include "gc/g1/g1HotCardCache.hpp"
  35 #include "gc/g1/g1OopClosures.inline.hpp"
  36 #include "gc/g1/g1RootClosures.hpp"
  37 #include "gc/g1/g1RemSet.hpp"
  38 #include "gc/g1/g1SharedDirtyCardQueue.hpp"
  39 #include "gc/g1/heapRegion.inline.hpp"
  40 #include "gc/g1/heapRegionManager.inline.hpp"
  41 #include "gc/g1/heapRegionRemSet.hpp"
  42 #include "gc/shared/gcTraceTime.inline.hpp"
  43 #include "gc/shared/suspendibleThreadSet.hpp"
  44 #include "jfr/jfrEvents.hpp"
  45 #include "memory/iterator.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/access.inline.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "runtime/os.hpp"
  50 #include "utilities/align.hpp"
  51 #include "utilities/globalDefinitions.hpp"
  52 #include "utilities/stack.inline.hpp"
  53 #include "utilities/ticks.hpp"
  54 
  55 // Collects information about the overall remembered set scan progress during an evacuation.
  56 class G1RemSetScanState : public CHeapObj<mtGC> {
  57 private:
  58   class G1ClearCardTableTask : public AbstractGangTask {


 507 
 508   // Now apply the closure to all remaining log entries.
 509   {
 510     G1EvacPhaseTimesTracker x(p, pss, G1GCPhaseTimes::UpdateRS, worker_i);
 511 
 512     G1ScanObjsDuringUpdateRSClosure update_rs_cl(_g1h, pss);
 513     G1RefineCardClosure refine_card_cl(_g1h, &update_rs_cl);
 514     _g1h->iterate_dirty_card_closure(&refine_card_cl, worker_i);
 515 
 516     p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_scanned(), G1GCPhaseTimes::UpdateRSScannedCards);
 517     p->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, refine_card_cl.cards_skipped(), G1GCPhaseTimes::UpdateRSSkippedCards);
 518   }
 519 }
 520 
 521 void G1RemSet::oops_into_collection_set_do(G1ParScanThreadState* pss, uint worker_i) {
 522   update_rem_set(pss, worker_i);
 523   scan_rem_set(pss, worker_i);;
 524 }
 525 
 526 void G1RemSet::prepare_for_oops_into_collection_set_do() {
 527   G1BarrierSet::dirty_card_queue_set().concatenate_logs();


 528   _scan_state->reset();
 529 }
 530 
 531 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
 532   G1GCPhaseTimes* phase_times = _g1h->phase_times();
 533 
 534   // Set all cards back to clean.
 535   double start = os::elapsedTime();
 536   _scan_state->clear_card_table(_g1h->workers());
 537   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
 538 }
 539 
 540 inline void check_card_ptr(jbyte* card_ptr, G1CardTable* ct) {
 541 #ifdef ASSERT
 542   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 543   assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
 544          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
 545          p2i(card_ptr),
 546          ct->index_for(ct->addr_for(card_ptr)),
 547          p2i(ct->addr_for(card_ptr)),


 646   // Okay to clean and process the card now.  There are still some
 647   // stale card cases that may be detected by iteration and dealt with
 648   // as iteration failure.
 649   *const_cast<volatile jbyte*>(card_ptr) = G1CardTable::clean_card_val();
 650 
 651   // This fence serves two purposes.  First, the card must be cleaned
 652   // before processing the contents.  Second, we can't proceed with
 653   // processing until after the read of top, for synchronization with
 654   // possibly concurrent humongous object allocation.  It's okay that
 655   // reading top and reading type were racy wrto each other.  We need
 656   // both set, in any order, to proceed.
 657   OrderAccess::fence();
 658 
 659   // Don't use addr_for(card_ptr + 1) which can ask for
 660   // a card beyond the heap.
 661   HeapWord* end = start + G1CardTable::card_size_in_words;
 662   MemRegion dirty_region(start, MIN2(scan_limit, end));
 663   assert(!dirty_region.is_empty(), "sanity");
 664 
 665   G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_i);
 666   if (r->oops_on_card_seq_iterate_careful<false>(dirty_region, &conc_refine_cl)) {
 667     _num_conc_refined_cards++; // Unsynchronized update, only used for logging.
 668     return;
 669   }
 670 
 671   // If unable to process the card then we encountered an unparsable
 672   // part of the heap (e.g. a partially allocated object, so only
 673   // temporarily a problem) while processing a stale card.  Despite
 674   // the card being stale, we can't simply ignore it, because we've
 675   // already marked the card cleaned, so taken responsibility for
 676   // ensuring the card gets scanned.
 677   //
 678   // However, the card might have gotten re-dirtied and re-enqueued
 679   // while we worked.  (In fact, it's pretty likely.)
 680   if (*card_ptr == G1CardTable::dirty_card_val()) {
 681     return;







 682   }
 683 
 684   // Re-dirty the card and enqueue in the *shared* queue.  Can't use
 685   // the thread-local queue, because that might be the queue that is
 686   // being processed by us; we could be a Java thread conscripted to
 687   // perform refinement on our queue's current buffer.
 688   *card_ptr = G1CardTable::dirty_card_val();
 689   G1BarrierSet::shared_dirty_card_queue().enqueue(card_ptr);
 690 }
 691 
 692 bool G1RemSet::refine_card_during_gc(jbyte* card_ptr,
 693                                      G1ScanObjsDuringUpdateRSClosure* update_rs_cl) {
 694   assert(_g1h->is_gc_active(), "Only call during GC");
 695 
 696   // Construct the region representing the card.
 697   HeapWord* card_start = _ct->addr_for(card_ptr);
 698   // And find the region containing it.
 699   uint const card_region_idx = _g1h->addr_to_region(card_start);
 700 
 701   HeapWord* scan_limit = _scan_state->scan_top(card_region_idx);
 702   if (scan_limit == NULL) {
 703     // This is a card into an uncommitted region. We need to bail out early as we
 704     // should not access the corresponding card table entry.
 705     return false;
 706   }
 707 
 708   check_card_ptr(card_ptr, _ct);
 709 


< prev index next >