8155524: HotCardCache shouldn't be part of ConcurrentG1Refine
authorkbarrett
Mon, 02 May 2016 12:07:58 -0400
changeset 38172 90f405aac699
parent 38171 9a0932ed12a1
child 38173 73d05e56ec86
8155524: HotCardCache shouldn't be part of ConcurrentG1Refine Summary: Make G1CollectedHeap owner of HotCardCache. Reviewed-by: jmasa, mgerdin, tschatzl
hotspot/src/share/vm/gc/g1/concurrentG1Refine.cpp
hotspot/src/share/vm/gc/g1/concurrentG1Refine.hpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp
hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp
hotspot/src/share/vm/gc/g1/g1DefaultPolicy.cpp
hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp
hotspot/src/share/vm/gc/g1/g1RemSet.cpp
hotspot/src/share/vm/gc/g1/g1RemSet.hpp
hotspot/src/share/vm/gc/g1/g1RemSetSummary.cpp
--- a/hotspot/src/share/vm/gc/g1/concurrentG1Refine.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/concurrentG1Refine.cpp	Mon May 02 12:07:58 2016 -0400
@@ -25,9 +25,10 @@
 #include "precompiled.hpp"
 #include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/concurrentG1RefineThread.hpp"
-#include "gc/g1/g1CollectedHeap.inline.hpp"
-#include "gc/g1/g1HotCardCache.hpp"
+#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
+#include "logging/log.hpp"
 #include "runtime/java.hpp"
+#include "runtime/thread.hpp"
 #include "utilities/debug.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "utilities/pair.hpp"
@@ -111,8 +112,7 @@
                     green_zone + deactivate_offset);
 }
 
-ConcurrentG1Refine::ConcurrentG1Refine(G1CollectedHeap* g1h,
-                                       size_t green_zone,
+ConcurrentG1Refine::ConcurrentG1Refine(size_t green_zone,
                                        size_t yellow_zone,
                                        size_t red_zone,
                                        size_t min_yellow_zone_size) :
@@ -122,8 +122,7 @@
   _green_zone(green_zone),
   _yellow_zone(yellow_zone),
   _red_zone(red_zone),
-  _min_yellow_zone_size(min_yellow_zone_size),
-  _hot_card_cache(g1h)
+  _min_yellow_zone_size(min_yellow_zone_size)
 {
   assert_zone_constraints_gyr(green_zone, yellow_zone, red_zone);
 }
@@ -170,8 +169,7 @@
   return MIN2(yellow + size, max_red_zone);
 }
 
