annotate agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java @ 17524:89152779163c

Merge with jdk8-b132
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 11:59:32 +0200
parents 4ca6dc0799b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17524
89152779163c Merge with jdk8-b132
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14909
diff changeset
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.tools;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 /** Traverses and prints the stack traces for all Java threads in the
a61af66fc99e Initial load
duke
parents:
diff changeset
32 * remote VM */
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class StackTrace extends Tool {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
34 // in non-verbose mode pc, sp and Method* are not printed
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public StackTrace(boolean v, boolean concurrentLocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 this.verbose = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 this.concurrentLocks = concurrentLocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public StackTrace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 this(true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 run(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
48 public StackTrace(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
49 super(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
50 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
51
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
52 public StackTrace(JVMDebugger d, boolean v, boolean concurrentLocks) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
53 super(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
54 this.verbose = v;
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
55 this.concurrentLocks = concurrentLocks;
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
56 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
57
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public void run(java.io.PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Ready to go with the database...
a61af66fc99e Initial load
duke
parents:
diff changeset
60 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // print deadlock information before stack trace
a61af66fc99e Initial load
duke
parents:
diff changeset
62 DeadlockDetector.print(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 exp.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 tty.println("Can't print deadlocks:" + exp.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 ConcurrentLocksPrinter concLocksPrinter = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (concurrentLocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 concLocksPrinter = new ConcurrentLocksPrinter();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int i = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 for (JavaThread cur = threads.first(); cur != null; cur = cur.next(), i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (cur.isJavaThread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 Address sp = cur.getLastJavaSP();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 tty.print("Thread ");
a61af66fc99e Initial load
duke
parents:
diff changeset
79 cur.printThreadIDOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 tty.print(": (state = " + cur.getThreadState());
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 tty.println(", current Java SP = " + sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 tty.println(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
85 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 for (JavaVFrame vf = cur.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Method method = vf.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 tty.print(" - " + method.externalNameAndSignature() +
a61af66fc99e Initial load
duke
parents:
diff changeset
89 " @bci=" + vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int lineNumber = method.getLineNumberFromBCI(vf.getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (lineNumber != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 tty.print(", line=" + lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 Address pc = vf.getFrame().getPC();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (pc != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 tty.print(", pc=" + pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
102 tty.print(", Method*=" + method.getAddress());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (vf.isCompiledFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 tty.print(" (Compiled frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (vf.isDeoptimized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 tty.print(" [deoptimized]");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (vf.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 tty.print(" (Interpreted frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (vf.mayBeImpreciseDbg()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 tty.print("; information may be imprecise");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 tty.println(")");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 tty.println("Error occurred during stack walking:");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 tty.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (concurrentLocks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 concLocksPrinter.print(cur, tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 tty.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 System.err.println("Error accessing address 0x" + Long.toHexString(e.getAddress()));
a61af66fc99e Initial load
duke
parents:
diff changeset
134 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 StackTrace st = new StackTrace();
12932
7fe6ef09d242 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 11054
diff changeset
140 st.execute(args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 private boolean verbose;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 private boolean concurrentLocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }