diff -r fd9b36598481 -r fb63be22ffa6 jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java --- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Mon May 09 13:12:48 2016 +0300 +++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Mon May 09 23:41:59 2016 +0300 @@ -30,8 +30,6 @@ import com.sun.tools.attach.VirtualMachine; import com.sun.tools.attach.AttachNotSupportedException; import sun.tools.attach.HotSpotVirtualMachine; -import jdk.internal.vm.agent.spi.ToolProvider; -import jdk.internal.vm.agent.spi.ToolProviderFinder; /* * This class is the main class for the JStack utility. It parses its arguments @@ -39,15 +37,14 @@ * obtained the thread dump from a target process using the VM attach mechanism */ public class JStack { - private static final String SA_JSTACK_TOOL_NAME = "jstack"; public static void main(String[] args) throws Exception { if (args.length == 0) { usage(1); // no arguments } - boolean useSA = false; - boolean mixed = false; + checkForUnsupportedOptions(args); + boolean locks = false; // Parse the options (arguments starting with "-" ) @@ -60,87 +57,33 @@ if (arg.equals("-help") || arg.equals("-h")) { usage(0); } - else if (arg.equals("-F")) { - useSA = true; - } else { - if (arg.equals("-m")) { - mixed = true; + if (arg.equals("-l")) { + locks = true; } else { - if (arg.equals("-l")) { - locks = true; - } else { - usage(1); - } + usage(1); } } optionCount++; } - // mixed stack implies SA tool - if (mixed) { - useSA = true; - } - - // Next we check the parameter count. If there are two parameters - // we assume core file and executable so we use SA. + // Next we check the parameter count. int paramCount = args.length - optionCount; - if (paramCount == 0 || paramCount > 2) { + if (paramCount != 1) { usage(1); } - if (paramCount == 2) { - useSA = true; - } else { - // If we can't parse it as a pid then it must be debug server - if (!args[optionCount].matches("[0-9]+")) { - useSA = true; - } - } - // now execute using the SA JStack tool or the built-in thread dumper - if (useSA) { - // parameters ( or - String params[] = new String[paramCount]; - for (int i=optionCount; i 1) { + SAOptionError("More than one non-option argument"); + } + } + + private static void SAOptionError(String msg) { + System.err.println("Error: " + msg); + System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jstack instead"); + System.exit(1); } // print usage message @@ -191,25 +156,8 @@ System.err.println("Usage:"); System.err.println(" jstack [-l] "); System.err.println(" (to connect to running process)"); - - if (isAgentToolPresent()) { - System.err.println(" jstack -F [-m] [-l] "); - System.err.println(" (to connect to a hung process)"); - System.err.println(" jstack [-m] [-l] "); - System.err.println(" (to connect to a core file)"); - System.err.println(" jstack [-m] [-l] [server_id@]"); - System.err.println(" (to connect to a remote debug server)"); - } - System.err.println(""); System.err.println("Options:"); - - if (isAgentToolPresent()) { - System.err.println(" -F to force a thread dump. Use when jstack does not respond" + - " (process is hung)"); - System.err.println(" -m to print both java and native frames (mixed mode)"); - } - System.err.println(" -l long listing. Prints additional information about locks"); System.err.println(" -h or -help to print this help message"); System.exit(exit);