public static void main(String args[]) throws Exception { OutputAnalyzer output; WhiteBox wb = WhiteBox.getWhiteBox(); // Grab my own PID String pid = Integer.toString(ProcessTools.getProcessId()); ProcessBuilder pb = new ProcessBuilder(); // Use WB API to alloc and free with the mtTest type long memAlloc3 = wb.NMTMalloc(128 * 1024); long memAlloc2 = wb.NMTMalloc(256 * 1024); wb.NMTFree(memAlloc3); long memAlloc1 = wb.NMTMalloc(512 * 1024); wb.NMTFree(memAlloc2); // Use WB API to ensure that all data has been merged before we continue if (!wb.NMTWaitForDataMerge()) { throw new Exception("Call to WB API NMTWaitForDataMerge() failed"); } // Run 'jcmd <pid> VM.native_memory summary' pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"}); output = new OutputAnalyzer(pb.start()); output.shouldContain("Test (reserved=512KB, committed=512KB)"); // Free the memory allocated by NMTAllocTest wb.NMTFree(memAlloc1); // Use WB API to ensure that all data has been merged before we continue if (!wb.NMTWaitForDataMerge()) { throw new Exception("Call to WB API NMTWaitForDataMerge() failed"); } output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Test (reserved="); }
public static void main(String args[]) throws Exception { is_64_bit_system = (Platform.is64bit()); OutputAnalyzer output; whiteBox = WhiteBox.getWhiteBox(); // Grab my own PID String pid = Integer.toString(ProcessTools.getProcessId()); ProcessBuilder pb = new ProcessBuilder(); AllocThread[] alloc_threads = new AllocThread[256]; ReleaseThread[] release_threads = new ReleaseThread[64]; int index; // Create many allocation threads for (index = 0; index < alloc_threads.length; index++) { alloc_threads[index] = new AllocThread(); } // Fewer release threads for (index = 0; index < release_threads.length; index++) { release_threads[index] = new ReleaseThread(); } if (is_64_bit_system()) { sleep_wait(2 * 60 * 1000); } else { sleep_wait(60 * 1000); } // pause the stress test phase = TestPhase.pause; while (pause_count.intValue() < alloc_threads.length + release_threads.length) { sleep_wait(10); } long mallocd_total_in_KB = (mallocd_total + K / 2) / K; // Now check if the result from NMT matches the total memory allocated. String expected_test_summary = "Test (reserved=" + mallocd_total_in_KB + "KB, committed=" + mallocd_total_in_KB + "KB)"; // Run 'jcmd <pid> VM.native_memory summary' pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary"}); output = new OutputAnalyzer(pb.start()); output.shouldContain(expected_test_summary); // Release all allocated memory phase = TestPhase.release; synchronized (mallocd_memory) { mallocd_memory.notifyAll(); } // Join all threads for (index = 0; index < alloc_threads.length; index++) { try { alloc_threads[index].join(); } catch (InterruptedException e) { } } for (index = 0; index < release_threads.length; index++) { try { release_threads[index].join(); } catch (InterruptedException e) { } } // All test memory allocated should be released output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Test (reserved="); // Verify that tracking level has not been downgraded pb.command( new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "statistics"}); output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Tracking level has been downgraded due to lack of resources"); }
private void verifyRTMRetryCount(int retryCount) throws Throwable { CompilableTest busyLock = new BusyLock(); long expectedAborts = retryCount + 1L; OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( busyLock, "-XX:-UseRTMXendForLockBusy", "-XX:RTMTotalCountIncrRate=1", CommandLineOptionTest.prepareNumericFlag("RTMRetryCount", retryCount), "-XX:RTMTotalCountIncrRate=1", "-XX:+PrintPreciseRTMLockingStatistics", BusyLock.class.getName(), Boolean.toString(TestRTMRetryCount.INFLATE_MONITOR), Integer.toString(TestRTMRetryCount.LOCKING_TIME)); outputAnalyzer.shouldHaveExitValue(0); List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( busyLock.getMethodWithLockName(), outputAnalyzer.getStdout()); Asserts.assertEQ( statistics.size(), 1, "VM output should contain " + "exactly one rtm locking statistics entry for method " + busyLock.getMethodWithLockName()); Asserts.assertEQ( statistics.get(0).getTotalAborts(), expectedAborts, String.format("It is expected to get %d aborts", expectedAborts)); }
/** * Executes a process, waits for it to finish, prints the process output to stdout and returns the * process output. * * <p>The process will have exited before this method returns. * * @param pb The ProcessBuilder to execute. * @return The {@linkplain OutputAnalyzer} instance wrapping the process. */ public static OutputAnalyzer executeCommand(ProcessBuilder pb) throws Throwable { String cmdLine = pb.command().stream().collect(Collectors.joining(" ")); System.out.println("Command line: [" + cmdLine + "]"); OutputAnalyzer analyzer = ProcessTools.executeProcess(pb); System.out.println(analyzer.getOutput()); return analyzer; }
/** * Executes a process, waits for it to finish, prints the process output to stdout, and returns * the process output. * * <p>The process will have exited before this method returns. * * @param cmds The command line to execute. * @return The {@linkplain OutputAnalyzer} instance wrapping the process. */ public static OutputAnalyzer executeCommand(String... cmds) throws Throwable { String cmdLine = Arrays.stream(cmds).collect(Collectors.joining(" ")); System.out.println("Command line: [" + cmdLine + "]"); OutputAnalyzer analyzer = ProcessTools.executeProcess(cmds); System.out.println(analyzer.getOutput()); return analyzer; }
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:MaxMetaspaceSize=10m", "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldContain( "is not large enough.\nEither don't specify the -XX:MaxMetaspaceSize=<size>\nor increase the size to at least"); output.shouldHaveExitValue(2); }
/** * Used to log command line, stdout, stderr and exit code from an executed process. * * @param pb The executed process. * @param output The output from the process. */ public static String getProcessLog(ProcessBuilder pb, OutputAnalyzer output) { String stderr = output == null ? "null" : output.getStderr(); String stdout = output == null ? "null" : output.getStdout(); String exitValue = output == null ? "null" : Integer.toString(output.getExitValue()); StringBuilder logMsg = new StringBuilder(); final String nl = System.getProperty("line.separator"); logMsg.append("--- ProcessLog ---" + nl); logMsg.append("cmd: " + getCommandLine(pb) + nl); logMsg.append("exitvalue: " + exitValue + nl); logMsg.append("stderr: " + stderr + nl); logMsg.append("stdout: " + stdout + nl); return logMsg.toString(); }
public static void main(String[] args) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintWarnings=8", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldContain("Improperly specified VM option 'PrintWarnings=8'"); output.shouldHaveExitValue(1); pb = ProcessTools.createJavaProcessBuilder("-XX:-PrintWarnings=8", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Improperly specified VM option 'PrintWarnings=8'"); output.shouldHaveExitValue(1); }
public static void main(String args[]) throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-showversion", "-XX:+UseParallelGC", "-XX:+UseAdaptiveGCBoundary", "-XX:+PrintCommandLineFlags", SystemGCCaller.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb.start()); output.shouldContain("+UseAdaptiveGCBoundary"); output.shouldNotContain("error"); output.shouldHaveExitValue(0); }
public static void main(String args[]) throws Exception { if (!Platform.is64bit()) { System.out.println( "ReadFromNoaccessArea tests is useful only on 64bit architecture. Passing silently."); return; } ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-Xbootclasspath/a:.", "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", "-XX:+UseCompressedOops", "-XX:HeapBaseMinAddress=33G", "-XX:-CreateCoredumpOnCrash", "-Xmx32m", DummyClassWithMainTryingToReadFromNoaccessArea.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb.start()); System.out.println("******* Printing stdout for analysis in case of failure *******"); System.out.println(output.getStdout()); System.out.println("******* Printing stderr for analysis in case of failure *******"); System.out.println(output.getStderr()); System.out.println("***************************************************************"); if (output.getStdout() != null && output.getStdout().contains("WB_ReadFromNoaccessArea method is useless")) { // Test conditions broken. There is no protected page in ReservedHeapSpace in these // circumstances. Silently passing test. return; } if (Platform.isWindows()) { output.shouldContain("EXCEPTION_ACCESS_VIOLATION"); } else if (Platform.isOSX()) { output.shouldContain("SIGBUS"); } else { output.shouldContain("SIGSEGV"); } }
public static void main(String[] args) throws Exception { ProcessBuilder pb; String filename = "./CDSCompressedKPtrsError.jsa"; if (Platform.is64bit()) { pb = ProcessTools.createJavaProcessBuilder( "-XX:+UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); try { output.shouldContain("Loading classes to share"); output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( "-XX:-UseCompressedClassPointers", "-XX:-UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( "-XX:-UseCompressedClassPointers", "-XX:+UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(0); pb = ProcessTools.createJavaProcessBuilder( "-XX:+UseCompressedClassPointers", "-XX:-UseCompressedOops", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=" + filename, "-Xshare:on", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(0); } catch (RuntimeException e) { output.shouldContain("Unable to use shared archive"); output.shouldHaveExitValue(1); } // Test bad options with -Xshare:dump. pb = ProcessTools.createJavaProcessBuilder( "-XX:-UseCompressedOops", "-XX:+UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad1.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); pb = ProcessTools.createJavaProcessBuilder( "-XX:+UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad2.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); pb = ProcessTools.createJavaProcessBuilder( "-XX:-UseCompressedOops", "-XX:-UseCompressedClassPointers", "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./CDSCompressedKPtrsErrorBad3.jsa", "-Xshare:dump"); output = new OutputAnalyzer(pb.start()); output.shouldContain("Cannot dump shared archive"); } }