< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java

Print this page




  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 the 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>\tThe 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);
 153         } else if (exe != null) {
 154             if (exe.length() == 0) {


 155                 throw new SAGetoptException("You have to set --exe.");
 156             }
 157 
 158             newArgs.add(exe);
 159 
 160             if ((core == null) || (core.length() == 0)) {
 161                 throw new SAGetoptException("You have to set --core.");
 162             }
 163 
 164             newArgs.add(core);


 165         }
 166     }
 167 
 168     private static void runCLHSDB(String[] oldArgs) {
 169         SAGetopt sg = new SAGetopt(oldArgs);
 170         String[] longOpts = {"exe=", "core=", "pid="};
 171 
 172         ArrayList<String> newArgs = new ArrayList();
 173         String pid = null;
 174         String exe = null;
 175         String core = null;
 176         String s = null;
 177 
 178         while((s = sg.next(null, longOpts)) != null) {
 179             if (s.equals("exe")) {
 180                 exe = sg.getOptarg();
 181                 continue;
 182             }
 183             if (s.equals("core")) {
 184                 core = sg.getOptarg();
 185                 continue;
 186             }
 187             if (s.equals("pid")) {
 188                 pid = sg.getOptarg();
 189                 continue;
 190             }
 191         }
 192 
 193         buildAttachArgs(newArgs, pid, exe, core, true);
 194         CLHSDB.main(newArgs.toArray(new String[newArgs.size()]));
 195     }
 196 
 197     private static void runHSDB(String[] oldArgs) {
 198         SAGetopt sg = new SAGetopt(oldArgs);
 199         String[] longOpts = {"exe=", "core=", "pid="};
 200 
 201         ArrayList<String> newArgs = new ArrayList();
 202         String pid = null;
 203         String exe = null;
 204         String core = null;
 205         String s = null;
 206 
 207         while((s = sg.next(null, longOpts)) != null) {
 208             if (s.equals("exe")) {
 209                 exe = sg.getOptarg();
 210                 continue;
 211             }
 212             if (s.equals("core")) {
 213                 core = sg.getOptarg();
 214                 continue;
 215             }
 216             if (s.equals("pid")) {
 217                 pid = sg.getOptarg();
 218                 continue;
 219             }
 220         }
 221 
 222         buildAttachArgs(newArgs, pid, exe, core, true);
 223         HSDB.main(newArgs.toArray(new String[newArgs.size()]));
 224     }
 225 
 226     private static void runJSTACK(String[] oldArgs) {
 227         SAGetopt sg = new SAGetopt(oldArgs);
 228         String[] longOpts = {"exe=", "core=", "pid=",
 229                                  "mixed", "locks"};
 230 
 231         ArrayList<String> newArgs = new ArrayList();
 232         String pid = null;
 233         String exe = null;
 234         String core = null;

 235         String s = null;
 236 
 237         while((s = sg.next(null, longOpts)) != null) {
 238             if (s.equals("exe")) {
 239                 exe = sg.getOptarg();
 240                 continue;
 241             }
 242             if (s.equals("core")) {
 243                 core = sg.getOptarg();
 244                 continue;
 245             }
 246             if (s.equals("pid")) {
 247                 pid = sg.getOptarg();
 248                 continue;
 249             }




 250             if (s.equals("mixed")) {
 251                 newArgs.add("-m");
 252                 continue;
 253             }
 254             if (s.equals("locks")) {
 255                 newArgs.add("-l");
 256                 continue;
 257             }
 258         }
 259 
 260         buildAttachArgs(newArgs, pid, exe, core, false);
 261         JStack jstack = new JStack(false, false);
 262         jstack.runWithArgs(newArgs.toArray(new String[newArgs.size()]));
 263     }
 264 
 265     private static void runJMAP(String[] oldArgs) {
 266         SAGetopt sg = new SAGetopt(oldArgs);
 267         String[] longOpts = {"exe=", "core=", "pid=",
 268               "heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"};
 269 
 270         ArrayList<String> newArgs = new ArrayList();
 271         String pid = null;
 272         String exe = null;
 273         String core = null;

 274         String s = null;
 275         String dumpfile = null;
 276         boolean requestHeapdump = false;
 277 
 278         while((s = sg.next(null, longOpts)) != null) {
 279             if (s.equals("exe")) {
 280                 exe = sg.getOptarg();
 281                 continue;
 282             }
 283             if (s.equals("core")) {
 284                 core = sg.getOptarg();
 285                 continue;
 286             }
 287             if (s.equals("pid")) {
 288                 pid = sg.getOptarg();
 289                 continue;
 290             }




 291             if (s.equals("heap")) {
 292                 newArgs.add("-heap");
 293                 continue;
 294             }
 295             if (s.equals("binaryheap")) {
 296                 requestHeapdump = true;
 297                 continue;
 298             }
 299             if (s.equals("dumpfile")) {
 300                 dumpfile = sg.getOptarg();
 301                 continue;
 302             }
 303             if (s.equals("histo")) {
 304                 newArgs.add("-histo");
 305                 continue;
 306             }
 307             if (s.equals("clstats")) {
 308                 newArgs.add("-clstats");
 309                 continue;
 310             }
 311             if (s.equals("finalizerinfo")) {
 312                 newArgs.add("-finalizerinfo");
 313                 continue;
 314             }
 315         }
 316 
 317         if (!requestHeapdump && (dumpfile != null)) {
 318             throw new IllegalArgumentException("Unexpected argument dumpfile");
 319         }
 320         if (requestHeapdump) {
 321             if (dumpfile == null) {
 322                 newArgs.add("-heap:format=b");
 323             } else {
 324                 newArgs.add("-heap:format=b,file=" + dumpfile);
 325             }
 326         }
 327 
 328         buildAttachArgs(newArgs, pid, exe, core, false);
 329         JMap.main(newArgs.toArray(new String[newArgs.size()]));
 330     }
 331 
 332     private static void runJINFO(String[] oldArgs) {
 333         SAGetopt sg = new SAGetopt(oldArgs);
 334         String[] longOpts = {"exe=", "core=", "pid=",
 335                                      "flags", "sysprops"};
 336 
 337         ArrayList<String> newArgs = new ArrayList();
 338         String exe = null;
 339         String pid = null;
 340         String core = null;

 341         String s = null;
 342 
 343         while((s = sg.next(null, longOpts)) != null) {
 344             if (s.equals("exe")) {
 345                 exe = sg.getOptarg();
 346                 continue;
 347             }
 348             if (s.equals("core")) {
 349                 core = sg.getOptarg();
 350                 continue;
 351             }
 352             if (s.equals("pid")) {
 353                 pid = sg.getOptarg();
 354                 continue;
 355             }




 356             if (s.equals("flags")) {
 357                 newArgs.add("-flags");
 358                 continue;
 359             }
 360             if (s.equals("sysprops")) {
 361                 newArgs.add("-sysprops");
 362                 continue;
 363             }
 364         }
 365 
 366         buildAttachArgs(newArgs, pid, exe, core, false);
 367         JInfo.main(newArgs.toArray(new String[newArgs.size()]));
 368     }
 369 
 370     private static void runJSNAP(String[] oldArgs) {
 371         SAGetopt sg = new SAGetopt(oldArgs);
 372         String[] longOpts = {"exe=", "core=", "pid=", "all"};
 373 
 374         ArrayList<String> newArgs = new ArrayList();
 375         String exe = null;
 376         String pid = null;
 377         String core = null;

 378         String s = null;
 379 
 380         while((s = sg.next(null, longOpts)) != null) {
 381             if (s.equals("exe")) {
 382                 exe = sg.getOptarg();
 383                 continue;
 384             }
 385             if (s.equals("core")) {
 386                 core = sg.getOptarg();
 387                 continue;
 388             }
 389             if (s.equals("pid")) {
 390                 pid = sg.getOptarg();
 391                 continue;
 392             }




 393             if (s.equals("all")) {
 394                 newArgs.add("-a");
 395                 continue;
 396             }
 397         }
 398 
 399         buildAttachArgs(newArgs, pid, exe, core, false);
 400         JSnap.main(newArgs.toArray(new String[newArgs.size()]));
 401     }
 402 
 403     private static void runDEBUGD(String[] oldArgs) {
 404         // By default SA agent classes prefer Windows process debugger
 405         // to windbg debugger. SA expects special properties to be set
 406         // to choose other debuggers. We will set those here before
 407         // attaching to SA agent.
 408         System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true");
 409 
 410         SAGetopt sg = new SAGetopt(oldArgs);
 411         String[] longOpts = {"exe=", "core=", "pid=", "serverid="};
 412 
 413         ArrayList<String> newArgs = new ArrayList<>();
 414         String exe = null;
 415         String pid = null;
 416         String core = null;
 417         String s = null;
 418         String serverid = null;
 419 
 420         while((s = sg.next(null, longOpts)) != null) {
 421           if (s.equals("exe")) {
 422               exe = sg.getOptarg();
 423               continue;
 424           }
 425           if (s.equals("core")) {
 426               core = sg.getOptarg();
 427               continue;
 428           }
 429           if (s.equals("pid")) {
 430               pid = sg.getOptarg();
 431               continue;
 432           }
 433           if (s.equals("serverid")) {
 434               serverid = sg.getOptarg();
 435               continue;
 436           }
 437         }
 438 
 439         buildAttachArgs(newArgs, pid, exe, core, false);
 440         if (serverid != null) {
 441             newArgs.add(serverid);
 442         }
 443 
 444         // delegate to the actual SA debug server.
 445         sun.jvm.hotspot.DebugServer.main(newArgs.toArray(new String[newArgs.size()]));
 446     }
 447 
 448     public static void main(String[] args) {
 449         // Provide a help
 450         if (args.length == 0) {
 451             launcherHelp();
 452             return;
 453         }
 454         // No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb
 455         if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) {
 456             toolHelp(args[0]);
 457             return;
 458         }
 459 




  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, boolean canConnectToRemote) {
  49         // --pid <pid>
  50         // --exe <exe>
  51         // --core <core>
  52         // --remote <[id@]server>
  53         System.out.println("    --pid <pid>           \tTo attach to and operate on the given");
  54         System.out.println("                          \tlive process.");
  55         System.out.println("    --core <corefile>     \tTo operate on the given core file.");
  56         System.out.println("    --exe <executable for corefile>");
  57         if (canConnectToRemote) {
  58             System.out.println("    --remote <[id@]server>\tTo operate on the remote debug server.");
  59         }
  60         System.out.println();
  61         System.out.println("    The --core and --exe options must be set together to give the core");
  62         System.out.println("    file, and associated executable, to operate on. They can use");
  63         System.out.println("    absolute or relative paths.");
  64         System.out.println("    The --pid option can be set to operate on a live process.");
  65         if (canConnectToRemote) {
  66             System.out.println("    The --remote option can be set to operate on a debug server.");
  67             System.out.println("    <--core --exe> and <--pid> and <--remote> are exclusive.");
  68         } else {
  69             System.out.println("    <--core --exe> and <--pid> are exclusive.");
  70         }
  71         System.out.println();
  72         System.out.println("    Examples: jhsdb " + mode + " --pid 1234");
  73         System.out.println("          or  jhsdb " + mode + " --core ./core.1234 --exe ./myexe");
  74         if (canConnectToRemote) {
  75             System.out.println("          or  jhsdb " + mode + " --remote debugserver");
  76             System.out.println("          or  jhsdb " + mode + " --remote id@debugserver");
  77         }
  78         return false;
  79     }
  80 
  81     private static boolean debugdHelp() {
  82         // [options] <pid> [server-id]
  83         // [options] <executable> <core> [server-id]
  84         System.out.println("    --serverid <id>       \tA unique identifier for this debug server.");
  85         return commonHelp("debugd", false);
  86     }
  87 
  88     private static boolean jinfoHelp() {
  89         // --flags -> -flags
  90         // --sysprops -> -sysprops
  91         System.out.println("    --flags               \tTo print VM flags.");
  92         System.out.println("    --sysprops            \tTo print Java System properties.");
  93         System.out.println("    <no option>           \tTo print both of the above.");
  94         return commonHelp("jinfo", true);
  95     }
  96 
  97     private static boolean jmapHelp() {
  98         // --heap -> -heap
  99         // --binaryheap -> -heap:format=b
 100         // --histo -> -histo
 101         // --clstats -> -clstats
 102         // --finalizerinfo -> -finalizerinfo
 103 
 104         System.out.println("    <no option>           \tTo print same info as Solaris pmap.");
 105         System.out.println("    --heap                \tTo print java heap summary.");
 106         System.out.println("    --binaryheap          \tTo dump java heap in hprof binary format.");
 107         System.out.println("    --dumpfile <name>     \tThe name of the dump file.");
 108         System.out.println("    --histo               \tTo print histogram of java object heap.");
 109         System.out.println("    --clstats             \tTo print class loader statistics.");
 110         System.out.println("    --finalizerinfo       \tTo print information on objects awaiting finalization.");
 111         return commonHelp("jmap", true);
 112     }
 113 
 114     private static boolean jstackHelp() {
 115         // --locks -> -l
 116         // --mixed -> -m
 117         System.out.println("    --locks               \tTo print java.util.concurrent locks.");
 118         System.out.println("    --mixed               \tTo print both Java and native frames (mixed mode).");
 119         return commonHelp("jstack", true);
 120     }
 121 
 122     private static boolean jsnapHelp() {
 123         System.out.println("    --all                 \tTo print all performance counters.");
 124         return commonHelp("jsnap", true);
 125     }
 126 
 127     private static boolean toolHelp(String toolName) {
 128         if (toolName.equals("jstack")) {
 129             return jstackHelp();
 130         }
 131         if (toolName.equals("jinfo")) {
 132             return jinfoHelp();
 133         }
 134         if (toolName.equals("jmap")) {
 135             return jmapHelp();
 136         }
 137         if (toolName.equals("jsnap")) {
 138             return jsnapHelp();
 139         }
 140         if (toolName.equals("debugd")) {
 141             return debugdHelp();
 142         }
 143         if (toolName.equals("hsdb")) {
 144             return commonHelp("hsdb", false);
 145         }
 146         if (toolName.equals("clhsdb")) {
 147             return commonHelp("clhsdb", false);
 148         }
 149         return launcherHelp();
 150     }
 151 
 152     private static void buildAttachArgs(ArrayList<String> newArgs, String pid,
 153                                   String exe, String core, String remote, boolean allowEmpty) {
 154         if (!allowEmpty && (pid == null) && (exe == null) && (remote == null)) {
 155             throw new SAGetoptException("You have to set --pid or --exe or --remote.");
 156         }
 157 
 158         if (pid != null) { // Attach to live process
 159             if (exe != null) {
 160                 throw new SAGetoptException("Unnecessary argument: --exe");
 161             } else if (core != null) {
 162                 throw new SAGetoptException("Unnecessary argument: --core");
 163             } else if (remote != null) {
 164                 throw new SAGetoptException("Unnecessary argument: --remote");
 165             } else if (!pid.matches("^\\d+$")) {
 166                 throw new SAGetoptException("Invalid pid: " + pid);
 167             }
 168 
 169             newArgs.add(pid);
 170         } else if (exe != null) {
 171             if (remote != null) {
 172                 throw new SAGetoptException("Unnecessary argument: --remote");
 173             } else if (exe.length() == 0) {
 174                 throw new SAGetoptException("You have to set --exe.");
 175             }
 176 
 177             newArgs.add(exe);
 178 
 179             if ((core == null) || (core.length() == 0)) {
 180                 throw new SAGetoptException("You have to set --core.");
 181             }
 182 
 183             newArgs.add(core);
 184         } else if (remote != null) {
 185             newArgs.add(remote);
 186         }
 187     }
 188 
 189     private static void runCLHSDB(String[] oldArgs) {
 190         SAGetopt sg = new SAGetopt(oldArgs);
 191         String[] longOpts = {"exe=", "core=", "pid="};
 192 
 193         ArrayList<String> newArgs = new ArrayList();
 194         String pid = null;
 195         String exe = null;
 196         String core = null;
 197         String s = null;
 198 
 199         while((s = sg.next(null, longOpts)) != null) {
 200             if (s.equals("exe")) {
 201                 exe = sg.getOptarg();
 202                 continue;
 203             }
 204             if (s.equals("core")) {
 205                 core = sg.getOptarg();
 206                 continue;
 207             }
 208             if (s.equals("pid")) {
 209                 pid = sg.getOptarg();
 210                 continue;
 211             }
 212         }
 213 
 214         buildAttachArgs(newArgs, pid, exe, core, null, true);
 215         CLHSDB.main(newArgs.toArray(new String[newArgs.size()]));
 216     }
 217 
 218     private static void runHSDB(String[] oldArgs) {
 219         SAGetopt sg = new SAGetopt(oldArgs);
 220         String[] longOpts = {"exe=", "core=", "pid="};
 221 
 222         ArrayList<String> newArgs = new ArrayList();
 223         String pid = null;
 224         String exe = null;
 225         String core = null;
 226         String s = null;
 227 
 228         while((s = sg.next(null, longOpts)) != null) {
 229             if (s.equals("exe")) {
 230                 exe = sg.getOptarg();
 231                 continue;
 232             }
 233             if (s.equals("core")) {
 234                 core = sg.getOptarg();
 235                 continue;
 236             }
 237             if (s.equals("pid")) {
 238                 pid = sg.getOptarg();
 239                 continue;
 240             }
 241         }
 242 
 243         buildAttachArgs(newArgs, pid, exe, core, null, true);
 244         HSDB.main(newArgs.toArray(new String[newArgs.size()]));
 245     }
 246 
 247     private static void runJSTACK(String[] oldArgs) {
 248         SAGetopt sg = new SAGetopt(oldArgs);
 249         String[] longOpts = {"exe=", "core=", "pid=", "remote=",
 250                                  "mixed", "locks"};
 251 
 252         ArrayList<String> newArgs = new ArrayList();
 253         String pid = null;
 254         String exe = null;
 255         String core = null;
 256         String remote = null;
 257         String s = null;
 258 
 259         while((s = sg.next(null, longOpts)) != null) {
 260             if (s.equals("exe")) {
 261                 exe = sg.getOptarg();
 262                 continue;
 263             }
 264             if (s.equals("core")) {
 265                 core = sg.getOptarg();
 266                 continue;
 267             }
 268             if (s.equals("pid")) {
 269                 pid = sg.getOptarg();
 270                 continue;
 271             }
 272             if (s.equals("remote")) {
 273                 remote = sg.getOptarg();
 274                 continue;
 275             }
 276             if (s.equals("mixed")) {
 277                 newArgs.add("-m");
 278                 continue;
 279             }
 280             if (s.equals("locks")) {
 281                 newArgs.add("-l");
 282                 continue;
 283             }
 284         }
 285 
 286         buildAttachArgs(newArgs, pid, exe, core, remote, false);
 287         JStack jstack = new JStack(false, false);
 288         jstack.runWithArgs(newArgs.toArray(new String[newArgs.size()]));
 289     }
 290 
 291     private static void runJMAP(String[] oldArgs) {
 292         SAGetopt sg = new SAGetopt(oldArgs);
 293         String[] longOpts = {"exe=", "core=", "pid=", "remote=",
 294               "heap", "binaryheap", "dumpfile=", "histo", "clstats", "finalizerinfo"};
 295 
 296         ArrayList<String> newArgs = new ArrayList();
 297         String pid = null;
 298         String exe = null;
 299         String core = null;
 300         String remote = null;
 301         String s = null;
 302         String dumpfile = null;
 303         boolean requestHeapdump = false;
 304 
 305         while((s = sg.next(null, longOpts)) != null) {
 306             if (s.equals("exe")) {
 307                 exe = sg.getOptarg();
 308                 continue;
 309             }
 310             if (s.equals("core")) {
 311                 core = sg.getOptarg();
 312                 continue;
 313             }
 314             if (s.equals("pid")) {
 315                 pid = sg.getOptarg();
 316                 continue;
 317             }
 318             if (s.equals("remote")) {
 319                 remote = sg.getOptarg();
 320                 continue;
 321             }
 322             if (s.equals("heap")) {
 323                 newArgs.add("-heap");
 324                 continue;
 325             }
 326             if (s.equals("binaryheap")) {
 327                 requestHeapdump = true;
 328                 continue;
 329             }
 330             if (s.equals("dumpfile")) {
 331                 dumpfile = sg.getOptarg();
 332                 continue;
 333             }
 334             if (s.equals("histo")) {
 335                 newArgs.add("-histo");
 336                 continue;
 337             }
 338             if (s.equals("clstats")) {
 339                 newArgs.add("-clstats");
 340                 continue;
 341             }
 342             if (s.equals("finalizerinfo")) {
 343                 newArgs.add("-finalizerinfo");
 344                 continue;
 345             }
 346         }
 347 
 348         if (!requestHeapdump && (dumpfile != null)) {
 349             throw new IllegalArgumentException("Unexpected argument dumpfile");
 350         }
 351         if (requestHeapdump) {
 352             if (dumpfile == null) {
 353                 newArgs.add("-heap:format=b");
 354             } else {
 355                 newArgs.add("-heap:format=b,file=" + dumpfile);
 356             }
 357         }
 358 
 359         buildAttachArgs(newArgs, pid, exe, core, remote, false);
 360         JMap.main(newArgs.toArray(new String[newArgs.size()]));
 361     }
 362 
 363     private static void runJINFO(String[] oldArgs) {
 364         SAGetopt sg = new SAGetopt(oldArgs);
 365         String[] longOpts = {"exe=", "core=", "pid=", "remote=",
 366                                      "flags", "sysprops"};
 367 
 368         ArrayList<String> newArgs = new ArrayList();
 369         String exe = null;
 370         String pid = null;
 371         String core = null;
 372         String remote = null;
 373         String s = null;
 374 
 375         while((s = sg.next(null, longOpts)) != null) {
 376             if (s.equals("exe")) {
 377                 exe = sg.getOptarg();
 378                 continue;
 379             }
 380             if (s.equals("core")) {
 381                 core = sg.getOptarg();
 382                 continue;
 383             }
 384             if (s.equals("pid")) {
 385                 pid = sg.getOptarg();
 386                 continue;
 387             }
 388             if (s.equals("remote")) {
 389                 remote = sg.getOptarg();
 390                 continue;
 391             }
 392             if (s.equals("flags")) {
 393                 newArgs.add("-flags");
 394                 continue;
 395             }
 396             if (s.equals("sysprops")) {
 397                 newArgs.add("-sysprops");
 398                 continue;
 399             }
 400         }
 401 
 402         buildAttachArgs(newArgs, pid, exe, core, remote, false);
 403         JInfo.main(newArgs.toArray(new String[newArgs.size()]));
 404     }
 405 
 406     private static void runJSNAP(String[] oldArgs) {
 407         SAGetopt sg = new SAGetopt(oldArgs);
 408         String[] longOpts = {"exe=", "core=", "pid=", "remote=", "all"};
 409 
 410         ArrayList<String> newArgs = new ArrayList();
 411         String exe = null;
 412         String pid = null;
 413         String core = null;
 414         String remote = null;
 415         String s = null;
 416 
 417         while((s = sg.next(null, longOpts)) != null) {
 418             if (s.equals("exe")) {
 419                 exe = sg.getOptarg();
 420                 continue;
 421             }
 422             if (s.equals("core")) {
 423                 core = sg.getOptarg();
 424                 continue;
 425             }
 426             if (s.equals("pid")) {
 427                 pid = sg.getOptarg();
 428                 continue;
 429             }
 430             if (s.equals("remote")) {
 431                 remote = sg.getOptarg();
 432                 continue;
 433             }
 434             if (s.equals("all")) {
 435                 newArgs.add("-a");
 436                 continue;
 437             }
 438         }
 439 
 440         buildAttachArgs(newArgs, pid, exe, core, remote, false);
 441         JSnap.main(newArgs.toArray(new String[newArgs.size()]));
 442     }
 443 
 444     private static void runDEBUGD(String[] oldArgs) {
 445         // By default SA agent classes prefer Windows process debugger
 446         // to windbg debugger. SA expects special properties to be set
 447         // to choose other debuggers. We will set those here before
 448         // attaching to SA agent.
 449         System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true");
 450 
 451         SAGetopt sg = new SAGetopt(oldArgs);
 452         String[] longOpts = {"exe=", "core=", "pid=", "serverid="};
 453 
 454         ArrayList<String> newArgs = new ArrayList<>();
 455         String exe = null;
 456         String pid = null;
 457         String core = null;
 458         String s = null;
 459         String serverid = null;
 460 
 461         while((s = sg.next(null, longOpts)) != null) {
 462           if (s.equals("exe")) {
 463               exe = sg.getOptarg();
 464               continue;
 465           }
 466           if (s.equals("core")) {
 467               core = sg.getOptarg();
 468               continue;
 469           }
 470           if (s.equals("pid")) {
 471               pid = sg.getOptarg();
 472               continue;
 473           }
 474           if (s.equals("serverid")) {
 475               serverid = sg.getOptarg();
 476               continue;
 477           }
 478         }
 479 
 480         buildAttachArgs(newArgs, pid, exe, core, null, false);
 481         if (serverid != null) {
 482             newArgs.add(serverid);
 483         }
 484 
 485         // delegate to the actual SA debug server.
 486         sun.jvm.hotspot.DebugServer.main(newArgs.toArray(new String[newArgs.size()]));
 487     }
 488 
 489     public static void main(String[] args) {
 490         // Provide a help
 491         if (args.length == 0) {
 492             launcherHelp();
 493             return;
 494         }
 495         // No arguments imply help for debugd, jstack, jmap, jinfo but launch clhsdb and hsdb
 496         if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) {
 497             toolHelp(args[0]);
 498             return;
 499         }
 500 


< prev index next >