src/hotspot/share/gc/shared/referenceProcessor.cpp
changeset 50401 bf7eb61349d2
parent 50277 f84ae8aa5d88
child 50605 7f63c74f0974
--- a/src/hotspot/share/gc/shared/referenceProcessor.cpp	Tue Jun 05 14:55:13 2018 +0200
+++ b/src/hotspot/share/gc/shared/referenceProcessor.cpp	Tue Jun 05 09:15:03 2018 -0400
@@ -592,6 +592,28 @@
   _next_id = 0;
 }
 
+bool ReferenceProcessor::need_balance_queues(DiscoveredList refs_lists[]) {
+  assert(_processing_is_mt, "why balance non-mt processing?");
+  // _num_queues is the processing degree.  Only list entries up to
+  // _num_queues will be processed, so any non-empty lists beyond
+  // that must be redistributed to lists in that range.  Even if not
+  // needed for that, balancing may be desirable to eliminate poor
+  // distribution of references among the lists.
+  if (ParallelRefProcBalancingEnabled) {
+    return true;                // Configuration says do it.
+  } else {
+    // Configuration says don't balance, but if there are non-empty
+    // lists beyond the processing degree, then must ignore the
+    // configuration and balance anyway.
+    for (uint i = _num_queues; i < _max_num_queues; ++i) {
+      if (!refs_lists[i].is_empty()) {
+        return true;            // Must balance despite configuration.
+      }
+    }
+    return false;               // Safe to obey configuration and not balance.
+  }
+}
+
 // Balances reference queues.
 // Move entries from all queues[0, 1, ..., _max_num_q-1] to
 // queues[0, 1, ..., _num_q-1] because only the first _num_q
@@ -690,7 +712,7 @@
 
   phase_times->set_processing_is_mt(mt_processing);
 
-  if (mt_processing && ParallelRefProcBalancingEnabled) {
+  if (mt_processing && need_balance_queues(refs_lists)) {
     RefProcBalanceQueuesTimeTracker tt(phase_times);
     balance_queues(refs_lists);
   }