< prev index next >

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

Print this page




  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 package sun.jvm.hotspot;
  26 
  27 import java.util.ArrayList;
  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 
  34 public class SALauncher {
  35 
  36     private static boolean launcherHelp() {
  37         System.out.println("    clhsdb       \tcommand line debugger");
  38         System.out.println("    hsdb         \tui debugger");
  39         System.out.println("    jstack --help\tto get more information");
  40         System.out.println("    jmap   --help\tto get more information");
  41         System.out.println("    jinfo  --help\tto get more information");

  42         return false;
  43     }
  44 
  45     private static boolean commonHelp() {
  46         // --pid <pid>
  47         // --exe <exe>
  48         // --core <core>
  49         System.out.println("    --exe\texecutable image name");
  50         System.out.println("    --core\tpath to coredump");
  51         System.out.println("    --pid\tpid of process to attach");
  52         return false;
  53     }
  54 
  55     private static boolean jinfoHelp() {
  56         // --flags -> -flags
  57         // --sysprops -> -sysprops
  58         System.out.println("    --flags\tto print VM flags");
  59         System.out.println("    --sysprops\tto print Java System properties");
  60         System.out.println("    <no option>\tto print both of the above");
  61         return commonHelp();


  68         // --clstats -> -clstats
  69         // --finalizerinfo -> -finalizerinfo
  70 
  71         System.out.println("    <no option>\tto print same info as Solaris pmap");
  72         System.out.println("    --heap\tto print java heap summary");
  73         System.out.println("    --binaryheap\tto dump java heap in hprof binary format");
  74         System.out.println("    --histo\tto print histogram of java object heap");
  75         System.out.println("    --clstats\tto print class loader statistics");
  76         System.out.println("    --finalizerinfo\tto print information on objects awaiting finalization");
  77         return commonHelp();
  78     }
  79 
  80     private static boolean jstackHelp() {
  81         // --locks -> -l
  82         // --mixed -> -m
  83         System.out.println("    --locks\tto print java.util.concurrent locks");
  84         System.out.println("    --mixed\tto print both java and native frames (mixed mode)");
  85         return commonHelp();
  86     }
  87 





  88     private static boolean toolHelp(String toolName) {
  89         if (toolName.equals("jstack")) {
  90             return jstackHelp();
  91         }
  92         if (toolName.equals("jinfo")) {
  93             return jinfoHelp();
  94         }
  95         if (toolName.equals("jmap")) {
  96             return jmapHelp();
  97         }



  98         if (toolName.equals("hsdb") || toolName.equals("clhsdb")) {
  99             return commonHelp();
 100         }
 101         return launcherHelp();
 102     }
 103 
 104     private static void runCLHSDB(String[] oldArgs) {
 105         SAGetopt sg = new SAGetopt(oldArgs);
 106         String[] longOpts = {"exe=", "core=", "pid="};
 107 
 108         ArrayList<String> newArgs = new ArrayList();
 109         String exeORpid = null;
 110         String core = null;
 111         String s = null;
 112 
 113         while((s = sg.next(null, longOpts)) != null) {
 114             if (s.equals("exe")) {
 115                 exeORpid = sg.getOptarg();
 116                 continue;
 117             }


 291             if (s.equals("flags")) {
 292                 newArgs.add("-flags");
 293                 continue;
 294             }
 295             if (s.equals("sysprops")) {
 296                 newArgs.add("-sysprops");
 297                 continue;
 298             }
 299         }
 300 
 301         if (exeORpid != null) {
 302             newArgs.add(exeORpid);
 303             if (core != null) {
 304                 newArgs.add(core);
 305             }
 306         }
 307 
 308         JInfo.main(newArgs.toArray(new String[newArgs.size()]));
 309     }
 310 


































 311     public static void main(String[] args) {
 312         // Provide a help
 313         if (args.length == 0) {
 314             launcherHelp();
 315             return;
 316         }
 317         // No arguments imply help for jstack, jmap, jinfo but launch clhsdb and hsdb
 318         if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) {
 319             toolHelp(args[0]);
 320             return;
 321         }
 322 
 323         for (String arg : args) {
 324             if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) {
 325                 toolHelp(args[0]);
 326                 return;
 327             }
 328         }
 329 
 330         String[] oldArgs = Arrays.copyOfRange(args, 1, args.length);


 336         }
 337 
 338         if (args[0].equals("hsdb")) {
 339             runHSDB(oldArgs);
 340             return;
 341         }
 342 
 343         // Run SA tmtools mode
 344         if (args[0].equals("jstack")) {
 345             runJSTACK(oldArgs);
 346             return;
 347         }
 348 
 349         if (args[0].equals("jmap")) {
 350             runJMAP(oldArgs);
 351             return;
 352         }
 353 
 354         if (args[0].equals("jinfo")) {
 355             runJINFO(oldArgs);





 356             return;
 357         }
 358     }
 359 }


  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 package sun.jvm.hotspot;
  26 
  27 import java.util.ArrayList;
  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("    jstack --help\tto get more information");
  41         System.out.println("    jmap   --help\tto get more information");
  42         System.out.println("    jinfo  --help\tto get more information");
  43         System.out.println("    jsnap  --help\tto get more information");
  44         return false;
  45     }
  46 
  47     private static boolean commonHelp() {
  48         // --pid <pid>
  49         // --exe <exe>
  50         // --core <core>
  51         System.out.println("    --exe\texecutable image name");
  52         System.out.println("    --core\tpath to coredump");
  53         System.out.println("    --pid\tpid of process to attach");
  54         return false;
  55     }
  56 
  57     private static boolean jinfoHelp() {
  58         // --flags -> -flags
  59         // --sysprops -> -sysprops
  60         System.out.println("    --flags\tto print VM flags");
  61         System.out.println("    --sysprops\tto print Java System properties");
  62         System.out.println("    <no option>\tto print both of the above");
  63         return commonHelp();


  70         // --clstats -> -clstats
  71         // --finalizerinfo -> -finalizerinfo
  72 
  73         System.out.println("    <no option>\tto print same info as Solaris pmap");
  74         System.out.println("    --heap\tto print java heap summary");
  75         System.out.println("    --binaryheap\tto dump java heap in hprof binary format");
  76         System.out.println("    --histo\tto print histogram of java object heap");
  77         System.out.println("    --clstats\tto print class loader statistics");
  78         System.out.println("    --finalizerinfo\tto print information on objects awaiting finalization");
  79         return commonHelp();
  80     }
  81 
  82     private static boolean jstackHelp() {
  83         // --locks -> -l
  84         // --mixed -> -m
  85         System.out.println("    --locks\tto print java.util.concurrent locks");
  86         System.out.println("    --mixed\tto print both java and native frames (mixed mode)");
  87         return commonHelp();
  88     }
  89 
  90     private static boolean jsnapHelp() {
  91         System.out.println(" <no option>\tdump perfromance counters");
  92         return commonHelp();
  93     }
  94 
  95     private static boolean toolHelp(String toolName) {
  96         if (toolName.equals("jstack")) {
  97             return jstackHelp();
  98         }
  99         if (toolName.equals("jinfo")) {
 100             return jinfoHelp();
 101         }
 102         if (toolName.equals("jmap")) {
 103             return jmapHelp();
 104         }
 105         if (toolName.equals("jsnap")) {
 106             return jsnapHelp();
 107         }
 108         if (toolName.equals("hsdb") || toolName.equals("clhsdb")) {
 109             return commonHelp();
 110         }
 111         return launcherHelp();
 112     }
 113 
 114     private static void runCLHSDB(String[] oldArgs) {
 115         SAGetopt sg = new SAGetopt(oldArgs);
 116         String[] longOpts = {"exe=", "core=", "pid="};
 117 
 118         ArrayList<String> newArgs = new ArrayList();
 119         String exeORpid = null;
 120         String core = null;
 121         String s = null;
 122 
 123         while((s = sg.next(null, longOpts)) != null) {
 124             if (s.equals("exe")) {
 125                 exeORpid = sg.getOptarg();
 126                 continue;
 127             }


 301             if (s.equals("flags")) {
 302                 newArgs.add("-flags");
 303                 continue;
 304             }
 305             if (s.equals("sysprops")) {
 306                 newArgs.add("-sysprops");
 307                 continue;
 308             }
 309         }
 310 
 311         if (exeORpid != null) {
 312             newArgs.add(exeORpid);
 313             if (core != null) {
 314                 newArgs.add(core);
 315             }
 316         }
 317 
 318         JInfo.main(newArgs.toArray(new String[newArgs.size()]));
 319     }
 320 
 321     private static void runJSNAP(String[] oldArgs) {
 322         SAGetopt sg = new SAGetopt(oldArgs);
 323         String[] longOpts = {"exe=", "core=", "pid="};
 324 
 325         ArrayList<String> newArgs = new ArrayList();
 326         String exeORpid = null;
 327         String core = null;
 328         String s = null;
 329 
 330         while((s = sg.next(null, longOpts)) != null) {
 331             if (s.equals("exe")) {
 332                 exeORpid = sg.getOptarg();
 333                 continue;
 334             }
 335             if (s.equals("core")) {
 336                 core = sg.getOptarg();
 337                 continue;
 338             }
 339             if (s.equals("pid")) {
 340                 exeORpid = sg.getOptarg();
 341                 continue;
 342             }
 343         }
 344 
 345         if (exeORpid != null) {
 346             newArgs.add(exeORpid);
 347             if (core != null) {
 348                 newArgs.add(core);
 349             }
 350         }
 351 
 352         JSnap.main(newArgs.toArray(new String[newArgs.size()]));
 353     }
 354 
 355     public static void main(String[] args) {
 356         // Provide a help
 357         if (args.length == 0) {
 358             launcherHelp();
 359             return;
 360         }
 361         // No arguments imply help for jstack, jmap, jinfo but launch clhsdb and hsdb
 362         if (args.length == 1 && !args[0].equals("clhsdb") && !args[0].equals("hsdb")) {
 363             toolHelp(args[0]);
 364             return;
 365         }
 366 
 367         for (String arg : args) {
 368             if (arg.equals("-h") || arg.equals("-help") || arg.equals("--help")) {
 369                 toolHelp(args[0]);
 370                 return;
 371             }
 372         }
 373 
 374         String[] oldArgs = Arrays.copyOfRange(args, 1, args.length);


 380         }
 381 
 382         if (args[0].equals("hsdb")) {
 383             runHSDB(oldArgs);
 384             return;
 385         }
 386 
 387         // Run SA tmtools mode
 388         if (args[0].equals("jstack")) {
 389             runJSTACK(oldArgs);
 390             return;
 391         }
 392 
 393         if (args[0].equals("jmap")) {
 394             runJMAP(oldArgs);
 395             return;
 396         }
 397 
 398         if (args[0].equals("jinfo")) {
 399             runJINFO(oldArgs);
 400             return;
 401         }
 402 
 403         if (args[0].equals("jsnap")) {
 404             runJSNAP(oldArgs);
 405             return;
 406         }
 407     }
 408 }
< prev index next >