< 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();


  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             }
 118             if (s.equals("core")) {


 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        \tdump PerfCounter");
  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();


  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 toolHelp(String toolName) {
  91         if (toolName.equals("jstack")) {
  92             return jstackHelp();
  93         }
  94         if (toolName.equals("jinfo")) {
  95             return jinfoHelp();
  96         }
  97         if (toolName.equals("jmap")) {
  98             return jmapHelp();
  99         }
 100         if (toolName.equals("hsdb") || toolName.equals("clhsdb") || toolName.equals("jsnap")) {
 101             return commonHelp();
 102         }
 103         return launcherHelp();
 104     }
 105 
 106     private static void runCLHSDB(String[] oldArgs) {
 107         SAGetopt sg = new SAGetopt(oldArgs);
 108         String[] longOpts = {"exe=", "core=", "pid="};
 109 
 110         ArrayList<String> newArgs = new ArrayList();
 111         String exeORpid = null;
 112         String core = null;
 113         String s = null;
 114 
 115         while((s = sg.next(null, longOpts)) != null) {
 116             if (s.equals("exe")) {
 117                 exeORpid = sg.getOptarg();
 118                 continue;
 119             }
 120             if (s.equals("core")) {


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


 372         }
 373 
 374         if (args[0].equals("hsdb")) {
 375             runHSDB(oldArgs);
 376             return;
 377         }
 378 
 379         // Run SA tmtools mode
 380         if (args[0].equals("jstack")) {
 381             runJSTACK(oldArgs);
 382             return;
 383         }
 384 
 385         if (args[0].equals("jmap")) {
 386             runJMAP(oldArgs);
 387             return;
 388         }
 389 
 390         if (args[0].equals("jinfo")) {
 391             runJINFO(oldArgs);
 392             return;
 393         }
 394 
 395         if (args[0].equals("jsnap")) {
 396             runJSNAP(oldArgs);
 397             return;
 398         }
 399     }
 400 }
< prev index next >