28 import java.util.Arrays; 29 30 import sun.jvm.hotspot.tools.JStack; 31 import sun.jvm.hotspot.tools.JMap; 32 import sun.jvm.hotspot.tools.JInfo; 33 import sun.jvm.hotspot.tools.JSnap; 34 35 public class SALauncher { 36 37 private static boolean launcherHelp() { 38 System.out.println(" clhsdb \tcommand line debugger"); 39 System.out.println(" hsdb \tui debugger"); 40 System.out.println(" debugd --help\tto get more information"); 41 System.out.println(" jstack --help\tto get more information"); 42 System.out.println(" jmap --help\tto get more information"); 43 System.out.println(" jinfo --help\tto get more information"); 44 System.out.println(" jsnap --help\tto get more information"); 45 return false; 46 } 47 48 private static boolean commonHelp() { 49 // --pid <pid> 50 // --exe <exe> 51 // --core <core> 52 System.out.println(" --exe\t<executable image name>"); 53 System.out.println(" --core\t<path to coredump>"); 54 System.out.println(" --pid\t<pid of process to attach>"); 55 return false; 56 } 57 58 private static boolean debugdHelp() { 59 // [options] <pid> [server-id] 60 // [options] <executable> <core> [server-id] 61 System.out.println(" --serverid\t<unique id for this debug server>"); 62 return commonHelp(); 63 } 64 65 private static boolean jinfoHelp() { 66 // --flags -> -flags 67 // --sysprops -> -sysprops 68 System.out.println(" --flags\tto print VM flags"); 69 System.out.println(" --sysprops\tto print Java System properties"); 70 System.out.println(" <no option>\tto print both of the above"); 71 return commonHelp(); 72 } 73 74 private static boolean jmapHelp() { 75 // --heap -> -heap 76 // --binaryheap -> -heap:format=b 77 // --histo -> -histo 78 // --clstats -> -clstats 79 // --finalizerinfo -> -finalizerinfo 80 81 System.out.println(" <no option>\tto print same info as Solaris pmap"); 82 System.out.println(" --heap\tto print java heap summary"); 83 System.out.println(" --binaryheap\tto dump java heap in hprof binary format"); 84 System.out.println(" --dumpfile\tname of the dump file"); 85 System.out.println(" --histo\tto print histogram of java object heap"); 86 System.out.println(" --clstats\tto print class loader statistics"); 87 System.out.println(" --finalizerinfo\tto print information on objects awaiting finalization"); 88 return commonHelp(); 89 } 90 91 private static boolean jstackHelp() { 92 // --locks -> -l 93 // --mixed -> -m 94 System.out.println(" --locks\tto print java.util.concurrent locks"); 95 System.out.println(" --mixed\tto print both java and native frames (mixed mode)"); 96 return commonHelp(); 97 } 98 99 private static boolean jsnapHelp() { 100 System.out.println(" --all\tto print all performance counters"); 101 return commonHelp(); 102 } 103 104 private static boolean toolHelp(String toolName) { 105 if (toolName.equals("jstack")) { 106 return jstackHelp(); 107 } 108 if (toolName.equals("jinfo")) { 109 return jinfoHelp(); 110 } 111 if (toolName.equals("jmap")) { 112 return jmapHelp(); 113 } 114 if (toolName.equals("jsnap")) { 115 return jsnapHelp(); 116 } 117 if (toolName.equals("debugd")) { 118 return debugdHelp(); 119 } 120 if (toolName.equals("hsdb") || toolName.equals("clhsdb")) { 121 return commonHelp(); 122 } 123 return launcherHelp(); 124 } 125 126 private static void buildAttachArgs(ArrayList<String> newArgs, String pid, 127 String exe, String core, boolean allowEmpty) { 128 if (!allowEmpty && (pid == null) && (exe == null)) { 129 throw new SAGetoptException("You have to set --pid or --exe."); 130 } 131 132 if (pid != null) { // Attach to live process 133 if (exe != null) { 134 throw new SAGetoptException("Unnecessary argument: --exe"); 135 } else if (core != null) { 136 throw new SAGetoptException("Unnecessary argument: --core"); 137 } else if (!pid.matches("^\\d+$")) { 138 throw new SAGetoptException("Invalid pid: " + pid); 139 } 140 141 newArgs.add(pid); | 28 import java.util.Arrays; 29 30 import sun.jvm.hotspot.tools.JStack; 31 import sun.jvm.hotspot.tools.JMap; 32 import sun.jvm.hotspot.tools.JInfo; 33 import sun.jvm.hotspot.tools.JSnap; 34 35 public class SALauncher { 36 37 private static boolean launcherHelp() { 38 System.out.println(" clhsdb \tcommand line debugger"); 39 System.out.println(" hsdb \tui debugger"); 40 System.out.println(" debugd --help\tto get more information"); 41 System.out.println(" jstack --help\tto get more information"); 42 System.out.println(" jmap --help\tto get more information"); 43 System.out.println(" jinfo --help\tto get more information"); 44 System.out.println(" jsnap --help\tto get more information"); 45 return false; 46 } 47 48 private static boolean commonHelp(String mode) { 49 // --pid <pid> 50 // --exe <exe> 51 // --core <core> 52 System.out.println(" --pid <pid> \tTo attach to and operate on the given live process."); 53 System.out.println(" --core <corefile>\tTo operate on a given core file."); 54 System.out.println(" --exe <executable for corefile>"); 55 System.out.println(); 56 System.out.println(" The --core and --exe options must be set together to give the core"); 57 System.out.println(" file, and associated executable, to operate on. Otherwise the --pid"); 58 System.out.println(" option can be set to operate on a live process."); 59 System.out.println(" The arguments for --exe and --core can use absolute or relative paths."); 60 System.out.println(); 61 System.out.println(" Examples: jhsdb " + mode + " --pid 1234"); 62 System.out.println(" or jhsdb " + mode + " --core ./core.1234 --exe ./myexe"); 63 return false; 64 } 65 66 private static boolean debugdHelp() { 67 // [options] <pid> [server-id] 68 // [options] <executable> <core> [server-id] 69 System.out.println(" --serverid <id> \tA unique identifier for this debug server."); 70 return commonHelp("debugd"); 71 } 72 73 private static boolean jinfoHelp() { 74 // --flags -> -flags 75 // --sysprops -> -sysprops 76 System.out.println(" --flags \tTo print VM flags."); 77 System.out.println(" --sysprops \tTo print Java System properties."); 78 System.out.println(" <no option> \tTo print both of the above."); 79 return commonHelp("jinfo"); 80 } 81 82 private static boolean jmapHelp() { 83 // --heap -> -heap 84 // --binaryheap -> -heap:format=b 85 // --histo -> -histo 86 // --clstats -> -clstats 87 // --finalizerinfo -> -finalizerinfo 88 89 System.out.println(" <no option> \tTo print same info as Solaris pmap."); 90 System.out.println(" --heap \tTo print java heap summary."); 91 System.out.println(" --binaryheap \tTo dump java heap in hprof binary format."); 92 System.out.println(" --dumpfile <name>\tA Name of the dump file."); 93 System.out.println(" --histo \tTo print histogram of java object heap."); 94 System.out.println(" --clstats \tTo print class loader statistics."); 95 System.out.println(" --finalizerinfo \tTo print information on objects awaiting finalization."); 96 return commonHelp("jmap"); 97 } 98 99 private static boolean jstackHelp() { 100 // --locks -> -l 101 // --mixed -> -m 102 System.out.println(" --locks \tTo print java.util.concurrent locks."); 103 System.out.println(" --mixed \tTo print both Java and native frames (mixed mode)."); 104 return commonHelp("jstack"); 105 } 106 107 private static boolean jsnapHelp() { 108 System.out.println(" --all \tTo print all performance counters."); 109 return commonHelp("jsnap"); 110 } 111 112 private static boolean toolHelp(String toolName) { 113 if (toolName.equals("jstack")) { 114 return jstackHelp(); 115 } 116 if (toolName.equals("jinfo")) { 117 return jinfoHelp(); 118 } 119 if (toolName.equals("jmap")) { 120 return jmapHelp(); 121 } 122 if (toolName.equals("jsnap")) { 123 return jsnapHelp(); 124 } 125 if (toolName.equals("debugd")) { 126 return debugdHelp(); 127 } 128 if (toolName.equals("hsdb")) { 129 return commonHelp("hsdb"); 130 } 131 if (toolName.equals("clhsdb")) { 132 return commonHelp("clhsdb"); 133 } 134 return launcherHelp(); 135 } 136 137 private static void buildAttachArgs(ArrayList<String> newArgs, String pid, 138 String exe, String core, boolean allowEmpty) { 139 if (!allowEmpty && (pid == null) && (exe == null)) { 140 throw new SAGetoptException("You have to set --pid or --exe."); 141 } 142 143 if (pid != null) { // Attach to live process 144 if (exe != null) { 145 throw new SAGetoptException("Unnecessary argument: --exe"); 146 } else if (core != null) { 147 throw new SAGetoptException("Unnecessary argument: --core"); 148 } else if (!pid.matches("^\\d+$")) { 149 throw new SAGetoptException("Invalid pid: " + pid); 150 } 151 152 newArgs.add(pid); |