8043639: Backout JDK-8034852: Shrinking of Metaspace high-water-mark causes incorrect OutOfMemoryErrors or back-to-back GCs
authorehelin
Wed, 21 May 2014 16:11:04 +0200
changeset 24474 32fc2affe592
parent 24473 1227042cdc67
child 24475 89309db99b3d
8043639: Backout JDK-8034852: Shrinking of Metaspace high-water-mark causes incorrect OutOfMemoryErrors or back-to-back GCs Reviewed-by: stefank, tschatzl
hotspot/src/share/vm/memory/metaspace.cpp
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Tue May 20 18:25:14 2014 +0400
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Wed May 21 16:11:04 2014 +0200
@@ -1433,9 +1433,10 @@
   }
 
   size_t capacity_until_gc = capacity_until_GC();
-  assert(capacity_until_gc >= committed_bytes,
-         err_msg("capacity_until_gc: " SIZE_FORMAT " < committed_bytes: " SIZE_FORMAT,
-                 capacity_until_gc, committed_bytes));
+
+  if (capacity_until_gc <= committed_bytes) {
+    return 0;
+  }
 
   size_t left_until_GC = capacity_until_gc - committed_bytes;
   size_t left_to_commit = MIN2(left_until_GC, left_until_max);
@@ -1448,15 +1449,7 @@
   uint current_shrink_factor = _shrink_factor;
   _shrink_factor = 0;
 
-  // Using committed_bytes() for used_after_gc is an overestimation, since the
-  // chunk free lists are included in committed_bytes() and the memory in an
-  // un-fragmented chunk free list is available for future allocations.
-  // However, if the chunk free lists becomes fragmented, then the memory may
-  // not be available for future allocations and the memory is therefore "in use".
-  // Including the chunk free lists in the definition of "in use" is therefore
-  // necessary. Not including the chunk free lists can cause capacity_until_GC to
-  // shrink below committed_bytes() and this has caused serious bugs in the past.
-  const size_t used_after_gc = MetaspaceAux::committed_bytes();
+  const size_t used_after_gc = MetaspaceAux::capacity_bytes();
   const size_t capacity_until_GC = MetaspaceGC::capacity_until_GC();
 
   const double minimum_free_percentage = MinMetaspaceFreeRatio / 100.0;