< prev index next >

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

Print this page


 128 
 129         cmd.add("-Xshare:dump");
 130 
 131         if (opts.archiveName == null)
 132             opts.archiveName = getCurrentArchiveName();
 133 
 134         cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
 135 
 136         if (opts.classList != null) {
 137             File classListFile = makeClassList(opts.classList);
 138             cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath());
 139         }
 140 
 141         for (String s : opts.suffix) cmd.add(s);
 142 
 143         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 144         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 145         return executeAndLog(pb, "dump");
 146     }
 147 









 148 
 149     // Execute JVM using AppCDS archive with specified AppCDSOptions
 150     public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
 151         throws Exception {
 152 
 153         ArrayList<String> cmd = new ArrayList<String>();
 154 
 155         for (String p : opts.prefix) cmd.add(p);
 156 
 157         cmd.add("-Xshare:" + opts.xShareMode);
 158         cmd.add("-showversion");
 159         cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
 160         cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
 161 
 162         if (opts.appJar != null) {
 163             cmd.add("-cp");
 164             cmd.add(opts.appJar);
 165         }
 166 
 167         for (String s : opts.suffix) cmd.add(s);
















 168 
 169         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 170         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 171         return executeAndLog(pb, "exec");
 172     }
 173 
 174 
 175     public static OutputAnalyzer execCommon(String... suffix) throws Exception {
 176         AppCDSOptions opts = (new AppCDSOptions());
 177         opts.addSuffix(suffix);
 178         return runWithArchive(opts);
 179     }
 180 
 181     // This is the new API for running a Java process with CDS enabled.
 182     // See comments in the CDSTestUtils.Result class for how to use this method.
 183     public static Result run(String... suffix) throws Exception {
 184         AppCDSOptions opts = (new AppCDSOptions());
 185         opts.addSuffix(suffix);
 186         return new Result(opts, runWithArchive(opts));
 187     }




 128 
 129         cmd.add("-Xshare:dump");
 130 
 131         if (opts.archiveName == null)
 132             opts.archiveName = getCurrentArchiveName();
 133 
 134         cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
 135 
 136         if (opts.classList != null) {
 137             File classListFile = makeClassList(opts.classList);
 138             cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath());
 139         }
 140 
 141         for (String s : opts.suffix) cmd.add(s);
 142 
 143         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 144         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 145         return executeAndLog(pb, "dump");
 146     }
 147 
 148     // This allows you to run the AppCDS tests with JFR enabled at runtime (though not at
 149     // dump time, as that's uncommon for typical AppCDS users).
 150     //
 151     // To run in this special mode, specify the following in your jtreg command-line
 152     //    -vmoptions:-Dtest.cds.run.with.jfr=true
 153     //
 154     // Some AppCDS tests are not compatible with this mode. See the group
 155     // hotspot_appcds_with_jfr in ../../TEST.ROOT for details.
 156     private static final boolean RUN_WITH_JFR = Boolean.getBoolean("test.cds.run.with.jfr");
 157 
 158     // Execute JVM using AppCDS archive with specified AppCDSOptions
 159     public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
 160         throws Exception {
 161 
 162         ArrayList<String> cmd = new ArrayList<String>();
 163 
 164         for (String p : opts.prefix) cmd.add(p);
 165 
 166         cmd.add("-Xshare:" + opts.xShareMode);
 167         cmd.add("-showversion");
 168         cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
 169         cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
 170 
 171         if (opts.appJar != null) {
 172             cmd.add("-cp");
 173             cmd.add(opts.appJar);
 174         }
 175 
 176         for (String s : opts.suffix) cmd.add(s);
 177 
 178         if (RUN_WITH_JFR) {
 179             boolean usesJFR = false;
 180             for (String s : cmd) {
 181                 if (s.startsWith("-XX:StartFlightRecording=") || s.startsWith("-XX:FlightRecorderOptions")) {
 182                     System.out.println("JFR option might have been specified. Don't interfere: " + s);
 183                     usesJFR = true;
 184                     break;
 185                 }
 186             }
 187             if (!usesJFR) {
 188                 System.out.println("JFR option not specified. Enabling JFR ...");
 189                 cmd.add(0, "-XX:StartFlightRecording=dumponexit=true");
 190                 System.out.println(cmd);
 191             }
 192         }
 193 
 194         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
 195         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
 196         return executeAndLog(pb, "exec");
 197     }
 198 
 199 
 200     public static OutputAnalyzer execCommon(String... suffix) throws Exception {
 201         AppCDSOptions opts = (new AppCDSOptions());
 202         opts.addSuffix(suffix);
 203         return runWithArchive(opts);
 204     }
 205 
 206     // This is the new API for running a Java process with CDS enabled.
 207     // See comments in the CDSTestUtils.Result class for how to use this method.
 208     public static Result run(String... suffix) throws Exception {
 209         AppCDSOptions opts = (new AppCDSOptions());
 210         opts.addSuffix(suffix);
 211         return new Result(opts, runWithArchive(opts));
 212     }


< prev index next >