Java Code Examples for jdk.test.lib.process.ProcessTools#createJavaProcessBuilder()
The following examples show how to use
jdk.test.lib.process.ProcessTools#createJavaProcessBuilder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDynamicNumberOfGCThreads.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void testDynamicNumberOfGCThreads(String gcFlag) throws Exception { // UseDynamicNumberOfGCThreads and TraceDynamicGCThreads enabled String[] baseArgs = {"-XX:+" + gcFlag, "-Xmx10M", "-XX:+UseDynamicNumberOfGCThreads", "-Xlog:gc+task=trace", GCTest.class.getName()}; // Base test with gc and +UseDynamicNumberOfGCThreads: ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder(baseArgs); verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start())); // Ensure it also works on uniprocessors or if user specifies -XX:ParallelGCThreads=1: String[] extraArgs = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+ForceDynamicNumberOfGCThreads", "-XX:ParallelGCThreads=1"}; String[] finalArgs = new String[baseArgs.length + extraArgs.length]; System.arraycopy(extraArgs, 0, finalArgs, 0, extraArgs.length); System.arraycopy(baseArgs, 0, finalArgs, extraArgs.length, baseArgs.length); pb_enabled = ProcessTools.createJavaProcessBuilder(finalArgs); verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start())); // Turn on parallel reference processing String[] parRefProcArg = {"-XX:+ParallelRefProcEnabled", "-XX:-ShowMessageBoxOnError"}; String[] parRefArgs = new String[baseArgs.length + parRefProcArg.length]; System.arraycopy(parRefProcArg, 0, parRefArgs, 0, parRefProcArg.length); System.arraycopy(baseArgs, 0, parRefArgs, parRefProcArg.length, baseArgs.length); pb_enabled = ProcessTools.createJavaProcessBuilder(parRefArgs); verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start())); }
Example 2
Source File: MonitorInflationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:monitorinflation=debug", InnerClass.class.getName()); analyzeOutputOn(pb); pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceMonitorInflation", InnerClass.class.getName()); analyzeOutputOn(pb); pb = ProcessTools.createJavaProcessBuilder("-Xlog:monitorinflation=off", InnerClass.class.getName()); analyzeOutputOff(pb); pb = ProcessTools.createJavaProcessBuilder("-XX:-TraceMonitorInflation", InnerClass.class.getName()); analyzeOutputOff(pb); }
Example 3
Source File: CDSTestUtils.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static OutputAnalyzer createArchive(CDSOptions opts) throws Exception { startNewArchiveName(); ArrayList<String> cmd = new ArrayList<String>(); for (String p : opts.prefix) cmd.add(p); cmd.add("-Xshare:dump"); cmd.add("-Xlog:cds,cds+hashtables"); if (opts.archiveName == null) opts.archiveName = getDefaultArchiveName(); cmd.add("-XX:SharedArchiveFile=./" + opts.archiveName); for (String s : opts.suffix) cmd.add(s); String[] cmdLine = cmd.toArray(new String[cmd.size()]); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); return executeAndLog(pb, "dump"); }
Example 4
Source File: BiasedLockingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:biasedlocking", "-XX:BiasedLockingStartupDelay=0", InnerClass.class.getName()); analyzeOutputOn(pb); pb = ProcessTools.createJavaProcessBuilder("-XX:+TraceBiasedLocking", "-XX:BiasedLockingStartupDelay=0", InnerClass.class.getName()); analyzeOutputOn(pb); pb = ProcessTools.createJavaProcessBuilder("-Xlog:biasedlocking=off", "-XX:BiasedLockingStartupDelay=0", InnerClass.class.getName()); analyzeOutputOff(pb); pb = ProcessTools.createJavaProcessBuilder("-XX:-TraceBiasedLocking", "-XX:BiasedLockingStartupDelay=0", InnerClass.class.getName()); analyzeOutputOff(pb); }
Example 5
Source File: TestNewRatioFlag.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Verify that actual size of young gen conforms specified NewRatio * * @param ratio value of NewRatio option * @param options additional options for VM */ public static void testNewRatio(int ratio, LinkedList<String> options) throws Exception { LinkedList<String> vmOptions = new LinkedList<>(options); Collections.addAll(vmOptions, "-Xbootclasspath/a:.", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", "-XX:GCLockerEdenExpansionPercent=0", "-Xmx" + HEAP_SIZE, "-Xms" + HEAP_SIZE, "-XX:NewRatio=" + ratio, "-XX:-UseLargePages", NewRatioVerifier.class.getName(), Integer.toString(ratio) ); ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); analyzer.shouldHaveExitValue(0); System.out.println(analyzer.getOutput()); }
Example 6
Source File: TestMultipleXlogArgs.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:logging=debug", "-Xlog:logging=trace", "-Xlog:defaultmethods=trace", "-Xlog:defaultmethods=off", "-Xlog:safepoint=info", "-Xlog:safepoint=info", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); // -Xlog:logging=trace means that the log configuration will be printed. String stdoutConfigLine = "\\[logging *\\] #0: stdout .*"; // Ensure logging=trace has overwritten logging=debug output.shouldMatch(stdoutConfigLine + "logging=trace").shouldNotMatch(stdoutConfigLine + "logging=debug"); // Make sure safepoint=info is printed exactly once even though we're setting it twice output.shouldMatch(stdoutConfigLine + "safepoint=info").shouldNotMatch(stdoutConfigLine + "safepoint=info.*safepoint=info"); // Shouldn't see defaultmethods at all, because disabled tags are not listed output.shouldNotMatch(stdoutConfigLine + "defaultmethods"); output.shouldHaveExitValue(0); }
Example 7
Source File: TestDumpOnExit.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void testDumponExit(Supplier<Path> p,String... args) throws Exception, IOException { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, args); OutputAnalyzer output = ProcessTools.executeProcess(pb); System.out.println(output.getOutput()); output.shouldHaveExitValue(0); Path dump = p.get(); Asserts.assertTrue(Files.isRegularFile(dump), "No recording dumped " + dump); System.out.println("Dumped recording size=" + Files.size(dump)); Asserts.assertFalse(RecordingFile.readAllEvents(dump).isEmpty(), "No events in dump"); }
Example 8
Source File: UnsupportedClassFileVersion.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String... args) throws Exception { writeClassFile(); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".", "ClassFile"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldContain("ClassFile has been compiled by a more recent version of the " + "Java Runtime (class file version 99.0), this version of " + "the Java Runtime only recognizes class file versions up to " + System.getProperty("java.class.version")); output.shouldHaveExitValue(1); }
Example 9
Source File: TestParallelGC.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseParallelGC", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldNotContain("deprecated"); output.shouldNotContain("error"); output.shouldHaveExitValue(0); }
Example 10
Source File: TestG1PercentageOptions.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void check(String flag, boolean is_valid) throws Exception { String[] flags = new String[] { "-XX:+UseG1GC", flag, "-version" }; ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); OutputAnalyzer output = new OutputAnalyzer(pb.start()); if (is_valid) { output.shouldHaveExitValue(0); } else { output.shouldHaveExitValue(1); } }
Example 11
Source File: StackTraceLogging.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:stacktrace=info", "-XX:MaxJavaStackTraceDepth=1024", "--add-opens", "java.base/java.lang=ALL-UNNAMED", "TestThrowable"); analyzeOutputOn(pb); }
Example 12
Source File: CommandLineOptionTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Verifies that value of specified JVM option is the same as * expected value. * This method filter out option with {@code optionName} * name from test java options. * * @param optionName a name of tested option. * @param expectedValue expected value of tested option. * @param addTestVmOptions if {@code true}, then test VM options * will be used. * @param optionErrorString message will be shown if option value is not as * expected. * @param additionalVMOpts additional options that should be * passed to JVM. * @throws Throwable if verification fails or some other issues * occur. */ public static void verifyOptionValue(String optionName, String expectedValue, String optionErrorString, boolean addTestVmOptions, String... additionalVMOpts) throws Throwable { List<String> vmOpts = new ArrayList<>(); if (addTestVmOptions) { Collections.addAll(vmOpts, Utils.getFilteredTestJavaOpts(optionName)); } Collections.addAll(vmOpts, additionalVMOpts); Collections.addAll(vmOpts, "-XX:+PrintFlagsFinal", "-version"); ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder( vmOpts.toArray(new String[vmOpts.size()])); OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start()); try { outputAnalyzer.shouldHaveExitValue(0); } catch (RuntimeException e) { String errorMessage = String.format( "JVM should start with option '%s' without errors.", optionName); throw new AssertionError(errorMessage, e); } verifyOptionValue(optionName, expectedValue, optionErrorString, outputAnalyzer); }
Example 13
Source File: GetObjectSizeOverflow.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { if (!Platform.is64bit()) { System.out.println("Test needs a 4GB heap and can only be run as a 64bit process, skipping."); return; } PrintWriter pw = new PrintWriter("MANIFEST.MF"); pw.println("Premain-Class: GetObjectSizeOverflowAgent"); pw.close(); ProcessBuilder pb = new ProcessBuilder(); pb.command(new String[] { JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF", "agent.jar", "GetObjectSizeOverflowAgent.class"}); pb.start().waitFor(); ProcessBuilder pt = ProcessTools.createJavaProcessBuilder(true, "-Xmx4000m", "-javaagent:agent.jar", "GetObjectSizeOverflowAgent"); OutputAnalyzer output = new OutputAnalyzer(pt.start()); if (output.getStdout().contains("Could not reserve enough space") || output.getStderr().contains("java.lang.OutOfMemoryError")) { System.out.println("stdout: " + output.getStdout()); System.out.println("stderr: " + output.getStderr()); System.out.println("Test could not reserve or allocate enough space, skipping"); return; } output.stdoutShouldContain("GetObjectSizeOverflow passed"); }
Example 14
Source File: TraceExceptionsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-Xlog:exceptions=info", "NoClassFound"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldContain("<a 'java/lang/ClassNotFoundException'").shouldContain(": NoClassFound>"); output.shouldNotContain("<a 'java/lang/ClassNotFoundException'>"); output.shouldHaveExitValue(1); }
Example 15
Source File: TestDefaultLogOutput.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:badTag"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.stdoutShouldMatch("\\[error *\\]\\[logging *\\]"); output.shouldHaveExitValue(1); }
Example 16
Source File: ObjectAlignment.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static OutputAnalyzer testObjectAlignment(int alignment) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:ObjectAlignmentInBytes=" + alignment, "-version"); return new OutputAnalyzer(pb.start()); }
Example 17
Source File: PatchModuleClassList.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String args[]) throws Throwable { // Case 1. A class to be loaded by the boot class loader // Create a class file in the module java.naming. This class file // will be put in the javanaming.jar file. String source = "package javax.naming.spi; " + "public class NamingManager { " + " static { " + " System.out.println(\"I pass!\"); " + " } " + "}"; ClassFileInstaller.writeClassToDisk(BOOT_CLASS, InMemoryJavaCompiler.compile(BOOT_CLASS.replace('/', '.'), source, "-Xmodule:java.naming"), System.getProperty("test.classes")); // Build the jar file that will be used for the module "java.naming". BasicJarBuilder.build("javanaming", BOOT_CLASS); String moduleJar = BasicJarBuilder.getTestJar("javanaming.jar"); String classList = "javanaming.list"; ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( true, "-XX:DumpLoadedClassList=" + classList, "--patch-module=java.naming=" + moduleJar, "PatchModuleMain", BOOT_CLASS.replace('/', '.')); new OutputAnalyzer(pb.start()).shouldHaveExitValue(0); // check the generated classlist file String content = new String(Files.readAllBytes(Paths.get(classList))); if (content.indexOf(BOOT_CLASS) >= 0) { throw new RuntimeException(BOOT_CLASS + " should not be in the classlist"); } // Case 2. A class to be loaded by the platform class loader // Create a class file in the module java.transaction. This class file // will be put in the javatransaction.jar file. source = "package javax.transaction; " + "public class InvalidTransactionException { " + " static { " + " System.out.println(\"I pass!\"); " + " } " + "}"; ClassFileInstaller.writeClassToDisk(PLATFORM_CLASS, InMemoryJavaCompiler.compile(PLATFORM_CLASS.replace('/', '.'), source, "-Xmodule:java.transaction"), System.getProperty("test.classes")); // Build the jar file that will be used for the module "java.transaction". BasicJarBuilder.build("javatransaction", PLATFORM_CLASS); moduleJar = BasicJarBuilder.getTestJar("javatransaction.jar"); classList = "javatransaction.list"; pb = ProcessTools.createJavaProcessBuilder( true, "-XX:DumpLoadedClassList=" + classList, "--patch-module=java.naming=" + moduleJar, "PatchModuleMain", PLATFORM_CLASS.replace('/', '.')); new OutputAnalyzer(pb.start()).shouldHaveExitValue(0); // check the generated classlist file content = new String(Files.readAllBytes(Paths.get(classList))); if (content.indexOf(PLATFORM_CLASS) >= 0) { throw new RuntimeException(PLATFORM_CLASS + " should not be in the classlist"); } // Case 3. A class to be loaded from the bootclasspath/a // Create a simple class file source = "public class Hello { " + " public static void main(String args[]) { " + " System.out.println(\"Hello\"); " + " } " + "}"; ClassFileInstaller.writeClassToDisk("Hello", InMemoryJavaCompiler.compile("Hello", source), System.getProperty("test.classes")); // Build hello.jar BasicJarBuilder.build("hello", "Hello"); moduleJar = BasicJarBuilder.getTestJar("hello.jar"); classList = "hello.list"; pb = ProcessTools.createJavaProcessBuilder( true, "-XX:DumpLoadedClassList=" + classList, "-Xbootclasspath/a:" + moduleJar, "Hello"); new OutputAnalyzer(pb.start()).shouldHaveExitValue(0); // check the generated classlist file content = new String(Files.readAllBytes(Paths.get(classList))); if (content.indexOf("Hello") < 0) { throw new RuntimeException("Hello should be in the classlist"); } }
Example 18
Source File: TestGCId.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testGCId(String gcFlag) throws Exception { ProcessBuilder pb_default = ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-Xlog:gc", "-Xmx10M", GCTest.class.getName()); verifyContainsGCIDs(new OutputAnalyzer(pb_default.start())); }
Example 19
Source File: AttachSetGetFlag.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static ProcessBuilder runTarget(String flagName, String flagValue) throws Exception { return ProcessTools.createJavaProcessBuilder( "-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "AttachSetGetFlag$Target"); }
Example 20
Source File: TestTargetSurvivorRatioFlag.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Verify that actual survivor space usage ratio conforms specified TargetSurvivorRatio * * @param ratio value of TargetSurvivorRatio * @param options additional VM options */ public static void positiveTest(int ratio, LinkedList<String> options) throws Exception { LinkedList<String> vmOptions = new LinkedList<>(options); Collections.addAll(vmOptions, "-Xbootclasspath/a:.", "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", "-XX:+UseAdaptiveSizePolicy", "-Xlog:gc+age=trace", "-XX:MaxTenuringThreshold=" + MAX_TENURING_THRESHOLD, "-XX:NewSize=" + MAX_NEW_SIZE, "-XX:MaxNewSize=" + MAX_NEW_SIZE, "-XX:InitialHeapSize=" + 2 * MAX_NEW_SIZE, "-XX:MaxHeapSize=" + 2 * MAX_NEW_SIZE, "-XX:SurvivorRatio=" + SURVIVOR_RATIO, "-XX:TargetSurvivorRatio=" + ratio, // For reducing variance of survivor size. "-XX:TargetPLABWastePct=" + 1, TargetSurvivorRatioVerifier.class.getName(), Integer.toString(ratio) ); ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()])); OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start()); analyzer.shouldHaveExitValue(0); String output = analyzer.getOutput(); // Test avoids verification for parallel GC if (!output.contains(UNSUPPORTED_GC)) { // Two tests should be done - when actual ratio is lower than TargetSurvivorRatio // and when it is higher. We chech that output contains results for exactly two tests. List<Double> ratios = parseTestOutput(output); if (ratios.size() != 2) { System.out.println(output); throw new RuntimeException("Expected number of ratios extraced for output is 2," + " but " + ratios.size() + " ratios were extracted"); } // At the end of the first test survivor space usage ratio should lies between // TargetSurvivorRatio and TargetSurvivorRatio - 2*DELTA if (ratio < ratios.get(0) || ratio - ratios.get(0) > VARIANCE) { System.out.println(output); throw new RuntimeException("Survivor space usage ratio expected to be close to " + ratio + ", but observed ratio is: " + ratios.get(0)); } // After second test survivor space should be almost empty. if (ratios.get(1) > VARIANCE) { System.out.println(output); throw new RuntimeException("Survivor space expected to be empty due to " + "TargetSurvivorRatio overlimit, however observed " + "survivor space usage ratio is: " + ratios.get(1)); } } else { System.out.println("Selected GC does not support TargetSurvivorRatio option."); } }