0
|
1 /*
|
|
2 * Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.tools;
|
|
26
|
|
27 public class JStack extends Tool {
|
|
28 public JStack(boolean mixedMode, boolean concurrentLocks) {
|
|
29 this.mixedMode = mixedMode;
|
|
30 this.concurrentLocks = concurrentLocks;
|
|
31 }
|
|
32
|
|
33 public JStack() {
|
|
34 this(true, true);
|
|
35 }
|
|
36
|
|
37 protected boolean needsJavaPrefix() {
|
|
38 return false;
|
|
39 }
|
|
40
|
|
41 public String getName() {
|
|
42 return "jstack";
|
|
43 }
|
|
44
|
|
45 protected void printFlagsUsage() {
|
|
46 System.out.println(" -l\tto print java.util.concurrent locks");
|
|
47 System.out.println(" -m\tto print both java and native frames (mixed mode)");
|
|
48 super.printFlagsUsage();
|
|
49 }
|
|
50
|
|
51 public void run() {
|
|
52 Tool tool = null;
|
|
53 if (mixedMode) {
|
|
54 tool = new PStack(false, concurrentLocks);
|
|
55 } else {
|
|
56 tool = new StackTrace(false, concurrentLocks);
|
|
57 }
|
|
58 tool.setAgent(getAgent());
|
|
59 tool.setDebugeeType(getDebugeeType());
|
|
60 tool.run();
|
|
61 }
|
|
62
|
|
63 public static void main(String[] args) {
|
|
64 boolean mixedMode = false;
|
|
65 boolean concurrentLocks = false;
|
|
66 int used = 0;
|
|
67 for (int i = 0; i < args.length; i++) {
|
|
68 if (args[i].equals("-m")) {
|
|
69 mixedMode = true;
|
|
70 used++;
|
|
71 } else if (args[i].equals("-l")) {
|
|
72 concurrentLocks = true;
|
|
73 used++;
|
|
74 }
|
|
75 }
|
|
76
|
|
77 if (used != 0) {
|
|
78 String[] newArgs = new String[args.length - used];
|
|
79 for (int i = 0; i < newArgs.length; i++) {
|
|
80 newArgs[i] = args[i + used];
|
|
81 }
|
|
82 args = newArgs;
|
|
83 }
|
|
84
|
|
85 JStack jstack = new JStack(mixedMode, concurrentLocks);
|
|
86 jstack.start(args);
|
|
87 jstack.stop();
|
|
88 }
|
|
89
|
|
90 private boolean mixedMode;
|
|
91 private boolean concurrentLocks;
|
|
92 }
|