< prev index next >

test/gc/g1/TestLargePageUseForAuxMemory.java

Print this page
rev 8368 : imported patch 8079208-TestLargePageUseForAuxMemory.java-failing-on-windows

@@ -22,29 +22,32 @@
  */
 
 /*
  * @test TestLargePageUseForAuxMemory.java
  * @summary Test that auxiliary data structures are allocated using large pages if available.
- * @bug 8058354
+ * @bug 8058354 8079208
  * @key gc
  * @library /testlibrary /../../test/lib
  * @requires (vm.gc=="G1" | vm.gc=="null")
  * @build jdk.test.lib.* sun.hotspot.WhiteBox
  * @build TestLargePageUseForAuxMemory
- * @ignore 8079208
  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory
  */
 
+import java.lang.Math;
+
 import jdk.test.lib.*;
+import jdk.test.lib.Asserts;
 import sun.hotspot.WhiteBox;
 
 public class TestLargePageUseForAuxMemory {
-    static final int HEAP_REGION_SIZE = 4 * 1024 * 1024;
+    static final long HEAP_REGION_SIZE = 1 * 1024 * 1024;
     static long largePageSize;
     static long smallPageSize;
+    static long allocGranularity;
 
     static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception {
         output.shouldContain("G1 'Block offset table': pg_sz=" + expectedPageSize);
         output.shouldContain("G1 'Card counts table': pg_sz=" + expectedPageSize);
     }

@@ -52,20 +55,21 @@
     static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception {
         output.shouldContain("G1 'Prev Bitmap': pg_sz=" + expectedPageSize);
         output.shouldContain("G1 'Next Bitmap': pg_sz=" + expectedPageSize);
     }
 
-    static void testVM(long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {
+    static void testVM(String what, long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {
+        System.out.println(what);
         ProcessBuilder pb;
         // Test with large page enabled.
         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
-                                                   "-Xms" + 10 * HEAP_REGION_SIZE,
+                                                   "-Xms" + heapsize,
                                                    "-Xmx" + heapsize,
                                                    "-XX:+TracePageSizes",
                                                    "-XX:+UseLargePages",
-                                                   "-XX:+IgnoreUnrecognizedVMOptions",  // there is on ObjectAlignmentInBytes in 32 bit builds
+                                                   "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
                                                    "-XX:ObjectAlignmentInBytes=8",
                                                    "-version");
 
         OutputAnalyzer output = new OutputAnalyzer(pb.start());
         checkSmallTables(output, (cardsShouldUseLargePages ? largePageSize : smallPageSize));

@@ -73,15 +77,15 @@
         output.shouldHaveExitValue(0);
 
         // Test with large page disabled.
         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
-                                                   "-Xms" + 10 * HEAP_REGION_SIZE,
+                                                   "-Xms" + heapsize,
                                                    "-Xmx" + heapsize,
                                                    "-XX:+TracePageSizes",
                                                    "-XX:-UseLargePages",
-                                                   "-XX:+IgnoreUnrecognizedVMOptions",  // there is on ObjectAlignmentInBytes in 32 bit builds
+                                                   "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
                                                    "-XX:ObjectAlignmentInBytes=8",
                                                    "-version");
 
         output = new OutputAnalyzer(pb.start());
         checkSmallTables(output, smallPageSize);

@@ -96,10 +100,11 @@
         }
 
         WhiteBox wb = WhiteBox.getWhiteBox();
         smallPageSize = wb.getVMPageSize();
         largePageSize = wb.getVMLargePageSize();
+        allocGranularity = wb.getVMAllocationGranularity();
 
         if (largePageSize == 0) {
             System.out.println("Skip tests because large page support does not seem to be available on this platform.");
             return;
         }

@@ -110,22 +115,28 @@
         if (!Platform.is32bit()) {
             // Size that a single card covers.
             final int cardSize = 512;
 
             final long heapSizeForCardTableUsingLargePages = largePageSize * cardSize;
+            final long heapSizeDiffForCardTable = Math.max(Math.max(allocGranularity * cardSize, HEAP_REGION_SIZE), largePageSize);
 
-            testVM(heapSizeForCardTableUsingLargePages, true, true);
-            testVM(heapSizeForCardTableUsingLargePages + HEAP_REGION_SIZE, true, true);
-            testVM(heapSizeForCardTableUsingLargePages - HEAP_REGION_SIZE, false, true);
+            Asserts.assertGT(heapSizeForCardTableUsingLargePages, heapSizeDiffForCardTable,
+                             "To test we would require to use an invalid heap size");
+            testVM("case1: card table and bitmap use large pages (barely)", heapSizeForCardTableUsingLargePages, true, true);
+            testVM("case2: card table and bitmap use large pages (extra slack)", heapSizeForCardTableUsingLargePages + heapSizeDiffForCardTable, true, true);
+            testVM("case3: only bitmap uses large pages (barely not)", heapSizeForCardTableUsingLargePages - heapSizeDiffForCardTable, false, true);
         }
 
         // Minimum heap requirement to get large pages for bitmaps is 128M heap. This seems okay to test
         // everywhere.
         final int bitmapTranslationFactor = 8 * 8; // ObjectAlignmentInBytes * BitsPerByte
         final long heapSizeForBitmapUsingLargePages = largePageSize * bitmapTranslationFactor;
+        final long heapSizeDiffForBitmap = Math.max(Math.max(allocGranularity * bitmapTranslationFactor, HEAP_REGION_SIZE), largePageSize);
+
+        Asserts.assertGT(heapSizeForBitmapUsingLargePages, heapSizeDiffForBitmap,
+                         "To test we would require to use an invalid heap size");
 
-        testVM(heapSizeForBitmapUsingLargePages, false, true);
-        testVM(heapSizeForBitmapUsingLargePages + HEAP_REGION_SIZE, false, true);
-        testVM(heapSizeForBitmapUsingLargePages - HEAP_REGION_SIZE, false, false);
+        testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
+        testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
+        testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
     }
 }
-
< prev index next >