test/hotspot/jtreg/runtime/appcds/GraalWithLimitedMetaspace.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Sdiff test/hotspot/jtreg/runtime/appcds

test/hotspot/jtreg/runtime/appcds/GraalWithLimitedMetaspace.java

Print this page




  70         dumpArchive();
  71 
  72     }
  73 
  74     public static List<String> toClassNames(String filename) throws IOException {
  75         ArrayList<String> classes = new ArrayList<>();
  76         try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)))) {
  77             for (; ; ) {
  78                 String line = br.readLine();
  79                 if (line == null) {
  80                     break;
  81                 }
  82                 classes.add(line.replaceAll("/", "."));
  83             }
  84         }
  85         return classes;
  86     }
  87 
  88     static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
  89         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
  90           TestCommon.makeCommandLineForAppCDS(
  91             "-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
  92             // trigger JVMCI runtime init so that JVMCI classes will be
  93             // included in the classlist
  94             "-XX:+EagerJVMCI",
  95             "-cp",
  96             TESTJAR,
  97             TESTNAME,
  98             TEST_OUT));
  99 
 100         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dump-loaded-classes")
 101             .shouldHaveExitValue(0)
 102             .shouldContain(TEST_OUT);
 103 
 104         List<String> dumpedClasses = toClassNames(CLASSLIST_FILE);
 105 
 106         for (String clazz : expectedClasses) {
 107             if (!dumpedClasses.contains(clazz)) {
 108                 throw new RuntimeException(clazz + " missing in " +
 109                                            CLASSLIST_FILE);
 110             }
 111         }
 112     }
 113 
 114     static void dumpArchive() throws Exception {
 115         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
 116           TestCommon.makeCommandLineForAppCDS(
 117             "-cp",
 118             TESTJAR,
 119             "-XX:SharedClassListFile=" + CLASSLIST_FILE,
 120             "-XX:SharedArchiveFile=" + ARCHIVE_FILE,
 121             "-Xlog:cds",
 122             "-Xshare:dump",
 123             "-XX:MetaspaceSize=12M",
 124             "-XX:MaxMetaspaceSize=12M"));
 125 
 126         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dump-archive");
 127         int exitValue = output.getExitValue();
 128         if (exitValue == 1) {
 129             output.shouldContain("Failed allocating metaspace object type");
 130         } else if (exitValue == 0) {
 131             output.shouldContain("Loading classes to share");
 132         } else {
 133             throw new RuntimeException("Unexpected exit value " + exitValue);
 134         }
 135     }
 136 }


  70         dumpArchive();
  71 
  72     }
  73 
  74     public static List<String> toClassNames(String filename) throws IOException {
  75         ArrayList<String> classes = new ArrayList<>();
  76         try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename)))) {
  77             for (; ; ) {
  78                 String line = br.readLine();
  79                 if (line == null) {
  80                     break;
  81                 }
  82                 classes.add(line.replaceAll("/", "."));
  83             }
  84         }
  85         return classes;
  86     }
  87 
  88     static void dumpLoadedClasses(String[] expectedClasses) throws Exception {
  89         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,

  90             "-XX:DumpLoadedClassList=" + CLASSLIST_FILE,
  91             // trigger JVMCI runtime init so that JVMCI classes will be
  92             // included in the classlist
  93             "-XX:+EagerJVMCI",
  94             "-cp",
  95             TESTJAR,
  96             TESTNAME,
  97             TEST_OUT);
  98 
  99         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dump-loaded-classes")
 100             .shouldHaveExitValue(0)
 101             .shouldContain(TEST_OUT);
 102 
 103         List<String> dumpedClasses = toClassNames(CLASSLIST_FILE);
 104 
 105         for (String clazz : expectedClasses) {
 106             if (!dumpedClasses.contains(clazz)) {
 107                 throw new RuntimeException(clazz + " missing in " +
 108                                            CLASSLIST_FILE);
 109             }
 110         }
 111     }
 112 
 113     static void dumpArchive() throws Exception {
 114         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,

 115             "-cp",
 116             TESTJAR,
 117             "-XX:SharedClassListFile=" + CLASSLIST_FILE,
 118             "-XX:SharedArchiveFile=" + ARCHIVE_FILE,
 119             "-Xlog:cds",
 120             "-Xshare:dump",
 121             "-XX:MetaspaceSize=12M",
 122             "-XX:MaxMetaspaceSize=12M");
 123 
 124         OutputAnalyzer output = TestCommon.executeAndLog(pb, "dump-archive");
 125         int exitValue = output.getExitValue();
 126         if (exitValue == 1) {
 127             output.shouldContain("Failed allocating metaspace object type");
 128         } else if (exitValue == 0) {
 129             output.shouldContain("Loading classes to share");
 130         } else {
 131             throw new RuntimeException("Unexpected exit value " + exitValue);
 132         }
 133     }
 134 }
test/hotspot/jtreg/runtime/appcds/GraalWithLimitedMetaspace.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File