-ConcurrentG1Refine* ConcurrentG1Refine::create(G1CollectedHeap* g1h,
-                                               CardTableEntryClosure* refine_closure,
+ConcurrentG1Refine* ConcurrentG1Refine::create(CardTableEntryClosure* refine_closure,
                                                jint* ecode) {
   size_t min_yellow_zone_size = calc_min_yellow_zone_size();
   size_t green_zone = calc_init_green_zone();
@@ -185,8 +183,7 @@
             "min yellow size: " SIZE_FORMAT,
             green_zone, yellow_zone, red_zone, min_yellow_zone_size);
 
-  ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(g1h,
-                                                    green_zone,
+  ConcurrentG1Refine* cg1r = new ConcurrentG1Refine(green_zone,
                                                     yellow_zone,
                                                     red_zone,
                                                     min_yellow_zone_size);
@@ -240,10 +237,6 @@
   return cg1r;
 }
 
-void ConcurrentG1Refine::init(G1RegionToSpaceMapper* card_counts_storage) {
-  _hot_card_cache.initialize(card_counts_storage);
-}
-
 void ConcurrentG1Refine::stop() {
   for (uint i = 0; i < _n_worker_threads; i++) {
     _threads[i]->stop();
--- a/hotspot/src/share/vm/gc/g1/concurrentG1Refine.hpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/concurrentG1Refine.hpp	Mon May 02 12:07:58 2016 -0400
@@ -25,20 +25,15 @@
 #ifndef SHARE_VM_GC_G1_CONCURRENTG1REFINE_HPP
 #define SHARE_VM_GC_G1_CONCURRENTG1REFINE_HPP
 
-#include "gc/g1/g1HotCardCache.hpp"
-#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
 #include "memory/allocation.hpp"
-#include "runtime/thread.hpp"
 #include "utilities/globalDefinitions.hpp"
 
 // Forward decl
+class CardTableEntryClosure;
 class ConcurrentG1RefineThread;
-class G1CollectedHeap;
-class G1HotCardCache;
-class G1Predictions;
-class G1RegionToSpaceMapper;
-class G1RemSet;
-class DirtyCardQueue;
+class G1YoungRemSetSamplingThread;
+class outputStream;
+class ThreadClosure;
 
 class ConcurrentG1Refine: public CHeapObj<mtGC> {
   G1YoungRemSetSamplingThread* _sample_thread;
@@ -67,11 +62,7 @@
   size_t _red_zone;
   size_t _min_yellow_zone_size;
 
-  // We delay the refinement of 'hot' cards using the hot card cache.
-  G1HotCardCache _hot_card_cache;
-
-  ConcurrentG1Refine(G1CollectedHeap* g1h,
-                     size_t green_zone,
+  ConcurrentG1Refine(size_t green_zone,
                      size_t yellow_zone,
                      size_t red_zone,
                      size_t min_yellow_zone_size);
@@ -89,9 +80,8 @@
 
   // Returns ConcurrentG1Refine instance if succeeded to create/initialize ConcurrentG1Refine and ConcurrentG1RefineThread.
   // Otherwise, returns NULL with error code.
-  static ConcurrentG1Refine* create(G1CollectedHeap* g1h, CardTableEntryClosure* refine_closure, jint* ecode);
+  static ConcurrentG1Refine* create(CardTableEntryClosure* refine_closure, jint* ecode);
 
-  void init(G1RegionToSpaceMapper* card_counts_storage);
   void stop();
 
   void adjust(double update_rs_time, size_t update_rs_processed_buffers, double goal_ms);
@@ -112,10 +102,6 @@
   size_t green_zone() const      { return _green_zone;  }
   size_t yellow_zone() const     { return _yellow_zone; }
   size_t red_zone() const        { return _red_zone;    }
-
-  G1HotCardCache* hot_card_cache() { return &_hot_card_cache; }
-
-  static bool hot_card_cache_enabled() { return G1HotCardCache::default_use_cache(); }
 };
 
 #endif // SHARE_VM_GC_G1_CONCURRENTG1REFINE_HPP
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.cpp	Mon May 02 12:07:58 2016 -0400
@@ -42,6 +42,7 @@
 #include "gc/g1/g1HeapSizingPolicy.hpp"
 #include "gc/g1/g1HeapTransition.hpp"
 #include "gc/g1/g1HeapVerifier.hpp"
+#include "gc/g1/g1HotCardCache.hpp"
 #include "gc/g1/g1MarkSweep.hpp"
 #include "gc/g1/g1OopClosures.inline.hpp"
 #include "gc/g1/g1ParScanThreadState.inline.hpp"
@@ -1322,10 +1323,9 @@
       // the compaction events.
       print_hrm_post_compaction();
 
-      G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
-      if (hot_card_cache->use_cache()) {
-        hot_card_cache->reset_card_counts();
-        hot_card_cache->reset_hot_cache();
+      if (_hot_card_cache->use_cache()) {
+        _hot_card_cache->reset_card_counts();
+        _hot_card_cache->reset_hot_cache();
       }
 
       // Rebuild remembered sets of all regions.
@@ -1704,6 +1704,8 @@
   _ref_processor_cm(NULL),
   _ref_processor_stw(NULL),
   _bot(NULL),
+  _hot_card_cache(NULL),
+  _g1_rem_set(NULL),
   _cg1r(NULL),
   _g1mm(NULL),
   _refine_cte_cl(NULL),
@@ -1817,7 +1819,7 @@
   _refine_cte_cl = new RefineCardTableEntryClosure();
 
   jint ecode = JNI_OK;
-  _cg1r = ConcurrentG1Refine::create(this, _refine_cte_cl, &ecode);
+  _cg1r = ConcurrentG1Refine::create(_refine_cte_cl, &ecode);
   if (_cg1r == NULL) {
     return ecode;
   }
@@ -1847,8 +1849,11 @@
   assert(bs->is_a(BarrierSet::G1SATBCTLogging), "sanity");
   set_barrier_set(bs);
 
+  // Create the hot card cache.
+  _hot_card_cache = new G1HotCardCache(this);
+
   // Also create a G1 rem set.
-  _g1_rem_set = new G1RemSet(this, g1_barrier_set());
+  _g1_rem_set = new G1RemSet(this, g1_barrier_set(), _hot_card_cache);
 
   // Carve out the G1 part of the heap.
   ReservedSpace g1_rs = heap_rs.first_part(max_byte_size);
@@ -1893,8 +1898,8 @@
 
   _hrm.initialize(heap_storage, prev_bitmap_storage, next_bitmap_storage, bot_storage, cardtable_storage, card_counts_storage);
   g1_barrier_set()->initialize(cardtable_storage);
-   // Do later initialization work for concurrent refinement.
-  _cg1r->init(card_counts_storage);
+  // Do later initialization work for concurrent refinement.
+  _hot_card_cache->initialize(card_counts_storage);
 
   // 6843694 - ensure that the maximum region index can fit
   // in the remembered set structures.
@@ -2123,7 +2128,7 @@
 #endif // PRODUCT
 
 void G1CollectedHeap::iterate_hcc_closure(CardTableEntryClosure* cl, uint worker_i) {
-  _cg1r->hot_card_cache()->drain(cl, worker_i);
+  _hot_card_cache->drain(cl, worker_i);
 }
 
 void G1CollectedHeap::iterate_dirty_card_closure(CardTableEntryClosure* cl, uint worker_i) {
@@ -4510,9 +4515,8 @@
   _evacuation_failed = false;
 
   // Disable the hot card cache.
-  G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
-  hot_card_cache->reset_hot_cache_claimed_index();
-  hot_card_cache->set_use_cache(false);
+  _hot_card_cache->reset_hot_cache_claimed_index();
+  _hot_card_cache->set_use_cache(false);
 
   g1_rem_set()->prepare_for_oops_into_collection_set_do();
   _preserved_marks_set.assert_empty();
@@ -4615,9 +4619,8 @@
   // Reset and re-enable the hot card cache.
   // Note the counts for the cards in the regions in the
   // collection set are reset when the collection set is freed.
-  G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
-  hot_card_cache->reset_hot_cache();
-  hot_card_cache->set_use_cache(true);
+  _hot_card_cache->reset_hot_cache();
+  _hot_card_cache->set_use_cache(true);
 
   purge_code_root_memory();
 
@@ -4652,7 +4655,7 @@
   // Note: we only need to do this if the region is not young
   // (since we don't refine cards in young regions).
   if (!hr->is_young()) {
-    _cg1r->hot_card_cache()->reset_card_counts(hr);
+    _hot_card_cache->reset_card_counts(hr);
   }
   hr->hr_clear(par, true /* clear_space */, locked /* locked */);
   free_list->add_ordered(hr);
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp	Mon May 02 12:07:58 2016 -0400
@@ -71,6 +71,7 @@
 class G1CollectionSet;
 class G1CollectorPolicy;
 class G1Policy;
+class G1HotCardCache;
 class G1RemSet;
 class HeapRegionRemSetIterator;
 class G1ConcurrentMark;
@@ -762,6 +763,9 @@
   // Update object copying statistics.
   void record_obj_copy_mem_stats();
 
+  // The hot card cache for remembered set insertion optimization.
+  G1HotCardCache* _hot_card_cache;
+
   // The g1 remembered set of the heap.
   G1RemSet* _g1_rem_set;
 
--- a/hotspot/src/share/vm/gc/g1/g1DefaultPolicy.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1DefaultPolicy.cpp	Mon May 02 12:07:58 2016 -0400
@@ -30,6 +30,7 @@
 #include "gc/g1/g1CollectionSet.hpp"
 #include "gc/g1/g1ConcurrentMark.hpp"
 #include "gc/g1/g1DefaultPolicy.hpp"
+#include "gc/g1/g1HotCardCache.hpp"
 #include "gc/g1/g1IHOPControl.hpp"
 #include "gc/g1/g1GCPhaseTimes.hpp"
 #include "gc/g1/g1Policy.hpp"
@@ -675,7 +676,7 @@
   _short_lived_surv_rate_group->start_adding_regions();
   // Do that for any other surv rate groups
 
-  double scan_hcc_time_ms = ConcurrentG1Refine::hot_card_cache_enabled() ? average_time_ms(G1GCPhaseTimes::ScanHCC) : 0.0;
+  double scan_hcc_time_ms = G1HotCardCache::default_use_cache() ? average_time_ms(G1GCPhaseTimes::ScanHCC) : 0.0;
 
   if (update_stats) {
     double cost_per_card_ms = 0.0;
--- a/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1GCPhaseTimes.cpp	Mon May 02 12:07:58 2016 -0400
@@ -23,9 +23,9 @@
  */
 
 #include "precompiled.hpp"
-#include "gc/g1/concurrentG1Refine.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1GCPhaseTimes.hpp"
+#include "gc/g1/g1HotCardCache.hpp"
 #include "gc/g1/g1StringDedup.hpp"
 #include "gc/g1/workerDataArray.inline.hpp"
 #include "memory/resourceArea.hpp"
@@ -60,7 +60,7 @@
   _gc_par_phases[SATBFiltering] = new WorkerDataArray<double>(max_gc_threads, "SATB Filtering (ms):");
 
   _gc_par_phases[UpdateRS] = new WorkerDataArray<double>(max_gc_threads, "Update RS (ms):");
-  if (ConcurrentG1Refine::hot_card_cache_enabled()) {
+  if (G1HotCardCache::default_use_cache()) {
     _gc_par_phases[ScanHCC] = new WorkerDataArray<double>(max_gc_threads, "Scan HCC (ms):");
   } else {
     _gc_par_phases[ScanHCC] = NULL;
@@ -255,7 +255,7 @@
     trace_phase(_gc_par_phases[i]);
   }
   debug_phase(_gc_par_phases[UpdateRS]);
-  if (ConcurrentG1Refine::hot_card_cache_enabled()) {
+  if (G1HotCardCache::default_use_cache()) {
     trace_phase(_gc_par_phases[ScanHCC]);
   }
   debug_phase(_gc_par_phases[ScanRS]);
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.cpp	Mon May 02 12:07:58 2016 -0400
@@ -24,7 +24,6 @@
 
 #include "precompiled.hpp"
 #include "gc/g1/concurrentG1Refine.hpp"
-#include "gc/g1/concurrentG1RefineThread.hpp"
 #include "gc/g1/dirtyCardQueue.hpp"
 #include "gc/g1/g1BlockOffsetTable.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
@@ -240,13 +239,15 @@
   }
 };
 
-G1RemSet::G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs) :
+G1RemSet::G1RemSet(G1CollectedHeap* g1,
+                   CardTableModRefBS* ct_bs,
+                   G1HotCardCache* hot_card_cache) :
   _g1(g1),
   _scan_state(new G1RemSetScanState()),
   _conc_refine_cards(0),
   _ct_bs(ct_bs),
   _g1p(_g1->g1_policy()),
-  _cg1r(g1->concurrent_g1_refine()),
+  _hot_card_cache(hot_card_cache),
   _prev_period_summary(),
   _into_cset_dirty_card_queue_set(false)
 {
@@ -437,7 +438,7 @@
   RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq, oops_in_heap_closure);
 
   G1GCParPhaseTimesTracker x(_g1p->phase_times(), G1GCPhaseTimes::UpdateRS, worker_i);
-  if (ConcurrentG1Refine::hot_card_cache_enabled()) {
+  if (G1HotCardCache::default_use_cache()) {
     // Apply the closure to the entries of the hot card cache.
     G1GCParPhaseTimesTracker y(_g1p->phase_times(), G1GCPhaseTimes::ScanHCC, worker_i);
     _g1->iterate_hcc_closure(&into_cset_update_rs_cl, worker_i);
@@ -614,12 +615,11 @@
   //   * a pointer to a "hot" card that was evicted from the "hot" cache.
   //
 
-  G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
-  if (hot_card_cache->use_cache()) {
+  if (_hot_card_cache->use_cache()) {
     assert(!check_for_refs_into_cset, "sanity");
     assert(!SafepointSynchronize::is_at_safepoint(), "sanity");
 
-    card_ptr = hot_card_cache->insert(card_ptr);
+    card_ptr = _hot_card_cache->insert(card_ptr);
     if (card_ptr == NULL) {
       // There was no eviction. Nothing to do.
       return false;
@@ -754,15 +754,14 @@
       dcqs.concatenate_logs();
     }
 
-    G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
-    bool use_hot_card_cache = hot_card_cache->use_cache();
-    hot_card_cache->set_use_cache(false);
+    bool use_hot_card_cache = _hot_card_cache->use_cache();
+    _hot_card_cache->set_use_cache(false);
 
     DirtyCardQueue into_cset_dcq(&_into_cset_dirty_card_queue_set);
     update_rem_set(&into_cset_dcq, NULL, 0);
     _into_cset_dirty_card_queue_set.clear();
 
-    hot_card_cache->set_use_cache(use_hot_card_cache);
+    _hot_card_cache->set_use_cache(use_hot_card_cache);
     assert(JavaThread::dirty_card_queue_set().completed_buffers_num() == 0, "All should be consumed");
   }
 }
--- a/hotspot/src/share/vm/gc/g1/g1RemSet.hpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1RemSet.hpp	Mon May 02 12:07:58 2016 -0400
@@ -38,9 +38,9 @@
 class BitMap;
 class CardTableModRefBS;
 class G1BlockOffsetTable;
-class ConcurrentG1Refine;
 class CodeBlobClosure;
 class G1CollectedHeap;
+class G1HotCardCache;
 class G1ParPushHeapRSClosure;
 class G1RemSetScanState;
 class G1Policy;
@@ -71,8 +71,7 @@
 protected:
   CardTableModRefBS*     _ct_bs;
   G1Policy*              _g1p;
-
-  ConcurrentG1Refine*    _cg1r;
+  G1HotCardCache*        _hot_card_cache;
 
 public:
   // Gives an approximation on how many threads can be expected to add records to
@@ -90,7 +89,9 @@
   // scanned.
   void cleanupHRRS();
 
-  G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs);
+  G1RemSet(G1CollectedHeap* g1,
+           CardTableModRefBS* ct_bs,
+           G1HotCardCache* hot_card_cache);
   ~G1RemSet();
 
   // Invoke "cl->do_oop" on all pointers into the collection set
--- a/hotspot/src/share/vm/gc/g1/g1RemSetSummary.cpp	Mon May 02 17:46:08 2016 +0000
+++ b/hotspot/src/share/vm/gc/g1/g1RemSetSummary.cpp	Mon May 02 12:07:58 2016 -0400
@@ -28,6 +28,7 @@
 #include "gc/g1/g1CollectedHeap.inline.hpp"
 #include "gc/g1/g1RemSet.inline.hpp"
 #include "gc/g1/g1RemSetSummary.hpp"
+#include "gc/g1/g1YoungRemSetSamplingThread.hpp"
 #include "gc/g1/heapRegion.hpp"
 #include "gc/g1/heapRegionRemSet.hpp"
 #include "memory/allocation.inline.hpp"