hotspot/test/gc/TestSmallHeap.java
changeset 39993 82256382f7a1
parent 38929 1ee62412a66f
child 39997 a65e14a0d827
--- a/hotspot/test/gc/TestSmallHeap.java	Thu Jul 21 14:06:22 2016 +0200
+++ b/hotspot/test/gc/TestSmallHeap.java	Thu Jul 21 17:12:35 2016 +0400
@@ -34,7 +34,7 @@
  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestSmallHeap
  */
 
-/* Note: It would be nice to verify the minimal supported heap size (2m) here,
+/* Note: It would be nice to verify the minimal supported heap size here,
  * but we align the heap size based on the card table size. And the card table
  * size is aligned based on the minimal pages size provided by the os. This
  * means that on most platforms, where the minimal page size is 4k, we get a
@@ -43,14 +43,18 @@
  * we get a minimal heap size of 32m. We never use large pages for the card table.
  *
  * There is also no check in the VM for verifying that the maximum heap size
- * is larger than the supported minimal heap size. This means that specifying
- * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m or 32m).
+ * is larger than the supported minimal heap size.
  *
- * To work around these rather strange behaviors this test uses -Xmx2m but then
+ * To work around these behaviors this test uses -Xmx4m but then
  * calculates what the expected heap size should be. The calculation is a
  * simplified version of the code in the VM. We assume that the card table will
  * use one page. Each byte in the card table corresponds to 512 bytes on the heap.
  * So, the expected heap size is page_size * 512.
+ *
+ * There is no formal requirement for the minimal value of the maximum heap size
+ * the VM should support. In most cases the VM could start with -Xmx2m.
+ * But with 2m limit GC could be triggered before VM initialization completed.
+ * Therefore we start the VM with 4M heap.
  */
 
 import jdk.test.lib.Asserts;
@@ -79,9 +83,10 @@
     }
 
     private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
+        long minMaxHeap = 4 * 1024 * 1024;
         LinkedList<String> vmOptions = new LinkedList<>();
         vmOptions.add(gc);
-        vmOptions.add("-Xmx2m");
+        vmOptions.add("-Xmx" + minMaxHeap);
         vmOptions.add("-XX:+PrintFlagsFinal");
         vmOptions.add(VerifyHeapSize.class.getName());
 
@@ -89,6 +94,7 @@
         OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
         analyzer.shouldHaveExitValue(0);
 
+        expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap);
         long maxHeapSize = Long.parseLong(analyzer.firstMatch("MaxHeapSize.+=\\s+(\\d+)",1));
         long actualHeapSize = Long.parseLong(analyzer.firstMatch(VerifyHeapSize.actualMsg + "(\\d+)",1));
         Asserts.assertEQ(maxHeapSize, expectedMaxHeap);