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 = Long.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"); }