test/hotspot/jtreg/runtime/appcds/cacheObject/DifferentHeapSizes.java
changeset 51720 b7bfd64e43a6
parent 51491 187c84a5efe1
child 51990 6003e034cdd8
equal deleted inserted replaced
51719:e3411e5e473d 51720:b7bfd64e43a6
    38 import jdk.test.lib.process.OutputAnalyzer;
    38 import jdk.test.lib.process.OutputAnalyzer;
    39 import sun.hotspot.WhiteBox;
    39 import sun.hotspot.WhiteBox;
    40 import jdk.test.lib.cds.CDSTestUtils;
    40 import jdk.test.lib.cds.CDSTestUtils;
    41 
    41 
    42 public class DifferentHeapSizes {
    42 public class DifferentHeapSizes {
       
    43     static final String DEDUP = "-XX:+UseStringDeduplication"; // This increases code coverage.
       
    44 
    43     static class Scenario {
    45     static class Scenario {
    44         int dumpSize;   // in MB
    46         int dumpSize;   // in MB
    45         int runSizes[]; // in MB
    47         int runSizes[]; // in MB
    46         Scenario(int ds, int... rs) {
    48         Scenario(int ds, int... rs) {
    47             dumpSize = ds;
    49             dumpSize = ds;
    57         new Scenario(     17000,         32, 512, 2048, 4097, 8500, 31000,      40000),
    59         new Scenario(     17000,         32, 512, 2048, 4097, 8500, 31000,      40000),
    58         new Scenario(     31000,         32, 512, 2048, 4097, 8500, 17000,      40000)
    60         new Scenario(     31000,         32, 512, 2048, 4097, 8500, 17000,      40000)
    59     };
    61     };
    60 
    62 
    61     public static void main(String[] args) throws Exception {
    63     public static void main(String[] args) throws Exception {
    62         String dedup = "-XX:+UseStringDeduplication"; // This increases code coverage.
       
    63         JarBuilder.getOrCreateHelloJar();
    64         JarBuilder.getOrCreateHelloJar();
    64         String appJar = TestCommon.getTestJar("hello.jar");
    65         String appJar = TestCommon.getTestJar("hello.jar");
    65         String appClasses[] = TestCommon.list("Hello");
    66         String appClasses[] = TestCommon.list("Hello");
    66 
    67 
    67         for (Scenario s : scenarios) {
    68         for (Scenario s : scenarios) {
    69             OutputAnalyzer output = TestCommon.dump(appJar, appClasses, dumpXmx);
    70             OutputAnalyzer output = TestCommon.dump(appJar, appClasses, dumpXmx);
    70 
    71 
    71             for (int runSize : s.runSizes) {
    72             for (int runSize : s.runSizes) {
    72                 String runXmx = "-Xmx" + runSize + "m";
    73                 String runXmx = "-Xmx" + runSize + "m";
    73                 CDSTestUtils.Result result = TestCommon.run("-cp", appJar, "-showversion",
    74                 CDSTestUtils.Result result = TestCommon.run("-cp", appJar, "-showversion",
    74                         "-Xlog:cds", runXmx, dedup, "Hello");
    75                         "-Xlog:cds", runXmx, DEDUP, "Hello");
    75                 if (runSize < 32768) {
    76                 if (runSize < 32768) {
    76                     result
    77                     result
    77                         .assertNormalExit("Hello World")
    78                         .assertNormalExit("Hello World")
    78                         .assertNormalExit(out -> {
    79                         .assertNormalExit(out -> {
    79                             out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP);
    80                             out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP);
    80                             out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE);
    81                             out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE);
    81                         });
    82                         });
    82                 } else {
    83                 } else {
    83                     result.assertAbnormalExit("Unable to use shared archive: UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
    84                     result.assertAbnormalExit(CDSTestUtils.MSG_COMPRESSION_MUST_BE_USED);
    84                 }
    85                 }
    85             }
    86             }
    86         }
    87         }
    87         String flag = "HeapBaseMinAddress";
       
    88         String xxflag = "-XX:" + flag + "=";
       
    89         String mx = "-Xmx128m";
       
    90         long base = WhiteBox.getWhiteBox().getSizeTVMFlag(flag).longValue();
       
    91 
    88 
    92         TestCommon.dump(appJar, appClasses, mx, xxflag + base);
    89         // Test various settings of -XX:HeapBaseMinAddress that would trigger
    93         TestCommon.run("-cp", appJar, "-showversion", "-Xlog:cds", mx, xxflag + (base + 256 * 1024 * 1024), dedup, "Hello")
    90         // "CDS heap data need to be relocated because the desired range ... is outside of the heap"
    94             .assertNormalExit("Hello World")
    91         long default_base = WhiteBox.getWhiteBox().getSizeTVMFlag("HeapBaseMinAddress").longValue();
    95             .assertNormalExit(out -> {
    92         long M = 1024 * 1024;
    96                     out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP);
    93         long bases[] = new long[] {
    97                     out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE);
    94             /* dump xmx */   /* run xmx */   /* dump base */             /* run base */
    98                 });
    95             128 * M,         128 * M,        default_base,               default_base + 256L * 1024 * 1024,
       
    96             128 * M,         16376 * M,      0x0000000119200000L,        -1,
       
    97         };
       
    98 
       
    99         for (int i = 0; i < bases.length; i += 4) {
       
   100             String dump_xmx  = getXmx(bases[i+0]);
       
   101             String run_xmx   = getXmx(bases[i+1]);
       
   102             String dump_base = getHeapBaseMinAddress(bases[i+2]);
       
   103             String run_base  = getHeapBaseMinAddress(bases[i+3]);
       
   104 
       
   105             TestCommon.dump(appJar, appClasses, dump_xmx, dump_base);
       
   106             TestCommon.run("-cp", appJar, "-showversion", "-Xlog:cds", run_xmx, run_base, DEDUP, "Hello")
       
   107                 .assertNormalExit("Hello World")
       
   108                 .assertNormalExit(out -> {
       
   109                         out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP);
       
   110                         out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE);
       
   111                     });
       
   112         }
       
   113     }
       
   114 
       
   115     static String getXmx(long value) {
       
   116         if (value < 0) {
       
   117             return "-showversion"; // This is a harmless command line arg
       
   118         } else {
       
   119             return "-Xmx" + (value / 1024 / 1024) + "m";
       
   120         }
       
   121     }
       
   122     static String getHeapBaseMinAddress(long value) {
       
   123         if (value < 0) {
       
   124             return "-showversion"; // This is a harmless command line arg
       
   125         } else {
       
   126             return "-XX:HeapBaseMinAddress=0x" + Long.toHexString(value);
       
   127         }
    99     }
   128     }
   100 }
   129 }