Merge
authorkvn
Wed, 19 Oct 2016 17:53:01 +0000
changeset 42025 6f480cdf6037
parent 42024 f3ee61fe224c (current diff)
parent 42023 766a4229a2dd (diff)
child 42027 b09ba48a3a5d
Merge
--- a/hotspot/test/gc/g1/TestHumongousShrinkHeap.java	Wed Oct 19 10:48:48 2016 -0700
+++ b/hotspot/test/gc/g1/TestHumongousShrinkHeap.java	Wed Oct 19 17:53:01 2016 +0000
@@ -51,23 +51,29 @@
     private static final int REGION_SIZE = 1024 * 1024; // 1M
     private static final int LISTS_COUNT = 10;
     private static final int HUMON_SIZE = Math.round(.9f * REGION_SIZE);
-    private static final long AVAILABLE_MEMORY
-                              = Runtime.getRuntime().freeMemory();
-    private static final int HUMON_COUNT
-                             = (int) ((AVAILABLE_MEMORY / HUMON_SIZE)
-            / LISTS_COUNT);
 
+    private static final long TOTAL_MEMORY = Runtime.getRuntime().totalMemory();
+    private static final long MAX_MEMORY = Runtime.getRuntime().maxMemory();
+
+    private static final int HUMON_COUNT = (int) ((TOTAL_MEMORY / HUMON_SIZE) / LISTS_COUNT);
 
     public static void main(String[] args) {
         if (HUMON_COUNT == 0) {
             System.out.println("Skipped. Heap is too small");
             return;
         }
-        System.out.format("Running with %s max heap size. "
-                + "Will allocate humongous object of %s size %d times.%n",
-                MemoryUsagePrinter.humanReadableByteCount(AVAILABLE_MEMORY, false),
-                MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false),
-                HUMON_COUNT
+
+        if (TOTAL_MEMORY + REGION_SIZE * HUMON_COUNT > MAX_MEMORY) {
+            System.out.println("Skipped. Initial heap size is to close to max heap size.");
+            return;
+        }
+
+        System.out.format("Running with %s initial heap size of %s maximum heap size. "
+                          + "Will allocate humongous object of %s size %d times.%n",
+                          MemoryUsagePrinter.humanReadableByteCount(TOTAL_MEMORY, false),
+                          MemoryUsagePrinter.humanReadableByteCount(MAX_MEMORY, false),
+                          MemoryUsagePrinter.humanReadableByteCount(HUMON_SIZE, false),
+                          HUMON_COUNT
         );
         new TestHumongousShrinkHeap().test();
     }
--- a/hotspot/test/serviceability/tmtools/jstat/GcTest02.java	Wed Oct 19 10:48:48 2016 -0700
+++ b/hotspot/test/serviceability/tmtools/jstat/GcTest02.java	Wed Oct 19 17:53:01 2016 +0000
@@ -31,7 +31,6 @@
  * @modules java.base/jdk.internal.misc
  * @library /test/lib
  * @library ../share
- * @ignore 8155570
  * @run main/othervm -XX:+UsePerfData -Xmx128M -XX:MaxMetaspaceSize=128M GcTest02
  */
 
--- a/hotspot/test/serviceability/tmtools/jstat/utils/GcProvokerImpl.java	Wed Oct 19 10:48:48 2016 -0700
+++ b/hotspot/test/serviceability/tmtools/jstat/utils/GcProvokerImpl.java	Wed Oct 19 17:53:01 2016 +0000
@@ -50,7 +50,7 @@
                 used += memoryChunk;
             } catch (OutOfMemoryError e) {
                 list = null;
-                throw new RuntimeException("Unexpected OOME while eating " + targetUsage + " of heap memory.");
+                throw new RuntimeException("Unexpected OOME '" + e.getMessage() + "' while eating " + targetUsage + " of heap memory.");
             }
         }
         return list;
@@ -73,8 +73,10 @@
 
     @Override
     public void eatMetaspaceAndHeap(float targetMemoryUsagePercent) {
+        // Metaspace should be filled before Java Heap to prevent unexpected OOME
+        // in the Java Heap while filling Metaspace
+        eatenMetaspace = eatMetaspace(targetMemoryUsagePercent);
         eatenMemory = eatHeapMemory(targetMemoryUsagePercent);
-        eatenMetaspace = eatMetaspace(targetMemoryUsagePercent);
     }
 
     private static List<Object> eatMetaspace(float targetUsage) {
@@ -97,7 +99,7 @@
                 list.add(gp.create(0));
             } catch (OutOfMemoryError oome) {
                 list = null;
-                throw new RuntimeException("Unexpected OOME while eating " + targetUsage + " of Metaspace.");
+                throw new RuntimeException("Unexpected OOME '" + oome.getMessage() + "' while eating " + targetUsage + " of Metaspace.");
             }
             MemoryUsage memoryUsage = metaspacePool.getUsage();
             currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax());