hotspot/test/gc/g1/TestLargePageUseForAuxMemory.java
changeset 37462 58bb9394a98b
parent 33806 4160a3c28ce8
child 38152 80e5da81fb2c
equal deleted inserted replaced
37461:b5c955296b75 37462:58bb9394a98b
    34  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
    34  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
    35  * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory
    35  * @run main/othervm -Xbootclasspath/a:. -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+IgnoreUnrecognizedVMOptions -XX:+UseLargePages TestLargePageUseForAuxMemory
    36  */
    36  */
    37 
    37 
    38 import java.lang.Math;
    38 import java.lang.Math;
       
    39 import java.lang.reflect.InvocationTargetException;
       
    40 import java.lang.reflect.Method;
    39 
    41 
    40 import jdk.test.lib.*;
    42 import jdk.test.lib.*;
    41 import jdk.test.lib.Asserts;
    43 import jdk.test.lib.Asserts;
    42 import sun.hotspot.WhiteBox;
    44 import sun.hotspot.WhiteBox;
    43 
    45 
    45     static final long HEAP_REGION_SIZE = 1 * 1024 * 1024;
    47     static final long HEAP_REGION_SIZE = 1 * 1024 * 1024;
    46     static long largePageSize;
    48     static long largePageSize;
    47     static long smallPageSize;
    49     static long smallPageSize;
    48     static long allocGranularity;
    50     static long allocGranularity;
    49 
    51 
       
    52     static void checkSize(OutputAnalyzer output, long expectedSize, String pattern) {
       
    53         String pageSizeStr = output.firstMatch(pattern, 1);
       
    54 
       
    55         if (pageSizeStr == null) {
       
    56             output.reportDiagnosticSummary();
       
    57             throw new RuntimeException("Match from '" + pattern + "' got 'null' expected: " + expectedSize);
       
    58         }
       
    59 
       
    60         long size = parseMemoryString(pageSizeStr);
       
    61         if (size != expectedSize) {
       
    62             output.reportDiagnosticSummary();
       
    63             throw new RuntimeException("Match from '" + pattern + "' got " + size + " expected: " + expectedSize);
       
    64         }
       
    65     }
       
    66 
    50     static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception {
    67     static void checkSmallTables(OutputAnalyzer output, long expectedPageSize) throws Exception {
    51         output.shouldContain("G1 'Block offset table': pg_sz=" + expectedPageSize);
    68         checkSize(output, expectedPageSize, "Block Offset Table: .*page_size=([^ ]+)");
    52         output.shouldContain("G1 'Card counts table': pg_sz=" + expectedPageSize);
    69         checkSize(output, expectedPageSize, "Card Counts Table: .*page_size=([^ ]+)");
    53     }
    70     }
    54 
    71 
    55     static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception {
    72     static void checkBitmaps(OutputAnalyzer output, long expectedPageSize) throws Exception {
    56         output.shouldContain("G1 'Prev Bitmap': pg_sz=" + expectedPageSize);
    73         checkSize(output, expectedPageSize, "Prev Bitmap: .*page_size=([^ ]+)");
    57         output.shouldContain("G1 'Next Bitmap': pg_sz=" + expectedPageSize);
    74         checkSize(output, expectedPageSize, "Next Bitmap: .*page_size=([^ ]+)");
    58     }
    75     }
    59 
    76 
    60     static void testVM(String what, long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {
    77     static void testVM(String what, long heapsize, boolean cardsShouldUseLargePages, boolean bitmapShouldUseLargePages) throws Exception {
    61         System.out.println(what + " heapsize " + heapsize + " card table should use large pages " + cardsShouldUseLargePages + " " +
    78         System.out.println(what + " heapsize " + heapsize + " card table should use large pages " + cardsShouldUseLargePages + " " +
    62                            "bitmaps should use large pages " + bitmapShouldUseLargePages);
    79                            "bitmaps should use large pages " + bitmapShouldUseLargePages);
    64         // Test with large page enabled.
    81         // Test with large page enabled.
    65         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    82         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    66                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
    83                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
    67                                                    "-Xms" + heapsize,
    84                                                    "-Xms" + heapsize,
    68                                                    "-Xmx" + heapsize,
    85                                                    "-Xmx" + heapsize,
    69                                                    "-XX:+TracePageSizes",
    86                                                    "-Xlog:pagesize",
    70                                                    "-XX:+UseLargePages",
    87                                                    "-XX:+UseLargePages",
    71                                                    "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
    88                                                    "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
    72                                                    "-XX:ObjectAlignmentInBytes=8",
    89                                                    "-XX:ObjectAlignmentInBytes=8",
    73                                                    "-version");
    90                                                    "-version");
    74 
    91 
    80         // Test with large page disabled.
    97         // Test with large page disabled.
    81         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    98         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
    82                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
    99                                                    "-XX:G1HeapRegionSize=" + HEAP_REGION_SIZE,
    83                                                    "-Xms" + heapsize,
   100                                                    "-Xms" + heapsize,
    84                                                    "-Xmx" + heapsize,
   101                                                    "-Xmx" + heapsize,
    85                                                    "-XX:+TracePageSizes",
   102                                                    "-Xlog:pagesize",
    86                                                    "-XX:-UseLargePages",
   103                                                    "-XX:-UseLargePages",
    87                                                    "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
   104                                                    "-XX:+IgnoreUnrecognizedVMOptions",  // there is no ObjectAlignmentInBytes in 32 bit builds
    88                                                    "-XX:ObjectAlignmentInBytes=8",
   105                                                    "-XX:ObjectAlignmentInBytes=8",
    89                                                    "-version");
   106                                                    "-version");
    90 
   107 
   106     private static long lcm(long x, long y) {
   123     private static long lcm(long x, long y) {
   107         return x * (y / gcd(x, y));
   124         return x * (y / gcd(x, y));
   108     }
   125     }
   109 
   126 
   110     public static void main(String[] args) throws Exception {
   127     public static void main(String[] args) throws Exception {
   111         if (!Platform.isDebugBuild()) {
       
   112             System.out.println("Skip tests on non-debug builds because the required option TracePageSizes is a debug-only option.");
       
   113             return;
       
   114         }
       
   115 
       
   116         // Size that a single card covers.
   128         // Size that a single card covers.
   117         final int cardSize = 512;
   129         final int cardSize = 512;
   118         WhiteBox wb = WhiteBox.getWhiteBox();
   130         WhiteBox wb = WhiteBox.getWhiteBox();
   119         smallPageSize = wb.getVMPageSize();
   131         smallPageSize = wb.getVMPageSize();
   120         largePageSize = wb.getVMLargePageSize();
   132         largePageSize = wb.getVMLargePageSize();
   157 
   169 
   158         testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
   170         testVM("case4: only bitmap uses large pages (barely)", heapSizeForBitmapUsingLargePages, false, true);
   159         testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
   171         testVM("case5: only bitmap uses large pages (extra slack)", heapSizeForBitmapUsingLargePages + heapSizeDiffForBitmap, false, true);
   160         testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
   172         testVM("case6: nothing uses large pages (barely not)", heapSizeForBitmapUsingLargePages - heapSizeDiffForBitmap, false, false);
   161     }
   173     }
       
   174 
       
   175     public static long parseMemoryString(String value) {
       
   176         long multiplier = 1;
       
   177 
       
   178         if (value.endsWith("B")) {
       
   179             multiplier = 1;
       
   180         } else if (value.endsWith("K")) {
       
   181             multiplier = 1024;
       
   182         } else if (value.endsWith("M")) {
       
   183             multiplier = 1024 * 1024;
       
   184         } else if (value.endsWith("G")) {
       
   185             multiplier = 1024 * 1024 * 1024;
       
   186         } else {
       
   187             throw new IllegalArgumentException("Expected memory string '" + value + "'to end with either of: B, K, M, G");
       
   188         }
       
   189 
       
   190         long longValue = Long.parseUnsignedLong(value.substring(0, value.length() - 1));
       
   191 
       
   192         return longValue * multiplier;
       
   193     }
   162 }
   194 }