8138684: G1 decision about taking regions into the collection set is too aggressive
authortschatzl
Fri, 13 Nov 2015 09:12:06 +0100
changeset 34134 d4fd14f628fb
parent 34133 5d761539ac2c
child 34135 317af749634b
child 34136 7e08409e5935
8138684: G1 decision about taking regions into the collection set is too aggressive Summary: Factor in expected waste and uncertainty of our guess in the decision whether to take another region into the collection set. Reviewed-by: mgerdin, jmasa
hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp	Tue Nov 03 13:03:04 2015 -0800
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp	Fri Nov 13 09:12:06 2015 +0100
@@ -467,8 +467,19 @@
   }
 
   size_t free_bytes = (base_free_regions - young_length) * HeapRegion::GrainBytes;
-  if ((2.0 /* magic */ * _predictor.sigma()) * bytes_to_copy > free_bytes) {
-    // end condition 3: out-of-space (conservatively!)
+
+  // When copying, we will likely need more bytes free than is live in the region.
+  // Add some safety margin to factor in the confidence of our guess, and the
+  // natural expected waste.
+  // (100.0 / G1ConfidencePercent) is a scale factor that expresses the uncertainty
+  // of the calculation: the lower the confidence, the more headroom.
+  // (100 + TargetPLABWastePct) represents the increase in expected bytes during
+  // copying due to anticipated waste in the PLABs.
+  double safety_factor = (100.0 / G1ConfidencePercent) * (100 + TargetPLABWastePct) / 100.0;
+  size_t expected_bytes_to_copy = safety_factor * bytes_to_copy;
+
+  if (expected_bytes_to_copy > free_bytes) {
+    // end condition 3: out-of-space
     return false;
   }