author | rehn |
Tue, 21 May 2019 10:34:57 +0200 | |
changeset 54955 | 46409371a691 |
parent 48113 | af9e4669ca18 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54955
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
48113
diff
changeset
|
2 |
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.tools; |
|
26 |
||
27 |
import sun.jvm.hotspot.debugger.*; |
|
28 |
import sun.jvm.hotspot.runtime.*; |
|
29 |
import sun.jvm.hotspot.oops.*; |
|
30 |
||
31 |
/** Traverses and prints the stack traces for all Java threads in the |
|
32 |
* remote VM */ |
|
33 |
public class StackTrace extends Tool { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5547
diff
changeset
|
34 |
// in non-verbose mode pc, sp and Method* are not printed |
1 | 35 |
public StackTrace(boolean v, boolean concurrentLocks) { |
36 |
this.verbose = v; |
|
37 |
this.concurrentLocks = concurrentLocks; |
|
38 |
} |
|
39 |
||
40 |
public StackTrace() { |
|
41 |
this(true, true); |
|
42 |
} |
|
43 |
||
44 |
public void run() { |
|
45 |
run(System.out); |
|
46 |
} |
|
47 |
||
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
48 |
public StackTrace(JVMDebugger d) { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
49 |
super(d); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
50 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
51 |
|
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
52 |
public StackTrace(JVMDebugger d, boolean v, boolean concurrentLocks) { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
53 |
super(d); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
54 |
this.verbose = v; |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
55 |
this.concurrentLocks = concurrentLocks; |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
56 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
13728
diff
changeset
|
57 |
|
1 | 58 |
public void run(java.io.PrintStream tty) { |
59 |
// Ready to go with the database... |
|
60 |
try { |
|
61 |
// print deadlock information before stack trace |
|
62 |
DeadlockDetector.print(tty); |
|
63 |
} catch (Exception exp) { |
|
64 |
exp.printStackTrace(); |
|
65 |
tty.println("Can't print deadlocks:" + exp.getMessage()); |
|
66 |
} |
|
67 |
||
68 |
try { |
|
69 |
ConcurrentLocksPrinter concLocksPrinter = null; |
|
70 |
if (concurrentLocks) { |
|
71 |
concLocksPrinter = new ConcurrentLocksPrinter(); |
|
72 |
} |
|
73 |
Threads threads = VM.getVM().getThreads(); |
|
54955
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
48113
diff
changeset
|
74 |
for (int i = 0; i < threads.getNumberOfThreads(); i++) { |
46409371a691
8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents:
48113
diff
changeset
|
75 |
JavaThread cur = threads.getJavaThreadAt(i); |
1 | 76 |
if (cur.isJavaThread()) { |
46636 | 77 |
cur.printThreadInfoOn(tty); |
1 | 78 |
try { |
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
47216
diff
changeset
|
79 |
int count = 0; |
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
47216
diff
changeset
|
80 |
|
1 | 81 |
for (JavaVFrame vf = cur.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) { |
82 |
Method method = vf.getMethod(); |
|
83 |
tty.print(" - " + method.externalNameAndSignature() + |
|
84 |
" @bci=" + vf.getBCI()); |
|
85 |
||
86 |
int lineNumber = method.getLineNumberFromBCI(vf.getBCI()); |
|
87 |
if (lineNumber != -1) { |
|
88 |
tty.print(", line=" + lineNumber); |
|
89 |
} |
|
90 |
||
91 |
if (verbose) { |
|
92 |
Address pc = vf.getFrame().getPC(); |
|
93 |
if (pc != null) { |
|
94 |
tty.print(", pc=" + pc); |
|
95 |
} |
|
96 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
5547
diff
changeset
|
97 |
tty.print(", Method*=" + method.getAddress()); |
1 | 98 |
} |
99 |
||
100 |
if (vf.isCompiledFrame()) { |
|
101 |
tty.print(" (Compiled frame"); |
|
102 |
if (vf.isDeoptimized()) { |
|
103 |
tty.print(" [deoptimized]"); |
|
104 |
} |
|
105 |
} |
|
106 |
if (vf.isInterpretedFrame()) { |
|
107 |
tty.print(" (Interpreted frame"); |
|
108 |
} |
|
109 |
if (vf.mayBeImpreciseDbg()) { |
|
110 |
tty.print("; information may be imprecise"); |
|
111 |
} |
|
112 |
||
113 |
tty.println(")"); |
|
48113
af9e4669ca18
8185796: jstack and clhsdb jstack should show lock objects
ysuenaga
parents:
47216
diff
changeset
|
114 |
vf.printLockInfo(tty, count++); |
1 | 115 |
} |
116 |
} catch (Exception e) { |
|
117 |
tty.println("Error occurred during stack walking:"); |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
120 |
tty.println(); |
|
121 |
if (concurrentLocks) { |
|
122 |
concLocksPrinter.print(cur, tty); |
|
123 |
} |
|
124 |
tty.println(); |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
catch (AddressException e) { |
|
129 |
System.err.println("Error accessing address 0x" + Long.toHexString(e.getAddress())); |
|
130 |
e.printStackTrace(); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
public static void main(String[] args) { |
|
135 |
StackTrace st = new StackTrace(); |
|
21065
b8281f54308b
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
18481
diff
changeset
|
136 |
st.execute(args); |
1 | 137 |
} |
138 |
||
139 |
private boolean verbose; |
|
140 |
private boolean concurrentLocks; |
|
141 |
} |