src/share/classes/sun/tools/jinfo/JInfo.java

Print this page
rev 8717 : 8027765: Make exit codes and stdout/stderr printing from jmap/jinfo/jstack/jps consistent
Reviewed-by:

*** 42,52 **** */ public class JInfo { public static void main(String[] args) throws Exception { if (args.length == 0) { ! usage(); // no arguments } boolean useSA = true; String arg1 = args[0]; if (arg1.startsWith("-")) { --- 42,52 ---- */ public class JInfo { public static void main(String[] args) throws Exception { if (args.length == 0) { ! usage(1); // no arguments } boolean useSA = true; String arg1 = args[0]; if (arg1.startsWith("-")) {
*** 54,71 **** arg1.equals("-sysprops")) { // SA JInfo needs <pid> or <server> or // (<executable> and <code file>). So, total // argument count including option has to 2 or 3. if (args.length != 2 && args.length != 3) { ! usage(); } } else if (arg1.equals("-flag")) { // do not use SA, use attach-on-demand useSA = false; } else { // unknown option or -h or -help, print help ! usage(); } } if (useSA) { runTool(args); --- 54,77 ---- arg1.equals("-sysprops")) { // SA JInfo needs <pid> or <server> or // (<executable> and <code file>). So, total // argument count including option has to 2 or 3. if (args.length != 2 && args.length != 3) { ! usage(1); } } else if (arg1.equals("-flag")) { // do not use SA, use attach-on-demand useSA = false; } else { // unknown option or -h or -help, print help ! int exit; ! if (arg1.equals("-help") || arg1.equals("-h")) { ! exit = 0; ! } else { ! exit = 1; ! } ! usage(exit); } } if (useSA) { runTool(args);
*** 73,94 **** if (args.length == 3) { String pid = args[2]; String option = args[1]; flag(pid, option); } else { ! usage(); } } } // Invoke SA tool with the given arguments private static void runTool(String args[]) throws Exception { String tool = "sun.jvm.hotspot.tools.JInfo"; // Tool not available on this platform. Class<?> c = loadClass(tool); if (c == null) { ! usage(); } // invoke the main method with the arguments Class[] argTypes = { String[].class } ; Method m = c.getDeclaredMethod("main", argTypes); --- 79,101 ---- if (args.length == 3) { String pid = args[2]; String option = args[1]; flag(pid, option); } else { ! int exit = arg1.equals("-help") || arg1.equals("-h") ? 0 : 1; ! usage(exit); } } } // Invoke SA tool with the given arguments private static void runTool(String args[]) throws Exception { String tool = "sun.jvm.hotspot.tools.JInfo"; // Tool not available on this platform. Class<?> c = loadClass(tool); if (c == null) { ! usage(1); } // invoke the main method with the arguments Class[] argTypes = { String[].class } ; Method m = c.getDeclaredMethod("main", argTypes);
*** 174,214 **** vm.detach(); } // print usage message ! private static void usage() { Class<?> c = loadClass("sun.jvm.hotspot.tools.JInfo"); boolean usageSA = (c != null); ! System.out.println("Usage:"); if (usageSA) { ! System.out.println(" jinfo [option] <pid>"); ! System.out.println(" (to connect to running process)"); ! System.out.println(" jinfo [option] <executable <core>"); ! System.out.println(" (to connect to a core file)"); ! System.out.println(" jinfo [option] [server_id@]<remote server IP or hostname>"); ! System.out.println(" (to connect to remote debug server)"); ! System.out.println(""); ! System.out.println("where <option> is one of:"); ! System.out.println(" -flag <name> to print the value of the named VM flag"); ! System.out.println(" -flag [+|-]<name> to enable or disable the named VM flag"); ! System.out.println(" -flag <name>=<value> to set the named VM flag to the given value"); ! System.out.println(" -flags to print VM flags"); ! System.out.println(" -sysprops to print Java system properties"); ! System.out.println(" <no option> to print both of the above"); ! System.out.println(" -h | -help to print this help message"); ! } else { ! System.out.println(" jinfo <option> <pid>"); ! System.out.println(" (to connect to a running process)"); ! System.out.println(""); ! System.out.println("where <option> is one of:"); ! System.out.println(" -flag <name> to print the value of the named VM flag"); ! System.out.println(" -flag [+|-]<name> to enable or disable the named VM flag"); ! System.out.println(" -flag <name>=<value> to set the named VM flag to the given value"); ! System.out.println(" -h | -help to print this help message"); } ! System.exit(1); } } --- 181,221 ---- vm.detach(); } // print usage message ! private static void usage(int exit) { Class<?> c = loadClass("sun.jvm.hotspot.tools.JInfo"); boolean usageSA = (c != null); ! System.err.println("Usage:"); if (usageSA) { ! System.err.println(" jinfo [option] <pid>"); ! System.err.println(" (to connect to running process)"); ! System.err.println(" jinfo [option] <executable <core>"); ! System.err.println(" (to connect to a core file)"); ! System.err.println(" jinfo [option] [server_id@]<remote server IP or hostname>"); ! System.err.println(" (to connect to remote debug server)"); ! System.err.println(""); ! System.err.println("where <option> is one of:"); ! System.err.println(" -flag <name> to print the value of the named VM flag"); ! System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag"); ! System.err.println(" -flag <name>=<value> to set the named VM flag to the given value"); ! System.err.println(" -flags to print VM flags"); ! System.err.println(" -sysprops to print Java system properties"); ! System.err.println(" <no option> to print both of the above"); ! System.err.println(" -h | -help to print this help message"); ! } else { ! System.err.println(" jinfo <option> <pid>"); ! System.err.println(" (to connect to a running process)"); ! System.err.println(""); ! System.err.println("where <option> is one of:"); ! System.err.println(" -flag <name> to print the value of the named VM flag"); ! System.err.println(" -flag [+|-]<name> to enable or disable the named VM flag"); ! System.err.println(" -flag <name>=<value> to set the named VM flag to the given value"); ! System.err.println(" -h | -help to print this help message"); } ! System.exit(exit); } }