126 public static OutputAnalyzer dump(String appJar, String classList[], |
126 public static OutputAnalyzer dump(String appJar, String classList[], |
127 String... suffix) throws Exception { |
127 String... suffix) throws Exception { |
128 return createArchive(appJar, classList, suffix); |
128 return createArchive(appJar, classList, suffix); |
129 } |
129 } |
130 |
130 |
|
131 public static OutputAnalyzer dump(String appJarDir, String appJar, String classList[], |
|
132 String... suffix) throws Exception { |
|
133 return createArchive(appJarDir, appJar, classList, suffix); |
|
134 } |
131 |
135 |
132 // Create AppCDS archive using most common args - convenience method |
136 // Create AppCDS archive using most common args - convenience method |
133 public static OutputAnalyzer createArchive(String appJar, String classList[], |
137 public static OutputAnalyzer createArchive(String appJar, String classList[], |
134 String... suffix) throws Exception { |
138 String... suffix) throws Exception { |
135 AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
139 AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
136 opts.setClassList(classList); |
140 opts.setClassList(classList); |
137 opts.addSuffix(suffix); |
141 opts.addSuffix(suffix); |
138 return createArchive(opts); |
142 return createArchive(opts); |
139 } |
143 } |
140 |
144 |
|
145 public static OutputAnalyzer createArchive(String appJarDir, String appJar, String classList[], |
|
146 String... suffix) throws Exception { |
|
147 AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
|
148 opts.setAppJarDir(appJarDir); |
|
149 opts.setClassList(classList); |
|
150 opts.addSuffix(suffix); |
|
151 return createArchive(opts); |
|
152 } |
|
153 |
141 // Simulate -Xshare:dump with -XX:ArchiveClassesAtExit. See comments around patchJarForDynamicDump() |
154 // Simulate -Xshare:dump with -XX:ArchiveClassesAtExit. See comments around patchJarForDynamicDump() |
142 private static final Class tmp = DynamicDumpHelper.class; |
155 private static final Class tmp = DynamicDumpHelper.class; |
143 |
156 |
144 // Create AppCDS archive using appcds options |
157 // Create AppCDS archive using appcds options |
145 public static OutputAnalyzer createArchive(AppCDSOptions opts) |
158 public static OutputAnalyzer createArchive(AppCDSOptions opts) |
220 } |
233 } |
221 } |
234 } |
222 |
235 |
223 String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
236 String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
224 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
237 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
|
238 if (opts.appJarDir != null) { |
|
239 pb.directory(new File(opts.appJarDir)); |
|
240 } |
225 return executeAndLog(pb, "dump"); |
241 return executeAndLog(pb, "dump"); |
226 } |
242 } |
227 |
243 |
228 // This allows you to run the AppCDS tests with JFR enabled at runtime (though not at |
244 // This allows you to run the AppCDS tests with JFR enabled at runtime (though not at |
229 // dump time, as that's uncommon for typical AppCDS users). |
245 // dump time, as that's uncommon for typical AppCDS users). |
358 } |
374 } |
359 } |
375 } |
360 |
376 |
361 String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
377 String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
362 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
378 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
|
379 if (opts.appJarDir != null) { |
|
380 pb.directory(new File(opts.appJarDir)); |
|
381 } |
363 return executeAndLog(pb, "exec"); |
382 return executeAndLog(pb, "exec"); |
364 } |
383 } |
365 |
384 |
366 |
385 |
367 public static OutputAnalyzer execCommon(String... suffix) throws Exception { |
386 public static OutputAnalyzer execCommon(String... suffix) throws Exception { |
372 |
391 |
373 // This is the new API for running a Java process with CDS enabled. |
392 // This is the new API for running a Java process with CDS enabled. |
374 // See comments in the CDSTestUtils.Result class for how to use this method. |
393 // See comments in the CDSTestUtils.Result class for how to use this method. |
375 public static Result run(String... suffix) throws Exception { |
394 public static Result run(String... suffix) throws Exception { |
376 AppCDSOptions opts = (new AppCDSOptions()); |
395 AppCDSOptions opts = (new AppCDSOptions()); |
|
396 opts.addSuffix(suffix); |
|
397 return new Result(opts, runWithArchive(opts)); |
|
398 } |
|
399 |
|
400 public static Result runWithRelativePath(String jarDir, String... suffix) throws Exception { |
|
401 AppCDSOptions opts = (new AppCDSOptions()); |
|
402 opts.setAppJarDir(jarDir); |
377 opts.addSuffix(suffix); |
403 opts.addSuffix(suffix); |
378 return new Result(opts, runWithArchive(opts)); |
404 return new Result(opts, runWithArchive(opts)); |
379 } |
405 } |
380 |
406 |
381 public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception { |
407 public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception { |
441 } |
467 } |
442 output.shouldHaveExitValue(0); |
468 output.shouldHaveExitValue(0); |
443 return output; |
469 return output; |
444 } |
470 } |
445 |
471 |
|
472 public static OutputAnalyzer testDump(String appJarDir, String appJar, String classList[], |
|
473 String... suffix) throws Exception { |
|
474 OutputAnalyzer output = dump(appJarDir, appJar, classList, suffix); |
|
475 if (DYNAMIC_DUMP) { |
|
476 if (isUnableToMap(output)) { |
|
477 throw new SkippedException(UnableToMapMsg); |
|
478 } |
|
479 output.shouldContain("Written dynamic archive"); |
|
480 } else { |
|
481 output.shouldContain("Loading classes to share"); |
|
482 } |
|
483 output.shouldHaveExitValue(0); |
|
484 return output; |
|
485 } |
446 |
486 |
447 /** |
487 /** |
448 * Simple test -- dump and execute appJar with the given classList in classlist. |
488 * Simple test -- dump and execute appJar with the given classList in classlist. |
449 */ |
489 */ |
450 public static OutputAnalyzer test(String appJar, String classList[], String... args) |
490 public static OutputAnalyzer test(String appJar, String classList[], String... args) |
588 findAllClassesAtPath(entry, list); |
628 findAllClassesAtPath(entry, list); |
589 } catch (Throwable t) {} |
629 } catch (Throwable t) {} |
590 } |
630 } |
591 } |
631 } |
592 } |
632 } |
|
633 |
|
634 public static String composeRelPath(String appJar) { |
|
635 int idx = appJar.lastIndexOf(File.separator); |
|
636 String jarName = appJar.substring(idx + 1); |
|
637 String jarDir = appJar.substring(0, idx); |
|
638 String lastDir = jarDir.substring(jarDir.lastIndexOf(File.separator)); |
|
639 String relPath = jarDir + File.separator + ".." + File.separator + lastDir; |
|
640 String newJar = relPath + File.separator + jarName; |
|
641 return newJar; |
|
642 } |
|
643 |
|
644 |
|
645 public static File createSymLink(String appJar) throws Exception { |
|
646 int idx = appJar.lastIndexOf(File.separator); |
|
647 String jarName = appJar.substring(idx + 1); |
|
648 String jarDir = appJar.substring(0, idx); |
|
649 File origJar = new File(jarDir, jarName); |
|
650 String linkedJarName = "linked_" + jarName; |
|
651 File linkedJar = null; |
|
652 if (!Platform.isWindows()) { |
|
653 linkedJar = new File(jarDir, linkedJarName); |
|
654 if (linkedJar.exists()) { |
|
655 linkedJar.delete(); |
|
656 } |
|
657 Files.createSymbolicLink(linkedJar.toPath(), origJar.toPath()); |
|
658 } |
|
659 return linkedJar; |
|
660 } |
593 } |
661 } |