< prev index next >

test/hotspot/jtreg/runtime/appcds/dynamicArchive/NoClassToArchive.java

Print this page




  44     static final String appClass = "StrConcatApp";
  45 
  46     public static void main(String[] args) throws Exception {
  47         runTest(NoClassToArchive::testDefaultBase);
  48         runTest(NoClassToArchive::testCustomBase);
  49     }
  50 
  51     // (1) Test with default base archive + top archive
  52     static void testDefaultBase() throws Exception {
  53         String topArchiveName = getNewArchiveName("top");
  54         doTest(null, topArchiveName);
  55     }
  56 
  57     // (2) Test with custom base archive + top archive
  58     static void testCustomBase() throws Exception {
  59         String topArchiveName = getNewArchiveName("top2");
  60         String baseArchiveName = getNewArchiveName("base");
  61         doTestCustomBase(baseArchiveName, topArchiveName);
  62     }
  63 
  64     private static void checkWarning(OutputAnalyzer output) throws Exception {
  65         if (output.getStdout().contains("jrt:/") || output.getStdout().contains("unsafe anonymous")) {
  66             System.out.println("test skipped: this platform uses non-archived classes when running -version");
  67         } else {
  68             output.shouldContain(warningMessage);
  69         }
  70     }
  71 
  72     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
  73         dump2(baseArchiveName, topArchiveName,
  74              "-Xlog:cds",
  75              "-Xlog:cds+dynamic=debug",
  76              "-Xlog:class+load=trace",
  77              "-version")
  78             .assertNormalExit(output -> checkWarning(output));






  79 
  80         dump2(baseArchiveName, topArchiveName,
  81              "-Xlog:cds",
  82              "-Xlog:cds+dynamic=debug",
  83              "-Xlog:class+load=trace",
  84              "-help")
  85             .assertNormalExit(output -> {
  86                     // some classes will be loaded from the java.base module
  87                     output.shouldContain("java.text.MessageFormat source: jrt:/java.base");
  88                 });
  89     }
  90 
  91     private static void doTestCustomBase(String baseArchiveName, String topArchiveName) throws Exception {
  92         String appJar = ClassFileInstaller.getJarPath("strConcatApp.jar");
  93         // dump class list by running the StrConcatApp
  94         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  95             true,
  96             "-XX:DumpLoadedClassList=" + classList,
  97             "-cp",
  98             appJar,
  99             appClass);
 100         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dumpClassList");
 101         TestCommon.checkExecReturn(output, 0, true, "length = 0");
 102 
 103         // create a custom base archive based on the class list
 104         dumpBaseArchive(baseArchiveName, "-XX:SharedClassListFile=" + classList);
 105 
 106         // create a dynamic archive with the custom base archive
 107         // no class should be included in the dynamic archive
 108         dump2(baseArchiveName, topArchiveName,
 109               "-Xlog:cds",
 110               "-Xlog:cds+dynamic=debug",
 111               "-Xlog:class+load=trace",
 112               "-version")
 113             .assertNormalExit(out -> checkWarning(out));
 114     }
 115 }


  44     static final String appClass = "StrConcatApp";
  45 
  46     public static void main(String[] args) throws Exception {
  47         runTest(NoClassToArchive::testDefaultBase);
  48         runTest(NoClassToArchive::testCustomBase);
  49     }
  50 
  51     // (1) Test with default base archive + top archive
  52     static void testDefaultBase() throws Exception {
  53         String topArchiveName = getNewArchiveName("top");
  54         doTest(null, topArchiveName);
  55     }
  56 
  57     // (2) Test with custom base archive + top archive
  58     static void testCustomBase() throws Exception {
  59         String topArchiveName = getNewArchiveName("top2");
  60         String baseArchiveName = getNewArchiveName("base");
  61         doTestCustomBase(baseArchiveName, topArchiveName);
  62     }
  63 








  64     private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
  65         dump2(baseArchiveName, topArchiveName,
  66              "-Xlog:cds",
  67              "-Xlog:cds+dynamic=debug",
  68              "-Xlog:class+load=trace",
  69              "-version")
  70             .assertNormalExit(output -> {
  71                     if (output.getStdout().contains("jrt:/")) {
  72                         System.out.println("test skipped: this platform uses non-archived classes when running -version");
  73                     } else {
  74                         output.shouldContain(warningMessage);
  75                     }
  76                 });
  77 
  78         dump2(baseArchiveName, topArchiveName,
  79              "-Xlog:cds",
  80              "-Xlog:cds+dynamic=debug",
  81              "-Xlog:class+load=trace",
  82              "-help")
  83             .assertNormalExit(output -> {
  84                     // some classes will be loaded from the java.base module
  85                     output.shouldContain("java.text.MessageFormat source: jrt:/java.base");
  86                 });
  87     }
  88 
  89     private static void doTestCustomBase(String baseArchiveName, String topArchiveName) throws Exception {
  90         String appJar = ClassFileInstaller.getJarPath("strConcatApp.jar");
  91         // dump class list by running the StrConcatApp
  92         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  93             true,
  94             "-XX:DumpLoadedClassList=" + classList,
  95             "-cp",
  96             appJar,
  97             appClass);
  98         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dumpClassList");
  99         TestCommon.checkExecReturn(output, 0, true, "length = 0");
 100 
 101         // create a custom base archive based on the class list
 102         dumpBaseArchive(baseArchiveName, "-XX:SharedClassListFile=" + classList);
 103 
 104         // create a dynamic archive with the custom base archive
 105         // no class should be included in the dynamic archive
 106         dump2(baseArchiveName, topArchiveName, "-version")
 107             .assertNormalExit(out -> {
 108                     out.shouldMatch(warningMessage);
 109                 });


 110     }
 111 }
< prev index next >