< prev index next >

test/lib/jdk/test/lib/cds/CDSTestUtils.java

Print this page

269 
270         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
271         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(cmdLine);
272         return executeAndLog(pb, "dump");
273     }
274 
275     public static boolean isDynamicArchive() {
276         return DYNAMIC_DUMP;
277     }
278 
279     // check result of 'dump-the-archive' operation, that is "-Xshare:dump"
280     public static OutputAnalyzer checkDump(OutputAnalyzer output, String... extraMatches)
281         throws Exception {
282 
283         if (!DYNAMIC_DUMP) {
284             output.shouldContain("Loading classes to share");
285         } else {
286             output.shouldContain("Written dynamic archive 0x");
287         }
288         output.shouldHaveExitValue(0);
289         output.shouldNotContain(MSG_STATIC_FIELD_MAY_HOLD_DIFFERENT_VALUE);
290 
291         for (String match : extraMatches) {
292             output.shouldContain(match);
293         }
294 
295         return output;
296     }
297 
298     // check result of dumping base archive
299     public static OutputAnalyzer checkBaseDump(OutputAnalyzer output) throws Exception {
300         output.shouldContain("Loading classes to share");
301         output.shouldHaveExitValue(0);
302         output.shouldNotContain(MSG_STATIC_FIELD_MAY_HOLD_DIFFERENT_VALUE);
303         return output;
304     }
305 
306     // A commonly used convenience methods to create an archive and check the results
307     // Creates an archive and checks for errors
308     public static OutputAnalyzer createArchiveAndCheck(CDSOptions opts)
309         throws Exception {
310         return checkDump(createArchive(opts));
311     }
312 
313 
314     public static OutputAnalyzer createArchiveAndCheck(String... cliPrefix)
315         throws Exception {
316         return checkDump(createArchive(cliPrefix));
317     }
318 
319 
320     // This method should be used to check the output of child VM for common exceptions.
321     // Most of CDS tests deal with child VM processes for creating and using the archive.
322     // However exceptions that occur in the child process do not automatically propagate

423     // tests to make sure the archived heap objects are mapped/loaded properly.
424     public static void addVerifyArchivedFields(ArrayList<String> cmd) {
425         cmd.add("-XX:+UnlockDiagnosticVMOptions");
426         cmd.add("-XX:VerifyArchivedFields=1");
427     }
428 
429     // Execute JVM with CDS archive, specify CDSOptions
430     public static OutputAnalyzer runWithArchive(CDSOptions opts)
431         throws Exception {
432 
433         ArrayList<String> cmd = new ArrayList<String>();
434         cmd.addAll(opts.prefix);
435         cmd.add("-Xshare:" + opts.xShareMode);
436         cmd.add("-Dtest.timeout.factor=" + TestTimeoutFactor);
437 
438         if (!opts.useSystemArchive) {
439             if (opts.archiveName == null)
440                 opts.archiveName = getDefaultArchiveName();
441             cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
442         }
443         addVerifyArchivedFields(cmd);


444 
445         if (opts.useVersion)
446             cmd.add("-version");
447 
448         for (String s : opts.suffix) cmd.add(s);
449 
450         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
451         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(cmdLine);
452         return executeAndLog(pb, "exec");
453     }
454 
455 
456     // A commonly used convenience methods to create an archive and check the results
457     // Creates an archive and checks for errors
458     public static OutputAnalyzer runWithArchiveAndCheck(CDSOptions opts) throws Exception {
459         return checkExec(runWithArchive(opts));
460     }
461 
462 
463     public static OutputAnalyzer runWithArchiveAndCheck(String... cliPrefix) throws Exception {

269 
270         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
271         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(cmdLine);
272         return executeAndLog(pb, "dump");
273     }
274 
275     public static boolean isDynamicArchive() {
276         return DYNAMIC_DUMP;
277     }
278 
279     // check result of 'dump-the-archive' operation, that is "-Xshare:dump"
280     public static OutputAnalyzer checkDump(OutputAnalyzer output, String... extraMatches)
281         throws Exception {
282 
283         if (!DYNAMIC_DUMP) {
284             output.shouldContain("Loading classes to share");
285         } else {
286             output.shouldContain("Written dynamic archive 0x");
287         }
288         output.shouldHaveExitValue(0);
289         //output.shouldNotContain(MSG_STATIC_FIELD_MAY_HOLD_DIFFERENT_VALUE); // FIXME -- leyden+JEP483 merge
290 
291         for (String match : extraMatches) {
292             output.shouldContain(match);
293         }
294 
295         return output;
296     }
297 
298     // check result of dumping base archive
299     public static OutputAnalyzer checkBaseDump(OutputAnalyzer output) throws Exception {
300         output.shouldContain("Loading classes to share");
301         output.shouldHaveExitValue(0);
302         //output.shouldNotContain(MSG_STATIC_FIELD_MAY_HOLD_DIFFERENT_VALUE); // FIXME -- leyden+JEP483 merge
303         return output;
304     }
305 
306     // A commonly used convenience methods to create an archive and check the results
307     // Creates an archive and checks for errors
308     public static OutputAnalyzer createArchiveAndCheck(CDSOptions opts)
309         throws Exception {
310         return checkDump(createArchive(opts));
311     }
312 
313 
314     public static OutputAnalyzer createArchiveAndCheck(String... cliPrefix)
315         throws Exception {
316         return checkDump(createArchive(cliPrefix));
317     }
318 
319 
320     // This method should be used to check the output of child VM for common exceptions.
321     // Most of CDS tests deal with child VM processes for creating and using the archive.
322     // However exceptions that occur in the child process do not automatically propagate

423     // tests to make sure the archived heap objects are mapped/loaded properly.
424     public static void addVerifyArchivedFields(ArrayList<String> cmd) {
425         cmd.add("-XX:+UnlockDiagnosticVMOptions");
426         cmd.add("-XX:VerifyArchivedFields=1");
427     }
428 
429     // Execute JVM with CDS archive, specify CDSOptions
430     public static OutputAnalyzer runWithArchive(CDSOptions opts)
431         throws Exception {
432 
433         ArrayList<String> cmd = new ArrayList<String>();
434         cmd.addAll(opts.prefix);
435         cmd.add("-Xshare:" + opts.xShareMode);
436         cmd.add("-Dtest.timeout.factor=" + TestTimeoutFactor);
437 
438         if (!opts.useSystemArchive) {
439             if (opts.archiveName == null)
440                 opts.archiveName = getDefaultArchiveName();
441             cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
442         }
443         if (!opts.benchmarkMode) {
444           addVerifyArchivedFields(cmd);
445         }
446 
447         if (opts.useVersion)
448             cmd.add("-version");
449 
450         for (String s : opts.suffix) cmd.add(s);
451 
452         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
453         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(cmdLine);
454         return executeAndLog(pb, "exec");
455     }
456 
457 
458     // A commonly used convenience methods to create an archive and check the results
459     // Creates an archive and checks for errors
460     public static OutputAnalyzer runWithArchiveAndCheck(CDSOptions opts) throws Exception {
461         return checkExec(runWithArchive(opts));
462     }
463 
464 
465     public static OutputAnalyzer runWithArchiveAndCheck(String... cliPrefix) throws Exception {
< prev index next >