Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java @ 8103:5ed317b25e23
7165259: Remove BugSpot
Reviewed-by: coleenp, mgronlun
author | sla |
---|---|
date | Fri, 22 Feb 2013 10:03:02 +0100 |
parents | da91efe96a93 |
children | 39432a1cefdd |
rev | line source |
---|---|
0 | 1 /* |
6163 | 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
218
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
218
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:
218
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.code.*; | |
30 import sun.jvm.hotspot.interpreter.*; | |
31 import sun.jvm.hotspot.debugger.*; | |
32 import sun.jvm.hotspot.debugger.cdbg.*; | |
33 import sun.jvm.hotspot.oops.*; | |
34 import sun.jvm.hotspot.runtime.*; | |
35 | |
36 public class PStack extends Tool { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6163
diff
changeset
|
37 // in non-verbose mode, Method*s are not printed in java frames |
0 | 38 public PStack(boolean v, boolean concurrentLocks) { |
39 this.verbose = v; | |
40 this.concurrentLocks = concurrentLocks; | |
41 } | |
42 | |
43 public PStack() { | |
44 this(true, true); | |
45 } | |
46 | |
47 public void run() { | |
48 run(System.out); | |
49 } | |
50 | |
51 public void run(PrintStream out) { | |
52 Debugger dbg = getAgent().getDebugger(); | |
8103 | 53 run(out, dbg); |
0 | 54 } |
55 | |
56 public void run(PrintStream out, Debugger dbg) { | |
57 CDebugger cdbg = dbg.getCDebugger(); | |
58 if (cdbg != null) { | |
59 ConcurrentLocksPrinter concLocksPrinter = null; | |
8103 | 60 // compute and cache java Vframes. |
61 initJFrameCache(); | |
62 if (concurrentLocks) { | |
63 concLocksPrinter = new ConcurrentLocksPrinter(); | |
64 } | |
65 // print Java level deadlocks | |
66 try { | |
67 DeadlockDetector.print(out); | |
68 } catch (Exception exp) { | |
69 out.println("can't print deadlock information: " + exp.getMessage()); | |
0 | 70 } |
71 | |
72 List l = cdbg.getThreadList(); | |
73 final boolean cdbgCanDemangle = cdbg.canDemangle(); | |
74 for (Iterator itr = l.iterator() ; itr.hasNext();) { | |
75 ThreadProxy th = (ThreadProxy) itr.next(); | |
76 try { | |
77 CFrame f = cdbg.topFrameForThread(th); | |
78 out.print("----------------- "); | |
79 out.print(th); | |
80 out.println(" -----------------"); | |
81 while (f != null) { | |
82 ClosestSymbol sym = f.closestSymbolToPC(); | |
83 Address pc = f.pc(); | |
218
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
0
diff
changeset
|
84 out.print(pc + "\t"); |
0 | 85 if (sym != null) { |
86 String name = sym.getName(); | |
87 if (cdbgCanDemangle) { | |
88 name = cdbg.demangle(name); | |
89 } | |
218
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
0
diff
changeset
|
90 out.print(name); |
0 | 91 long diff = sym.getOffset(); |
92 if (diff != 0L) { | |
93 out.print(" + 0x" + Long.toHexString(diff)); | |
94 } | |
95 out.println(); | |
96 } else { | |
8103 | 97 // look for one or more java frames |
98 String[] names = null; | |
99 // check interpreter frame | |
100 Interpreter interp = VM.getVM().getInterpreter(); | |
101 if (interp.contains(pc)) { | |
102 names = getJavaNames(th, f.localVariableBase()); | |
103 // print codelet name if we can't determine method | |
104 if (names == null || names.length == 0) { | |
105 out.print("<interpreter> "); | |
106 InterpreterCodelet ic = interp.getCodeletContaining(pc); | |
107 if (ic != null) { | |
108 String desc = ic.getDescription(); | |
109 if (desc != null) out.print(desc); | |
110 } | |
111 out.println(); | |
112 } | |
113 } else { | |
114 // look for known code blobs | |
115 CodeCache c = VM.getVM().getCodeCache(); | |
116 if (c.contains(pc)) { | |
117 CodeBlob cb = c.findBlobUnsafe(pc); | |
118 if (cb.isNMethod()) { | |
119 names = getJavaNames(th, f.localVariableBase()); | |
120 // just print compiled code, if can't determine method | |
121 if (names == null || names.length == 0) { | |
122 out.println("<Unknown compiled code>"); | |
123 } | |
124 } else if (cb.isBufferBlob()) { | |
125 out.println("<StubRoutines>"); | |
126 } else if (cb.isRuntimeStub()) { | |
127 out.println("<RuntimeStub>"); | |
128 } else if (cb.isDeoptimizationStub()) { | |
129 out.println("<DeoptimizationStub>"); | |
130 } else if (cb.isUncommonTrapStub()) { | |
131 out.println("<UncommonTrap>"); | |
132 } else if (cb.isExceptionStub()) { | |
133 out.println("<ExceptionStub>"); | |
134 } else if (cb.isSafepointStub()) { | |
135 out.println("<SafepointStub>"); | |
136 } else { | |
137 out.println("<Unknown code blob>"); | |
138 } | |
139 } else { | |
140 printUnknown(out); | |
141 } | |
142 } | |
143 // print java frames, if any | |
144 if (names != null && names.length != 0) { | |
145 // print java frame(s) | |
146 for (int i = 0; i < names.length; i++) { | |
147 out.println(names[i]); | |
148 } | |
149 } | |
0 | 150 } |
6163 | 151 f = f.sender(th); |
0 | 152 } |
153 } catch (Exception exp) { | |
154 exp.printStackTrace(); | |
155 // continue, may be we can do a better job for other threads | |
156 } | |
8103 | 157 if (concurrentLocks) { |
0 | 158 JavaThread jthread = (JavaThread) proxyToThread.get(th); |
159 if (jthread != null) { | |
160 concLocksPrinter.print(jthread, out); | |
161 } | |
162 } | |
163 } // for threads | |
164 } else { | |
165 if (getDebugeeType() == DEBUGEE_REMOTE) { | |
166 out.println("remote configuration is not yet implemented"); | |
167 } else { | |
168 out.println("not yet implemented (debugger does not support CDebugger)!"); | |
169 } | |
170 } | |
171 } | |
172 | |
173 public static void main(String[] args) throws Exception { | |
174 PStack t = new PStack(); | |
175 t.start(args); | |
176 t.stop(); | |
177 } | |
178 | |
179 // -- Internals only below this point | |
180 private Map jframeCache; // Map<ThreadProxy, JavaVFrame[]> | |
181 private Map proxyToThread; // Map<ThreadProxy, JavaThread> | |
182 private PrintStream out; | |
183 private boolean verbose; | |
184 private boolean concurrentLocks; | |
185 | |
186 private void initJFrameCache() { | |
187 // cache frames for subsequent reference | |
188 jframeCache = new HashMap(); | |
189 proxyToThread = new HashMap(); | |
190 Threads threads = VM.getVM().getThreads(); | |
191 for (JavaThread cur = threads.first(); cur != null; cur = cur.next()) { | |
192 List tmp = new ArrayList(10); | |
193 try { | |
194 for (JavaVFrame vf = cur.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) { | |
195 tmp.add(vf); | |
196 } | |
197 } catch (Exception exp) { | |
198 // may be we may get frames for other threads, continue | |
199 // after printing stack trace. | |
200 exp.printStackTrace(); | |
201 } | |
202 JavaVFrame[] jvframes = new JavaVFrame[tmp.size()]; | |
203 System.arraycopy(tmp.toArray(), 0, jvframes, 0, jvframes.length); | |
204 jframeCache.put(cur.getThreadProxy(), jvframes); | |
205 proxyToThread.put(cur.getThreadProxy(), cur); | |
206 } | |
207 } | |
208 | |
218
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
0
diff
changeset
|
209 private void printUnknown(PrintStream out) { |
a5838065ab24
6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents:
0
diff
changeset
|
210 out.println("\t????????"); |
0 | 211 } |
212 | |
213 private String[] getJavaNames(ThreadProxy th, Address fp) { | |
214 if (fp == null) { | |
215 return null; | |
216 } | |
217 JavaVFrame[] jvframes = (JavaVFrame[]) jframeCache.get(th); | |
218 if (jvframes == null) return null; // not a java thread | |
219 List names = new ArrayList(10); | |
220 for (int fCount = 0; fCount < jvframes.length; fCount++) { | |
221 JavaVFrame vf = jvframes[fCount]; | |
222 Frame f = vf.getFrame(); | |
223 if (fp.equals(f.getFP())) { | |
224 StringBuffer sb = new StringBuffer(); | |
225 Method method = vf.getMethod(); | |
226 // a special char to identify java frames in output | |
227 sb.append("* "); | |
228 sb.append(method.externalNameAndSignature()); | |
229 sb.append(" bci:" + vf.getBCI()); | |
230 int lineNumber = method.getLineNumberFromBCI(vf.getBCI()); | |
231 if (lineNumber != -1) { | |
232 sb.append(" line:" + lineNumber); | |
233 } | |
234 | |
235 if (verbose) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6163
diff
changeset
|
236 sb.append(" Method*:" + method.getAddress()); |
0 | 237 } |
238 | |
239 if (vf.isCompiledFrame()) { | |
240 sb.append(" (Compiled frame"); | |
241 if (vf.isDeoptimized()) { | |
242 sb.append(" [deoptimized]"); | |
243 } | |
244 } else if (vf.isInterpretedFrame()) { | |
245 sb.append(" (Interpreted frame"); | |
246 } | |
247 if (vf.mayBeImpreciseDbg()) { | |
248 sb.append("; information may be imprecise"); | |
249 } | |
250 sb.append(")"); | |
251 names.add(sb.toString()); | |
252 } | |
253 } | |
254 String[] res = new String[names.size()]; | |
255 System.arraycopy(names.toArray(), 0, res, 0, res.length); | |
256 return res; | |
257 } | |
258 } |