1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8167108 27 * @summary Checks whether jstack reports a "Threads class SMR info" section. 28 * 29 * @library /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+EnableThreadSMRStatistics TestThreadDumpSMRInfo 33 */ 34 35 import jdk.test.lib.process.OutputAnalyzer; 36 import jdk.test.lib.JDKToolFinder; 37 38 public class TestThreadDumpSMRInfo { 39 // jstack tends to be closely bound to the VM that we are running 40 // so use getTestJDKTool() instead of getCompileJDKTool() or even 41 // getJDKTool() which can fall back to "compile.jdk". 42 final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack"); 43 final static String PID = "" + ProcessHandle.current().pid(); 44 45 // Here's a sample "Threads class SMR info" section: 46 // 47 // Threads class SMR info: 48 // _smr_java_thread_list=0x0000000000ce8da0, length=23, elements={ 49 // 0x000000000043a800, 0x0000000000aee800, 0x0000000000b06800, 0x0000000000b26000, 50 // 0x0000000000b28800, 0x0000000000b2b000, 0x0000000000b2e000, 0x0000000000b30000, 51 // 0x0000000000b32800, 0x0000000000b35000, 0x0000000000b3f000, 0x0000000000b41800, 52 // 0x0000000000b44000, 0x0000000000b46800, 0x0000000000b48800, 0x0000000000b53000, 53 // 0x0000000000b55800, 0x0000000000b57800, 0x0000000000b5a000, 0x0000000000b5c800, 54 // 0x0000000000cc8800, 0x0000000000fd9800, 0x0000000000ef4800 55 // } 56 // _smr_java_thread_list_alloc_cnt=24, _smr_java_thread_list_free_cnt=23, _smr_java_thread_list_max=23, _smr_nested_thread_list_max=0 57 // _smr_delete_lock_wait_cnt=0, _smr_delete_lock_wait_max=0 58 // _smr_to_delete_list_cnt=0, _smr_to_delete_list_max=1 59 60 final static String HEADER_STR = "Threads class SMR info:"; 61 62 static boolean verbose = false; 63 64 public static void main(String[] args) throws Exception { 65 if (args.length != 0) { 66 int arg_i = 0; 67 if (args[arg_i].equals("-v")) { 68 verbose = true; 69 arg_i++; 70 } 71 } 72 73 ProcessBuilder pb = new ProcessBuilder(JSTACK, PID); 74 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 75 76 if (verbose) { 77 System.out.println("stdout: " + output.getStdout()); 78 } 79 80 output.shouldHaveExitValue(0); 81 System.out.println("INFO: jstack ran successfully."); 82 83 output.shouldContain(HEADER_STR); 84 System.out.println("INFO: Found: '" + HEADER_STR + "' in jstack output."); 85 86 System.out.println("Test PASSED."); 87 } 88 89 static void usage() { 90 System.err.println("Usage: java TestThreadDumpSMRInfo [-v]"); 91 System.exit(1); 92 } 93 }