8209346: Refactor SATBMarkQueue filter configuration
authorkbarrett
Tue, 14 Aug 2018 13:16:26 -0400
changeset 51401 58113ce90caf
parent 51400 937fd6b81aaf
child 51402 bfdebb29b1e5
8209346: Refactor SATBMarkQueue filter configuration Summary: Moved reference to G1-specific option to G1CollectedHeap. Reviewed-by: shade, rkennke
src/hotspot/share/gc/g1/g1CollectedHeap.cpp
src/hotspot/share/gc/g1/g1SATBMarkQueueSet.cpp
src/hotspot/share/gc/g1/g1SATBMarkQueueSet.hpp
src/hotspot/share/gc/g1/satbMarkQueue.cpp
src/hotspot/share/gc/g1/satbMarkQueue.hpp
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Tue Aug 14 10:08:21 2018 -0700
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Tue Aug 14 13:16:26 2018 -0400
@@ -1691,6 +1691,7 @@
                                                  SATB_Q_CBL_mon,
                                                  SATB_Q_FL_lock,
                                                  G1SATBProcessCompletedThreshold,
+                                                 G1SATBBufferEnqueueingThresholdPercent,
                                                  Shared_SATB_Q_lock);
 
   jint ecode = initialize_concurrent_refinement();
--- a/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.cpp	Tue Aug 14 10:08:21 2018 -0700
+++ b/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.cpp	Tue Aug 14 13:16:26 2018 -0400
@@ -37,8 +37,12 @@
 void G1SATBMarkQueueSet::initialize(G1CollectedHeap* g1h,
                                     Monitor* cbl_mon, Mutex* fl_lock,
                                     int process_completed_threshold,
+                                    uint buffer_enqueue_threshold_percentage,
                                     Mutex* lock) {
-  SATBMarkQueueSet::initialize(cbl_mon, fl_lock, process_completed_threshold, lock);
+  SATBMarkQueueSet::initialize(cbl_mon, fl_lock,
+                               process_completed_threshold,
+                               buffer_enqueue_threshold_percentage,
+                               lock);
   _g1h = g1h;
 }
 
--- a/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.hpp	Tue Aug 14 10:08:21 2018 -0700
+++ b/src/hotspot/share/gc/g1/g1SATBMarkQueueSet.hpp	Tue Aug 14 13:16:26 2018 -0400
@@ -39,6 +39,7 @@
   void initialize(G1CollectedHeap* g1h,
                   Monitor* cbl_mon, Mutex* fl_lock,
                   int process_completed_threshold,
+                  uint buffer_enqueue_threshold_percentage,
                   Mutex* lock);
 
   static void handle_zero_index_for_thread(JavaThread* t);
--- a/src/hotspot/share/gc/g1/satbMarkQueue.cpp	Tue Aug 14 10:08:21 2018 -0700
+++ b/src/hotspot/share/gc/g1/satbMarkQueue.cpp	Tue Aug 14 13:16:26 2018 -0400
@@ -40,7 +40,8 @@
   // them with their active field set to false. If a thread is
   // created during a cycle and its SATB queue needs to be activated
   // before the thread starts running, we'll need to set its active
-  // field to true. This is done in G1SBarrierSet::on_thread_attach().
+  // field to true. This must be done in the collector-specific
+  // BarrierSet::on_thread_attach() implementation.
   PtrQueue(qset, permanent, false /* active */)
 { }
 
@@ -59,8 +60,6 @@
   assert(_lock == NULL || _lock->owned_by_self(),
          "we should have taken the lock before calling this");
 
-  // If G1SATBBufferEnqueueingThresholdPercent == 0 we could skip filtering.
-
   // This method should only be called if there is a non-NULL buffer
   // that is full.
   assert(index() == 0, "pre-condition");
@@ -68,10 +67,15 @@
 
   filter();
 
-  size_t cap = capacity();
-  size_t percent_used = ((cap - index()) * 100) / cap;
-  bool should_enqueue = percent_used > G1SATBBufferEnqueueingThresholdPercent;
-  return should_enqueue;
+  SATBMarkQueueSet* satb_qset = static_cast<SATBMarkQueueSet*>(qset());
+  size_t threshold = satb_qset->buffer_enqueue_threshold();
+  // Ensure we'll enqueue completely full buffers.
+  assert(threshold > 0, "enqueue threshold = 0");
+  // Ensure we won't enqueue empty buffers.
+  assert(threshold <= capacity(),
+         "enqueue threshold " SIZE_FORMAT " exceeds capacity " SIZE_FORMAT,
+         threshold, capacity());
+  return index() < threshold;
 }
 
 void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) {
@@ -103,14 +107,21 @@
 
 SATBMarkQueueSet::SATBMarkQueueSet() :
   PtrQueueSet(),
-  _shared_satb_queue(this, true /* permanent */)
+  _shared_satb_queue(this, true /* permanent */),
+  _buffer_enqueue_threshold(0)
 {}
 
 void SATBMarkQueueSet::initialize(Monitor* cbl_mon, Mutex* fl_lock,
                                   int process_completed_threshold,
+                                  uint buffer_enqueue_threshold_percentage,
                                   Mutex* lock) {
   PtrQueueSet::initialize(cbl_mon, fl_lock, process_completed_threshold, -1);
   _shared_satb_queue.set_lock(lock);
+  assert(buffer_size() != 0, "buffer size not initialized");
+  // Minimum threshold of 1 ensures enqueuing of completely full buffers.
+  size_t size = buffer_size();
+  size_t enqueue_qty = (size * buffer_enqueue_threshold_percentage) / 100;
+  _buffer_enqueue_threshold = MAX2(size - enqueue_qty, (size_t)1);
 }
 
 #ifdef ASSERT
--- a/src/hotspot/share/gc/g1/satbMarkQueue.hpp	Tue Aug 14 10:08:21 2018 -0700
+++ b/src/hotspot/share/gc/g1/satbMarkQueue.hpp	Tue Aug 14 13:16:26 2018 -0400
@@ -92,6 +92,7 @@
 
 class SATBMarkQueueSet: public PtrQueueSet {
   SATBMarkQueue _shared_satb_queue;
+  size_t _buffer_enqueue_threshold;
 
 #ifdef ASSERT
   void dump_active_states(bool expected_active);
@@ -109,6 +110,7 @@
 
   void initialize(Monitor* cbl_mon, Mutex* fl_lock,
                   int process_completed_threshold,
+                  uint buffer_enqueue_threshold_percentage,
                   Mutex* lock);
 
 public:
@@ -120,6 +122,7 @@
   // set itself, has an active value same as expected_active.
   void set_active_all_threads(bool active, bool expected_active);
 
+  size_t buffer_enqueue_threshold() const { return _buffer_enqueue_threshold; }
   virtual void filter(SATBMarkQueue* queue) = 0;
 
   // Filter all the currently-active SATB buffers.