Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 10801:4bfbd4be6e7a
Replace custom graph building with snippet for unsafe load lowering
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Wed, 17 Jul 2013 20:23:36 +0200 |
parents | 686916dc0439 |
children | 38ea2efa32a7 |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
2 * Copyright (c) 2005, 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:
1385
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
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:
1385
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot; | |
26 | |
8756
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
27 import java.io.BufferedOutputStream; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
28 import java.io.BufferedReader; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
29 import java.io.ByteArrayOutputStream; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
30 import java.io.FileInputStream; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
31 import java.io.FileOutputStream; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
32 import java.io.IOException; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
33 import java.io.InputStreamReader; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
34 import java.io.PrintStream; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
35 import java.util.ArrayList; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
36 import java.util.Arrays; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
37 import java.util.Comparator; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
38 import java.util.HashMap; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
39 import java.util.HashSet; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
40 import java.util.Iterator; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
41 import java.util.Stack; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
42 import java.util.regex.Matcher; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
43 import java.util.regex.Pattern; |
0 | 44 |
8756
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
45 import sun.jvm.hotspot.ci.ciEnv; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
46 import sun.jvm.hotspot.code.CodeBlob; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
47 import sun.jvm.hotspot.code.CodeCacheVisitor; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
48 import sun.jvm.hotspot.code.NMethod; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
49 import sun.jvm.hotspot.debugger.Address; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
50 import sun.jvm.hotspot.debugger.OopHandle; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
51 import sun.jvm.hotspot.memory.SymbolTable; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
52 import sun.jvm.hotspot.memory.SystemDictionary; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
53 import sun.jvm.hotspot.memory.Universe; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
54 import sun.jvm.hotspot.oops.DefaultHeapVisitor; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
55 import sun.jvm.hotspot.oops.HeapVisitor; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
56 import sun.jvm.hotspot.oops.InstanceKlass; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
57 import sun.jvm.hotspot.oops.Klass; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
58 import sun.jvm.hotspot.oops.Metadata; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
59 import sun.jvm.hotspot.oops.Method; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
60 import sun.jvm.hotspot.oops.MethodData; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
61 import sun.jvm.hotspot.oops.Oop; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
62 import sun.jvm.hotspot.oops.RawHeapVisitor; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
63 import sun.jvm.hotspot.oops.Symbol; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
64 import sun.jvm.hotspot.oops.UnknownOopException; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
65 import sun.jvm.hotspot.opto.Compile; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
66 import sun.jvm.hotspot.opto.InlineTree; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
67 import sun.jvm.hotspot.runtime.CompiledVFrame; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
68 import sun.jvm.hotspot.runtime.CompilerThread; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
69 import sun.jvm.hotspot.runtime.JavaThread; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
70 import sun.jvm.hotspot.runtime.JavaVFrame; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
71 import sun.jvm.hotspot.runtime.Threads; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
72 import sun.jvm.hotspot.runtime.VM; |
0 | 73 import sun.jvm.hotspot.tools.ObjectHistogram; |
8756
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
74 import sun.jvm.hotspot.tools.PMap; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
75 import sun.jvm.hotspot.tools.PStack; |
0 | 76 import sun.jvm.hotspot.tools.StackTrace; |
3939 | 77 import sun.jvm.hotspot.tools.jcore.ClassDump; |
78 import sun.jvm.hotspot.tools.jcore.ClassFilter; | |
8756
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
79 import sun.jvm.hotspot.types.CIntegerType; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
80 import sun.jvm.hotspot.types.Field; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
81 import sun.jvm.hotspot.types.Type; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
82 import sun.jvm.hotspot.types.basic.BasicType; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
83 import sun.jvm.hotspot.ui.classbrowser.HTMLGenerator; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
84 import sun.jvm.hotspot.ui.tree.CTypeTreeNodeAdapter; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
85 import sun.jvm.hotspot.ui.tree.OopTreeNodeAdapter; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
86 import sun.jvm.hotspot.ui.tree.SimpleTreeNode; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
87 import sun.jvm.hotspot.utilities.AddressOps; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
88 import sun.jvm.hotspot.utilities.Assert; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
89 import sun.jvm.hotspot.utilities.HeapProgressThunk; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
90 import sun.jvm.hotspot.utilities.LivenessPathElement; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
91 import sun.jvm.hotspot.utilities.MethodArray; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
92 import sun.jvm.hotspot.utilities.ObjectReader; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
93 import sun.jvm.hotspot.utilities.PointerFinder; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
94 import sun.jvm.hotspot.utilities.PointerLocation; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
95 import sun.jvm.hotspot.utilities.ReversePtrs; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
96 import sun.jvm.hotspot.utilities.ReversePtrsAnalysis; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
97 import sun.jvm.hotspot.utilities.RobustOopDeterminator; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
98 import sun.jvm.hotspot.utilities.SystemDictionaryHelper; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
99 import sun.jvm.hotspot.utilities.soql.JSJavaFactory; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
100 import sun.jvm.hotspot.utilities.soql.JSJavaFactoryImpl; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
101 import sun.jvm.hotspot.utilities.soql.JSJavaScriptEngine; |
0 | 102 |
103 public class CommandProcessor { | |
104 public abstract static class DebuggerInterface { | |
105 public abstract HotSpotAgent getAgent(); | |
106 public abstract boolean isAttached(); | |
107 public abstract void attach(String pid); | |
108 public abstract void attach(String java, String core); | |
109 public abstract void detach(); | |
110 public abstract void reattach(); | |
111 } | |
112 | |
3939 | 113 public static class BootFilter implements ClassFilter { |
114 public boolean canInclude(InstanceKlass kls) { | |
115 return kls.getClassLoader() == null; | |
116 } | |
117 } | |
118 | |
119 public static class NonBootFilter implements ClassFilter { | |
120 private HashMap emitted = new HashMap(); | |
121 public boolean canInclude(InstanceKlass kls) { | |
122 if (kls.getClassLoader() == null) return false; | |
123 if (emitted.get(kls.getName()) != null) { | |
124 // Since multiple class loaders are being shoved | |
125 // together duplicate classes are a possibilty. For | |
126 // now just ignore them. | |
127 return false; | |
128 } | |
129 emitted.put(kls.getName(), kls); | |
130 return true; | |
131 } | |
132 } | |
133 | |
0 | 134 static class Tokens { |
135 final String input; | |
136 int i; | |
137 String[] tokens; | |
138 int length; | |
139 | |
140 String[] splitWhitespace(String cmd) { | |
141 String[] t = cmd.split("\\s"); | |
142 if (t.length == 1 && t[0].length() == 0) { | |
143 return new String[0]; | |
144 } | |
145 return t; | |
146 } | |
147 | |
148 void add(String s, ArrayList t) { | |
149 if (s.length() > 0) { | |
150 t.add(s); | |
151 } | |
152 } | |
153 | |
154 Tokens(String cmd) { | |
155 input = cmd; | |
156 | |
157 // check for quoting | |
158 int quote = cmd.indexOf('"'); | |
159 ArrayList t = new ArrayList(); | |
160 if (quote != -1) { | |
161 while (cmd.length() > 0) { | |
162 if (quote != -1) { | |
163 int endquote = cmd.indexOf('"', quote + 1); | |
164 if (endquote == -1) { | |
165 throw new RuntimeException("mismatched quotes: " + input); | |
166 } | |
167 | |
168 String before = cmd.substring(0, quote).trim(); | |
169 String quoted = cmd.substring(quote + 1, endquote); | |
170 cmd = cmd.substring(endquote + 1).trim(); | |
171 if (before.length() > 0) { | |
172 String[] w = splitWhitespace(before); | |
173 for (int i = 0; i < w.length; i++) { | |
174 add(w[i], t); | |
175 } | |
176 } | |
177 add(quoted, t); | |
178 quote = cmd.indexOf('"'); | |
179 } else { | |
180 String[] w = splitWhitespace(cmd); | |
181 for (int i = 0; i < w.length; i++) { | |
182 add(w[i], t); | |
183 } | |
184 cmd = ""; | |
185 | |
186 } | |
187 } | |
188 } else { | |
189 String[] w = splitWhitespace(cmd); | |
190 for (int i = 0; i < w.length; i++) { | |
191 add(w[i], t); | |
192 } | |
193 } | |
194 tokens = (String[])t.toArray(new String[0]); | |
195 i = 0; | |
196 length = tokens.length; | |
197 | |
198 //for (int i = 0; i < tokens.length; i++) { | |
199 // System.out.println("\"" + tokens[i] + "\""); | |
200 //} | |
201 } | |
202 | |
203 String nextToken() { | |
204 return tokens[i++]; | |
205 } | |
206 boolean hasMoreTokens() { | |
207 return i < length; | |
208 } | |
209 int countTokens() { | |
210 return length - i; | |
211 } | |
212 void trim(int n) { | |
213 if (length >= n) { | |
214 length -= n; | |
215 } else { | |
216 throw new IndexOutOfBoundsException(String.valueOf(n)); | |
217 } | |
218 } | |
219 String join(String sep) { | |
220 StringBuffer result = new StringBuffer(); | |
221 for (int w = i; w < length; w++) { | |
222 result.append(tokens[w]); | |
223 if (w + 1 < length) { | |
224 result.append(sep); | |
225 } | |
226 } | |
227 return result.toString(); | |
228 } | |
229 | |
230 String at(int i) { | |
231 if (i < 0 || i >= length) { | |
232 throw new IndexOutOfBoundsException(String.valueOf(i)); | |
233 } | |
234 return tokens[i]; | |
235 } | |
236 } | |
237 | |
238 | |
239 abstract class Command { | |
240 Command(String n, String u, boolean ok) { | |
241 name = n; | |
242 usage = u; | |
243 okIfDisconnected = ok; | |
244 } | |
245 | |
246 Command(String n, boolean ok) { | |
247 name = n; | |
248 usage = n; | |
249 okIfDisconnected = ok; | |
250 } | |
251 | |
252 final String name; | |
253 final String usage; | |
254 final boolean okIfDisconnected; | |
255 abstract void doit(Tokens t); | |
256 void usage() { | |
257 out.println("Usage: " + usage); | |
258 } | |
259 | |
260 void printOopValue(Oop oop) { | |
261 if (oop != null) { | |
262 Klass k = oop.getKlass(); | |
263 Symbol s = k.getName(); | |
264 if (s != null) { | |
265 out.print("Oop for " + s.asString() + " @ "); | |
266 } else { | |
267 out.print("Oop @ "); | |
268 } | |
269 Oop.printOopAddressOn(oop, out); | |
270 } else { | |
271 out.print("null"); | |
272 } | |
273 } | |
274 | |
275 void printNode(SimpleTreeNode node) { | |
276 int count = node.getChildCount(); | |
277 for (int i = 0; i < count; i++) { | |
278 try { | |
279 SimpleTreeNode field = node.getChild(i); | |
280 if (field instanceof OopTreeNodeAdapter) { | |
281 out.print(field); | |
282 out.print(" "); | |
283 printOopValue(((OopTreeNodeAdapter)field).getOop()); | |
284 out.println(); | |
285 } else { | |
286 out.println(field); | |
287 } | |
288 } catch (Exception e) { | |
289 out.println(); | |
290 out.println("Error: " + e); | |
291 if (verboseExceptions) { | |
292 e.printStackTrace(out); | |
293 } | |
294 } | |
295 } | |
296 } | |
297 } | |
298 | |
299 void quote(String s) { | |
300 if (s.indexOf(" ") == -1) { | |
301 out.print(s); | |
302 } else { | |
303 out.print("\""); | |
304 out.print(s); | |
305 out.print("\""); | |
306 } | |
307 } | |
308 | |
309 void dumpType(Type type) { | |
310 out.print("type "); | |
311 quote(type.getName()); | |
312 out.print(" "); | |
313 if (type.getSuperclass() != null) { | |
314 quote(type.getSuperclass().getName()); | |
315 out.print(" "); | |
316 } else { | |
317 out.print("null "); | |
318 } | |
319 out.print(type.isOopType()); | |
320 out.print(" "); | |
321 if (type.isCIntegerType()) { | |
322 out.print("true "); | |
323 out.print(((CIntegerType)type).isUnsigned()); | |
324 out.print(" "); | |
325 } else { | |
326 out.print("false false "); | |
327 } | |
328 out.print(type.getSize()); | |
329 out.println(); | |
330 } | |
331 | |
332 void dumpFields(Type type) { | |
3939 | 333 dumpFields(type, true); |
334 } | |
335 | |
336 void dumpFields(Type type, boolean allowStatic) { | |
0 | 337 Iterator i = type.getFields(); |
338 while (i.hasNext()) { | |
339 Field f = (Field) i.next(); | |
3939 | 340 if (!allowStatic && f.isStatic()) continue; |
0 | 341 out.print("field "); |
342 quote(type.getName()); | |
343 out.print(" "); | |
344 out.print(f.getName()); | |
345 out.print(" "); | |
346 quote(f.getType().getName()); | |
347 out.print(" "); | |
348 out.print(f.isStatic()); | |
349 out.print(" "); | |
350 if (f.isStatic()) { | |
351 out.print("0 "); | |
352 out.print(f.getStaticFieldAddress()); | |
353 } else { | |
354 out.print(f.getOffset()); | |
355 out.print(" 0x0"); | |
356 } | |
357 out.println(); | |
358 } | |
359 } | |
360 | |
361 | |
362 Address lookup(String symbol) { | |
363 if (symbol.indexOf("::") != -1) { | |
364 String[] parts = symbol.split("::"); | |
365 StringBuffer mangled = new StringBuffer("__1c"); | |
366 for (int i = 0; i < parts.length; i++) { | |
367 int len = parts[i].length(); | |
368 if (len >= 26) { | |
369 mangled.append((char)('a' + (len / 26))); | |
370 len = len % 26; | |
371 } | |
372 mangled.append((char)('A' + len)); | |
373 mangled.append(parts[i]); | |
374 } | |
375 mangled.append("_"); | |
376 symbol = mangled.toString(); | |
377 } | |
378 return VM.getVM().getDebugger().lookup(null, symbol); | |
379 } | |
380 | |
381 Address parseAddress(String addr) { | |
382 return VM.getVM().getDebugger().parseAddress(addr); | |
383 } | |
384 | |
385 private final Command[] commandList = { | |
386 new Command("reattach", true) { | |
387 public void doit(Tokens t) { | |
388 int tokens = t.countTokens(); | |
389 if (tokens != 0) { | |
390 usage(); | |
391 return; | |
392 } | |
393 preAttach(); | |
394 debugger.reattach(); | |
395 postAttach(); | |
396 } | |
397 }, | |
398 new Command("attach", "attach pid | exec core", true) { | |
399 public void doit(Tokens t) { | |
400 int tokens = t.countTokens(); | |
401 if (tokens == 1) { | |
402 preAttach(); | |
403 debugger.attach(t.nextToken()); | |
404 postAttach(); | |
405 } else if (tokens == 2) { | |
406 preAttach(); | |
407 debugger.attach(t.nextToken(), t.nextToken()); | |
408 postAttach(); | |
409 } else { | |
410 usage(); | |
411 } | |
412 } | |
413 }, | |
414 new Command("detach", false) { | |
415 public void doit(Tokens t) { | |
416 if (t.countTokens() != 0) { | |
417 usage(); | |
418 } else { | |
419 debugger.detach(); | |
420 } | |
421 } | |
422 }, | |
423 new Command("examine", "examine [ address/count ] | [ address,address]", false) { | |
424 Pattern args1 = Pattern.compile("^(0x[0-9a-f]+)(/([0-9]*)([a-z]*))?$"); | |
425 Pattern args2 = Pattern.compile("^(0x[0-9a-f]+),(0x[0-9a-f]+)(/[a-z]*)?$"); | |
426 | |
427 String fill(Address a, int width) { | |
428 String s = "0x0"; | |
429 if (a != null) { | |
430 s = a.toString(); | |
431 } | |
432 if (s.length() != width) { | |
433 return s.substring(0, 2) + "000000000000000000000".substring(0, width - s.length()) + s.substring(2); | |
434 } | |
435 return s; | |
436 } | |
437 | |
438 public void doit(Tokens t) { | |
439 if (t.countTokens() != 1) { | |
440 usage(); | |
441 } else { | |
442 String arg = t.nextToken(); | |
443 Matcher m1 = args1.matcher(arg); | |
444 Matcher m2 = args2.matcher(arg); | |
445 Address start = null; | |
446 Address end = null; | |
447 String format = ""; | |
448 int formatSize = (int)VM.getVM().getAddressSize(); | |
449 | |
450 if (m1.matches()) { | |
451 start = VM.getVM().getDebugger().parseAddress(m1.group(1)); | |
452 int count = 1; | |
453 if (m1.group(2) != null) { | |
454 count = Integer.parseInt(m1.group(3)); | |
455 } | |
456 end = start.addOffsetTo(count * formatSize); | |
457 } else if (m2.matches()) { | |
458 start = VM.getVM().getDebugger().parseAddress(m2.group(1)); | |
459 end = VM.getVM().getDebugger().parseAddress(m2.group(2)); | |
460 } else { | |
461 usage(); | |
462 return; | |
463 } | |
464 int line = 80; | |
465 int formatWidth = formatSize * 8 / 4 + 2; | |
466 | |
467 out.print(fill(start, formatWidth)); | |
468 out.print(": "); | |
469 int width = line - formatWidth - 2; | |
470 | |
471 boolean needsPrintln = true; | |
472 while (start != null && start.lessThan(end)) { | |
473 Address val = start.getAddressAt(0); | |
474 out.print(fill(val, formatWidth)); | |
475 needsPrintln = true; | |
476 width -= formatWidth; | |
477 start = start.addOffsetTo(formatSize); | |
478 if (width <= formatWidth) { | |
479 out.println(); | |
480 needsPrintln = false; | |
481 if (start.lessThan(end)) { | |
482 out.print(fill(start, formatWidth)); | |
483 out.print(": "); | |
484 width = line - formatWidth - 2; | |
485 } | |
486 } else { | |
487 out.print(" "); | |
488 width -= 1; | |
489 } | |
490 } | |
491 if (needsPrintln) { | |
492 out.println(); | |
493 } | |
494 } | |
495 } | |
496 }, | |
6972
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
497 new Command("dumpreplaydata", "dumpreplaydata { <address > | -a | <thread_id> }", false) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
498 // This is used to dump replay data from ciInstanceKlass, ciMethodData etc |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
499 // default file name is replay.txt, also if java crashes in compiler |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
500 // thread, this file will be dumped in error processing. |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
501 public void doit(Tokens t) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
502 if (t.countTokens() != 1) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
503 usage(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
504 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
505 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
506 String name = t.nextToken(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
507 Address a = null; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
508 try { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
509 a = VM.getVM().getDebugger().parseAddress(name); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
510 } catch (NumberFormatException e) { } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
511 if (a != null) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
512 // only nmethod, Method, MethodData and InstanceKlass needed to |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
513 // dump replay data |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
514 |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
515 CodeBlob cb = VM.getVM().getCodeCache().findBlob(a); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
516 if (cb != null && (cb instanceof NMethod)) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
517 ((NMethod)cb).dumpReplayData(out); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
518 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
519 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
520 // assume it is Metadata |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
521 Metadata meta = Metadata.instantiateWrapperFor(a); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
522 if (meta != null) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
523 meta.dumpReplayData(out); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
524 } else { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
525 usage(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
526 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
527 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
528 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
529 // Not an address |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
530 boolean all = name.equals("-a"); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
531 Threads threads = VM.getVM().getThreads(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
532 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
533 ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
534 thread.printThreadIDOn(new PrintStream(bos)); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
535 if (all || bos.toString().equals(name)) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
536 if (thread instanceof CompilerThread) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
537 CompilerThread ct = (CompilerThread)thread; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
538 ciEnv env = ct.env(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
539 if (env != null) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
540 env.dumpReplayData(out); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
541 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
542 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
543 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
544 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
545 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
546 }, |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
547 new Command("buildreplayjars", "buildreplayjars [ all | app | boot ] | [ prefix ]", false) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
548 // This is used to dump jar files of all the classes |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
549 // loaded in the core. Everything on the bootclasspath |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
550 // will go in boot.jar and everything else will go in |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
551 // app.jar. Then the classes can be loaded by the replay |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
552 // jvm using -Xbootclasspath/p:boot.jar -cp app.jar. boot.jar usually |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
553 // not needed, unless changed by jvmti. |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
554 public void doit(Tokens t) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
555 int tcount = t.countTokens(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
556 if (tcount > 2) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
557 usage(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
558 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
559 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
560 try { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
561 String prefix = ""; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
562 String option = "all"; // default |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
563 switch(tcount) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
564 case 0: |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
565 break; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
566 case 1: |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
567 option = t.nextToken(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
568 if (!option.equalsIgnoreCase("all") && !option.equalsIgnoreCase("app") && |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
569 !option.equalsIgnoreCase("root")) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
570 prefix = option; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
571 option = "all"; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
572 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
573 break; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
574 case 2: |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
575 option = t.nextToken(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
576 prefix = t.nextToken(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
577 break; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
578 default: |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
579 usage(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
580 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
581 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
582 if (!option.equalsIgnoreCase("all") && !option.equalsIgnoreCase("app") && |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
583 !option.equalsIgnoreCase("boot")) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
584 usage(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
585 return; |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
586 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
587 ClassDump cd = new ClassDump(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
588 if (option.equalsIgnoreCase("all") || option.equalsIgnoreCase("boot")) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
589 cd.setClassFilter(new BootFilter()); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
590 cd.setJarOutput(prefix + "boot.jar"); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
591 cd.run(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
592 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
593 if (option.equalsIgnoreCase("all") || option.equalsIgnoreCase("app")) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
594 cd.setClassFilter(new NonBootFilter()); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
595 cd.setJarOutput(prefix + "app.jar"); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
596 cd.run(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
597 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
598 } catch (IOException ioe) { |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
599 ioe.printStackTrace(); |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
600 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
601 } |
bd7a7ce2e264
6830717: replay of compilations would help with debugging
minqi
parents:
6782
diff
changeset
|
602 }, |
0 | 603 new Command("findpc", "findpc address", false) { |
604 public void doit(Tokens t) { | |
605 if (t.countTokens() != 1) { | |
606 usage(); | |
607 } else { | |
608 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
609 PointerLocation loc = PointerFinder.find(a); | |
610 loc.printOn(out); | |
611 } | |
612 } | |
613 }, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
614 new Command("symbol", "symbol address", false) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
615 public void doit(Tokens t) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
616 if (t.countTokens() != 1) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
617 usage(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
618 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
619 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
620 Symbol.create(a).printValueOn(out); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
621 out.println(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
622 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
623 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
624 }, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
625 new Command("symboltable", "symboltable name", false) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
626 public void doit(Tokens t) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
627 if (t.countTokens() != 1) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
628 usage(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
629 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
630 out.println(SymbolTable.getTheTable().probe(t.nextToken())); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
631 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
632 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
633 }, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
634 new Command("symboldump", "symboldump", false) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
635 public void doit(Tokens t) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
636 SymbolTable.getTheTable().symbolsDo(new SymbolTable.SymbolVisitor() { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
637 public void visit(Symbol sym) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
638 sym.printValueOn(out); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
639 out.println(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
640 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
641 }); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
642 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
643 }, |
3939 | 644 new Command("flags", "flags [ flag | -nd ]", false) { |
0 | 645 public void doit(Tokens t) { |
646 int tokens = t.countTokens(); | |
647 if (tokens != 0 && tokens != 1) { | |
648 usage(); | |
649 } else { | |
650 String name = tokens > 0 ? t.nextToken() : null; | |
3939 | 651 boolean nonDefault = false; |
652 if (name != null && name.equals("-nd")) { | |
653 name = null; | |
654 nonDefault = true; | |
655 } | |
0 | 656 |
657 VM.Flag[] flags = VM.getVM().getCommandLineFlags(); | |
658 if (flags == null) { | |
659 out.println("Command Flag info not available (use 1.4.1_03 or later)!"); | |
660 } else { | |
661 boolean printed = false; | |
662 for (int f = 0; f < flags.length; f++) { | |
663 VM.Flag flag = flags[f]; | |
664 if (name == null || flag.getName().equals(name)) { | |
3939 | 665 |
666 if (nonDefault && flag.getOrigin() == 0) { | |
667 // only print flags which aren't their defaults | |
668 continue; | |
669 } | |
670 out.println(flag.getName() + " = " + flag.getValue() + " " + flag.getOrigin()); | |
0 | 671 printed = true; |
672 } | |
673 } | |
674 if (name != null && !printed) { | |
675 out.println("Couldn't find flag: " + name); | |
676 } | |
677 } | |
678 } | |
679 } | |
680 }, | |
681 new Command("help", "help [ command ]", true) { | |
682 public void doit(Tokens t) { | |
683 int tokens = t.countTokens(); | |
684 Command cmd = null; | |
685 if (tokens == 1) { | |
686 cmd = findCommand(t.nextToken()); | |
687 } | |
688 | |
689 if (cmd != null) { | |
690 cmd.usage(); | |
691 } else if (tokens == 0) { | |
692 out.println("Available commands:"); | |
693 Object[] keys = commands.keySet().toArray(); | |
694 Arrays.sort(keys, new Comparator() { | |
695 public int compare(Object o1, Object o2) { | |
696 return o1.toString().compareTo(o2.toString()); | |
697 } | |
698 }); | |
699 for (int i = 0; i < keys.length; i++) { | |
700 out.print(" "); | |
701 out.println(((Command)commands.get(keys[i])).usage); | |
702 } | |
703 } | |
704 } | |
705 }, | |
706 new Command("history", "history", true) { | |
707 public void doit(Tokens t) { | |
708 int tokens = t.countTokens(); | |
709 if (tokens != 0 && (tokens != 1 || !t.nextToken().equals("-h"))) { | |
710 usage(); | |
711 return; | |
712 } | |
713 boolean printIndex = tokens == 0; | |
714 for (int i = 0; i < history.size(); i++) { | |
715 if (printIndex) out.print(i + " "); | |
716 out.println(history.get(i)); | |
717 } | |
718 } | |
719 }, | |
6782 | 720 // decode raw address |
721 new Command("dis", "dis address [length]", false) { | |
722 public void doit(Tokens t) { | |
723 int tokens = t.countTokens(); | |
724 if (tokens != 1 && tokens != 2) { | |
725 usage(); | |
726 return; | |
727 } | |
728 String name = t.nextToken(); | |
729 Address addr = null; | |
730 int len = 0x10; // default length | |
731 try { | |
732 addr = VM.getVM().getDebugger().parseAddress(name); | |
733 } catch (NumberFormatException e) { | |
734 out.println(e); | |
735 return; | |
736 } | |
737 if (tokens == 2) { | |
738 try { | |
739 len = Integer.parseInt(t.nextToken()); | |
740 } catch (NumberFormatException e) { | |
741 out.println(e); | |
742 return; | |
743 } | |
744 } | |
745 HTMLGenerator generator = new HTMLGenerator(false); | |
746 out.println(generator.genHTMLForRawDisassembly(addr, len)); | |
747 } | |
748 | |
749 }, | |
750 // decode codeblob or nmethod | |
751 new Command("disassemble", "disassemble address", false) { | |
752 public void doit(Tokens t) { | |
753 int tokens = t.countTokens(); | |
754 if (tokens != 1) { | |
755 usage(); | |
756 return; | |
757 } | |
758 String name = t.nextToken(); | |
759 Address addr = null; | |
760 try { | |
761 addr = VM.getVM().getDebugger().parseAddress(name); | |
762 } catch (NumberFormatException e) { | |
763 out.println(e); | |
764 return; | |
765 } | |
766 | |
767 HTMLGenerator generator = new HTMLGenerator(false); | |
768 out.println(generator.genHTML(addr)); | |
769 } | |
770 }, | |
771 // print Java bytecode disassembly | |
772 new Command("jdis", "jdis address", false) { | |
773 public void doit(Tokens t) { | |
774 int tokens = t.countTokens(); | |
775 if (tokens != 1) { | |
776 usage(); | |
777 return; | |
778 } | |
779 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
780 Method m = (Method)Metadata.instantiateWrapperFor(a); | |
781 HTMLGenerator html = new HTMLGenerator(false); | |
782 out.println(html.genHTML(m)); | |
783 } | |
784 }, | |
1385 | 785 new Command("revptrs", "revptrs address", false) { |
786 public void doit(Tokens t) { | |
787 int tokens = t.countTokens(); | |
788 if (tokens != 1 && (tokens != 2 || !t.nextToken().equals("-c"))) { | |
789 usage(); | |
790 return; | |
791 } | |
792 boolean chase = tokens == 2; | |
793 ReversePtrs revptrs = VM.getVM().getRevPtrs(); | |
794 if (revptrs == null) { | |
795 out.println("Computing reverse pointers..."); | |
796 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis(); | |
797 final boolean[] complete = new boolean[1]; | |
798 HeapProgressThunk thunk = new HeapProgressThunk() { | |
799 public void heapIterationFractionUpdate(double d) {} | |
800 public synchronized void heapIterationComplete() { | |
801 complete[0] = true; | |
802 notify(); | |
803 } | |
804 }; | |
805 analysis.setHeapProgressThunk(thunk); | |
806 analysis.run(); | |
807 while (!complete[0]) { | |
808 synchronized (thunk) { | |
809 try { | |
810 thunk.wait(); | |
811 } catch (Exception e) { | |
812 } | |
813 } | |
814 } | |
815 revptrs = VM.getVM().getRevPtrs(); | |
816 out.println("Done."); | |
817 } | |
818 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
819 if (VM.getVM().getUniverse().heap().isInReserved(a)) { | |
820 OopHandle handle = a.addOffsetToAsOopHandle(0); | |
821 Oop oop = VM.getVM().getObjectHeap().newOop(handle); | |
822 ArrayList ptrs = revptrs.get(oop); | |
823 if (ptrs == null) { | |
824 out.println("no live references to " + a); | |
825 } else { | |
826 if (chase) { | |
827 while (ptrs.size() == 1) { | |
828 LivenessPathElement e = (LivenessPathElement)ptrs.get(0); | |
829 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
830 Oop.printOopValueOn(e.getObj(), new PrintStream(bos)); | |
831 out.println(bos.toString()); | |
832 ptrs = revptrs.get(e.getObj()); | |
833 } | |
834 } else { | |
835 for (int i = 0; i < ptrs.size(); i++) { | |
836 LivenessPathElement e = (LivenessPathElement)ptrs.get(i); | |
837 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
838 Oop.printOopValueOn(e.getObj(), new PrintStream(bos)); | |
839 out.println(bos.toString()); | |
840 oop = e.getObj(); | |
841 } | |
842 } | |
843 } | |
844 } | |
845 } | |
846 }, | |
3939 | 847 new Command("printmdo", "printmdo [ -a | expression ]", false) { |
848 // Print every MDO in the heap or the one referenced by expression. | |
849 public void doit(Tokens t) { | |
850 if (t.countTokens() != 1) { | |
851 usage(); | |
852 } else { | |
853 String s = t.nextToken(); | |
854 if (s.equals("-a")) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
855 SystemDictionary sysDict = VM.getVM().getSystemDictionary(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
856 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
857 public void visit(Klass k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
858 if (k instanceof InstanceKlass) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
859 MethodArray methods = ((InstanceKlass)k).getMethods(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
860 for (int i = 0; i < methods.length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
861 Method m = methods.at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
862 MethodData mdo = m.getMethodData(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
863 if (mdo != null) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
864 out.println("MethodData " + mdo.getAddress() + " for " + |
3939 | 865 "method " + m.getMethodHolder().getName().asString() + "." + |
866 m.getName().asString() + | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
867 m.getSignature().asString() + "@" + m.getAddress()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
868 mdo.printDataOn(out); |
3939 | 869 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
870 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
871 } |
3939 | 872 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
873 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
874 ); |
3939 | 875 } else { |
876 Address a = VM.getVM().getDebugger().parseAddress(s); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
877 MethodData mdo = (MethodData) Metadata.instantiateWrapperFor(a); |
3939 | 878 mdo.printDataOn(out); |
879 } | |
880 } | |
881 } | |
882 }, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
883 new Command("printall", "printall", false) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
884 // Print every MDO in the heap or the one referenced by expression. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
885 public void doit(Tokens t) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
886 if (t.countTokens() != 0) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
887 usage(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
888 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
889 SystemDictionary sysDict = VM.getVM().getSystemDictionary(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
890 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
891 public void visit(Klass k) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
892 if (k instanceof InstanceKlass && ((InstanceKlass)k).getConstants().getCache() != null) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
893 MethodArray methods = ((InstanceKlass)k).getMethods(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
894 for (int i = 0; i < methods.length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
895 Method m = methods.at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
896 HTMLGenerator gen = new HTMLGenerator(false); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
897 out.println(gen.genHTML(m)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
898 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
899 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
900 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
901 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
902 ); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
903 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
904 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
905 }, |
3939 | 906 new Command("dumpideal", "dumpideal { -a | id }", false) { |
907 // Do a full dump of the nodes reachabile from root in each compiler thread. | |
908 public void doit(Tokens t) { | |
909 if (t.countTokens() != 1) { | |
910 usage(); | |
911 } else { | |
912 String name = t.nextToken(); | |
913 boolean all = name.equals("-a"); | |
914 Threads threads = VM.getVM().getThreads(); | |
915 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
916 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
917 thread.printThreadIDOn(new PrintStream(bos)); | |
918 if (all || bos.toString().equals(name)) { | |
919 if (thread instanceof CompilerThread) { | |
920 CompilerThread ct = (CompilerThread)thread; | |
921 out.println(ct); | |
922 ciEnv env = ct.env(); | |
923 if (env != null) { | |
924 Compile c = env.compilerData(); | |
925 c.root().dump(9999, out); | |
926 } else { | |
927 out.println(" not compiling"); | |
928 } | |
929 } | |
930 } | |
931 } | |
932 } | |
933 } | |
934 }, | |
935 new Command("dumpcfg", "dumpcfg { -a | id }", false) { | |
936 // Dump the PhaseCFG for every compiler thread that has one live. | |
937 public void doit(Tokens t) { | |
938 if (t.countTokens() != 1) { | |
939 usage(); | |
940 } else { | |
941 String name = t.nextToken(); | |
942 boolean all = name.equals("-a"); | |
943 Threads threads = VM.getVM().getThreads(); | |
944 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
945 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
946 thread.printThreadIDOn(new PrintStream(bos)); | |
947 if (all || bos.toString().equals(name)) { | |
948 if (thread instanceof CompilerThread) { | |
949 CompilerThread ct = (CompilerThread)thread; | |
950 out.println(ct); | |
951 ciEnv env = ct.env(); | |
952 if (env != null) { | |
953 Compile c = env.compilerData(); | |
954 c.cfg().dump(out); | |
955 } | |
956 } | |
957 } | |
958 } | |
959 } | |
960 } | |
961 }, | |
962 new Command("dumpilt", "dumpilt { -a | id }", false) { | |
963 // dumps the InlineTree of a C2 compile | |
964 public void doit(Tokens t) { | |
965 if (t.countTokens() != 1) { | |
966 usage(); | |
967 } else { | |
968 String name = t.nextToken(); | |
969 boolean all = name.equals("-a"); | |
970 Threads threads = VM.getVM().getThreads(); | |
971 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
972 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
973 thread.printThreadIDOn(new PrintStream(bos)); | |
974 if (all || bos.toString().equals(name)) { | |
975 if (thread instanceof CompilerThread) { | |
976 CompilerThread ct = (CompilerThread)thread; | |
977 ciEnv env = ct.env(); | |
978 if (env != null) { | |
979 Compile c = env.compilerData(); | |
980 InlineTree ilt = c.ilt(); | |
981 if (ilt != null) { | |
982 ilt.print(out); | |
983 } | |
984 } | |
985 } | |
986 } | |
987 } | |
988 } | |
989 } | |
990 }, | |
991 new Command("vmstructsdump", "vmstructsdump", false) { | |
992 public void doit(Tokens t) { | |
993 if (t.countTokens() != 0) { | |
994 usage(); | |
995 return; | |
996 } | |
997 | |
998 // Dump a copy of the type database in a form that can | |
999 // be read back. | |
1000 Iterator i = agent.getTypeDataBase().getTypes(); | |
1001 // Make sure the types are emitted in an order than can be read back in | |
1002 HashSet emitted = new HashSet(); | |
1003 Stack pending = new Stack(); | |
1004 while (i.hasNext()) { | |
1005 Type n = (Type)i.next(); | |
1006 if (emitted.contains(n.getName())) { | |
1007 continue; | |
1008 } | |
1009 | |
1010 while (n != null && !emitted.contains(n.getName())) { | |
1011 pending.push(n); | |
1012 n = n.getSuperclass(); | |
1013 } | |
1014 while (!pending.empty()) { | |
1015 n = (Type)pending.pop(); | |
1016 dumpType(n); | |
1017 emitted.add(n.getName()); | |
1018 } | |
1019 } | |
1020 i = agent.getTypeDataBase().getTypes(); | |
1021 while (i.hasNext()) { | |
1022 dumpFields((Type)i.next(), false); | |
1023 } | |
1024 } | |
1025 }, | |
1026 | |
0 | 1027 new Command("inspect", "inspect expression", false) { |
1028 public void doit(Tokens t) { | |
1029 if (t.countTokens() != 1) { | |
1030 usage(); | |
1031 } else { | |
1032 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1033 SimpleTreeNode node = null; | |
1034 if (VM.getVM().getUniverse().heap().isInReserved(a)) { | |
1035 OopHandle handle = a.addOffsetToAsOopHandle(0); | |
1036 Oop oop = VM.getVM().getObjectHeap().newOop(handle); | |
1037 node = new OopTreeNodeAdapter(oop, null); | |
1038 | |
1039 out.println("instance of " + node.getValue() + " @ " + a + | |
1040 " (size = " + oop.getObjectSize() + ")"); | |
1041 } else if (VM.getVM().getCodeCache().contains(a)) { | |
1042 CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a); | |
1043 a = blob.headerBegin(); | |
1044 } | |
1045 if (node == null) { | |
1046 Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a); | |
1047 if (type != null) { | |
1048 out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")"); | |
1049 node = new CTypeTreeNodeAdapter(a, type, null); | |
1050 } | |
1051 } | |
1052 if (node != null) { | |
1053 printNode(node); | |
1054 } | |
1055 } | |
1056 } | |
1057 }, | |
1058 new Command("jhisto", "jhisto", false) { | |
1059 public void doit(Tokens t) { | |
1060 ObjectHistogram histo = new ObjectHistogram(); | |
1061 histo.run(out, err); | |
1062 } | |
1063 }, | |
1064 new Command("jstack", "jstack [-v]", false) { | |
1065 public void doit(Tokens t) { | |
1066 boolean verbose = false; | |
1067 if (t.countTokens() > 0 && t.nextToken().equals("-v")) { | |
1068 verbose = true; | |
1069 } | |
1070 StackTrace jstack = new StackTrace(verbose, true); | |
1071 jstack.run(out); | |
1072 } | |
1073 }, | |
1074 new Command("print", "print expression", false) { | |
1075 public void doit(Tokens t) { | |
1076 if (t.countTokens() != 1) { | |
1077 usage(); | |
1078 } else { | |
1079 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1080 HTMLGenerator gen = new HTMLGenerator(false); | |
1081 out.println(gen.genHTML(a)); | |
1082 } | |
1083 } | |
1084 }, | |
1085 new Command("printas", "printas type expression", false) { | |
1086 public void doit(Tokens t) { | |
1087 if (t.countTokens() != 2) { | |
1088 usage(); | |
1089 } else { | |
1090 Type type = agent.getTypeDataBase().lookupType(t.nextToken()); | |
1091 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1092 CTypeTreeNodeAdapter node = new CTypeTreeNodeAdapter(a, type, null); | |
1093 | |
1094 out.println("pointer to " + type + " @ " + a + | |
1095 " (size = " + type.getSize() + ")"); | |
1096 printNode(node); | |
1097 } | |
1098 } | |
1099 }, | |
1100 new Command("printstatics", "printstatics [ type ]", false) { | |
1101 public void doit(Tokens t) { | |
1102 if (t.countTokens() > 1) { | |
1103 usage(); | |
1104 } else { | |
1105 if (t.countTokens() == 0) { | |
1106 out.println("All known static fields"); | |
1107 printNode(new CTypeTreeNodeAdapter(agent.getTypeDataBase().getTypes())); | |
1108 } else { | |
1109 Type type = agent.getTypeDataBase().lookupType(t.nextToken()); | |
1110 out.println("Static fields of " + type.getName()); | |
1111 printNode(new CTypeTreeNodeAdapter(type)); | |
1112 } | |
1113 } | |
1114 } | |
1115 }, | |
1116 new Command("pmap", "pmap", false) { | |
1117 public void doit(Tokens t) { | |
1118 PMap pmap = new PMap(); | |
1119 pmap.run(out, debugger.getAgent().getDebugger()); | |
1120 } | |
1121 }, | |
1122 new Command("pstack", "pstack [-v]", false) { | |
1123 public void doit(Tokens t) { | |
1124 boolean verbose = false; | |
1125 if (t.countTokens() > 0 && t.nextToken().equals("-v")) { | |
1126 verbose = true; | |
1127 } | |
1128 PStack pstack = new PStack(verbose, true); | |
1129 pstack.run(out, debugger.getAgent().getDebugger()); | |
1130 } | |
1131 }, | |
1132 new Command("quit", true) { | |
1133 public void doit(Tokens t) { | |
1134 if (t.countTokens() != 0) { | |
1135 usage(); | |
1136 } else { | |
1137 debugger.detach(); | |
1138 System.exit(0); | |
1139 } | |
1140 } | |
1141 }, | |
1142 new Command("echo", "echo [ true | false ]", true) { | |
1143 public void doit(Tokens t) { | |
1144 if (t.countTokens() == 0) { | |
1145 out.println("echo is " + doEcho); | |
1146 } else if (t.countTokens() == 1) { | |
1147 doEcho = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1148 } else { | |
1149 usage(); | |
1150 } | |
1151 } | |
1152 }, | |
1153 new Command("versioncheck", "versioncheck [ true | false ]", true) { | |
1154 public void doit(Tokens t) { | |
1155 if (t.countTokens() == 0) { | |
1156 out.println("versioncheck is " + | |
1157 (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null)); | |
1158 } else if (t.countTokens() == 1) { | |
1159 if (Boolean.valueOf(t.nextToken()).booleanValue()) { | |
1160 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", null); | |
1161 } else { | |
1162 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", "true"); | |
1163 } | |
1164 } else { | |
1165 usage(); | |
1166 } | |
1167 } | |
1168 }, | |
1169 new Command("scanoops", "scanoops start end [ type ]", false) { | |
1170 public void doit(Tokens t) { | |
1171 if (t.countTokens() != 2 && t.countTokens() != 3) { | |
1172 usage(); | |
1173 } else { | |
1174 long stride = VM.getVM().getAddressSize(); | |
1175 Address base = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1176 Address end = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1177 Klass klass = null; | |
1178 if (t.countTokens() == 1) { | |
1179 klass = SystemDictionaryHelper.findInstanceKlass(t.nextToken()); | |
8756
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
1180 if (klass == null) { |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
1181 out.println("No such type."); |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
1182 return; |
686916dc0439
8009457: SA: A small fix on "scanoops" command in CLHSDB
sla
parents:
8750
diff
changeset
|
1183 } |
0 | 1184 } |
1185 while (base != null && base.lessThan(end)) { | |
1186 long step = stride; | |
1187 OopHandle handle = base.addOffsetToAsOopHandle(0); | |
1188 if (RobustOopDeterminator.oopLooksValid(handle)) { | |
1189 try { | |
1190 Oop oop = VM.getVM().getObjectHeap().newOop(handle); | |
1191 if (klass == null || oop.getKlass().isSubtypeOf(klass)) | |
1192 out.println(handle.toString() + " " + oop.getKlass().getName().asString()); | |
1193 step = oop.getObjectSize(); | |
1194 } catch (UnknownOopException ex) { | |
1195 // ok | |
1196 } catch (RuntimeException ex) { | |
1197 ex.printStackTrace(); | |
1198 } | |
1199 } | |
1200 base = base.addOffsetTo(step); | |
1201 } | |
1202 } | |
1203 } | |
1204 }, | |
3939 | 1205 new Command("intConstant", "intConstant [ name [ value ] ]", true) { |
1206 public void doit(Tokens t) { | |
1207 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) { | |
1208 usage(); | |
1209 return; | |
1210 } | |
1211 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); | |
1212 if (t.countTokens() == 1) { | |
1213 out.println("intConstant " + name + " " + db.lookupIntConstant(name)); | |
1214 } else if (t.countTokens() == 0) { | |
1215 Iterator i = db.getIntConstants(); | |
1216 while (i.hasNext()) { | |
1217 String name = (String)i.next(); | |
1218 out.println("intConstant " + name + " " + db.lookupIntConstant(name)); | |
1219 } | |
1220 } else if (t.countTokens() == 2) { | |
1221 String name = t.nextToken(); | |
1222 Integer value = Integer.valueOf(t.nextToken()); | |
1223 db.addIntConstant(name, value); | |
1224 } | |
1225 } | |
1226 }, | |
1227 new Command("longConstant", "longConstant [ name [ value ] ]", true) { | |
1228 public void doit(Tokens t) { | |
1229 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) { | |
1230 usage(); | |
1231 return; | |
1232 } | |
1233 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); | |
1234 if (t.countTokens() == 1) { | |
1235 out.println("longConstant " + name + " " + db.lookupLongConstant(name)); | |
1236 } else if (t.countTokens() == 0) { | |
1237 Iterator i = db.getLongConstants(); | |
1238 while (i.hasNext()) { | |
1239 String name = (String)i.next(); | |
1240 out.println("longConstant " + name + " " + db.lookupLongConstant(name)); | |
1241 } | |
1242 } else if (t.countTokens() == 2) { | |
1243 String name = t.nextToken(); | |
1244 Long value = Long.valueOf(t.nextToken()); | |
1245 db.addLongConstant(name, value); | |
1246 } | |
1247 } | |
1248 }, | |
0 | 1249 new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) { |
1250 public void doit(Tokens t) { | |
1251 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) { | |
1252 usage(); | |
1253 return; | |
1254 } | |
1255 if (t.countTokens() == 1) { | |
1256 Type type = agent.getTypeDataBase().lookupType(t.nextToken()); | |
1257 dumpFields(type); | |
1258 } else if (t.countTokens() == 0) { | |
1259 Iterator i = agent.getTypeDataBase().getTypes(); | |
1260 while (i.hasNext()) { | |
1261 dumpFields((Type)i.next()); | |
1262 } | |
1263 } else { | |
1264 BasicType containingType = (BasicType)agent.getTypeDataBase().lookupType(t.nextToken()); | |
1265 | |
1266 String fieldName = t.nextToken(); | |
1267 | |
1268 // The field's Type must already be in the database -- no exceptions | |
1269 Type fieldType = agent.getTypeDataBase().lookupType(t.nextToken()); | |
1270 | |
1271 boolean isStatic = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1272 long offset = Long.parseLong(t.nextToken()); | |
1273 Address staticAddress = parseAddress(t.nextToken()); | |
1274 if (isStatic && staticAddress == null) { | |
1275 staticAddress = lookup(containingType.getName() + "::" + fieldName); | |
1276 } | |
1277 | |
1278 // check to see if the field already exists | |
1279 Iterator i = containingType.getFields(); | |
1280 while (i.hasNext()) { | |
1281 Field f = (Field) i.next(); | |
1282 if (f.getName().equals(fieldName)) { | |
1283 if (f.isStatic() != isStatic) { | |
1284 throw new RuntimeException("static/nonstatic mismatch: " + t.input); | |
1285 } | |
1286 if (!isStatic) { | |
1287 if (f.getOffset() != offset) { | |
1288 throw new RuntimeException("bad redefinition of field offset: " + t.input); | |
1289 } | |
1290 } else { | |
1291 if (!f.getStaticFieldAddress().equals(staticAddress)) { | |
1292 throw new RuntimeException("bad redefinition of field location: " + t.input); | |
1293 } | |
1294 } | |
1295 if (f.getType() != fieldType) { | |
1296 throw new RuntimeException("bad redefinition of field type: " + t.input); | |
1297 } | |
1298 return; | |
1299 } | |
1300 } | |
1301 | |
1302 // Create field by type | |
1303 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); | |
1304 db.createField(containingType, | |
1305 fieldName, fieldType, | |
1306 isStatic, | |
1307 offset, | |
1308 staticAddress); | |
1309 | |
1310 } | |
1311 } | |
1312 | |
1313 }, | |
1314 new Command("tokenize", "tokenize ...", true) { | |
1315 public void doit(Tokens t) { | |
1316 while (t.hasMoreTokens()) { | |
1317 out.println("\"" + t.nextToken() + "\""); | |
1318 } | |
1319 } | |
1320 }, | |
1321 new Command("type", "type [ type [ name super isOop isInteger isUnsigned size ] ]", true) { | |
1322 public void doit(Tokens t) { | |
1323 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) { | |
1324 usage(); | |
1325 return; | |
1326 } | |
1327 if (t.countTokens() == 6) { | |
1328 String typeName = t.nextToken(); | |
1329 String superclassName = t.nextToken(); | |
1330 if (superclassName.equals("null")) { | |
1331 superclassName = null; | |
1332 } | |
1333 boolean isOop = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1334 boolean isInteger = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1335 boolean isUnsigned = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1336 long size = Long.parseLong(t.nextToken()); | |
1337 | |
1338 BasicType type = null; | |
1339 try { | |
1340 type = (BasicType)agent.getTypeDataBase().lookupType(typeName); | |
1341 } catch (RuntimeException e) { | |
1342 } | |
1343 if (type != null) { | |
1344 if (type.isOopType() != isOop) { | |
1345 throw new RuntimeException("oop mismatch in type definition: " + t.input); | |
1346 } | |
1347 if (type.isCIntegerType() != isInteger) { | |
1348 throw new RuntimeException("integer type mismatch in type definition: " + t.input); | |
1349 } | |
1350 if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) { | |
1351 throw new RuntimeException("unsigned mismatch in type definition: " + t.input); | |
1352 } | |
1353 if (type.getSuperclass() == null) { | |
1354 if (superclassName != null) { | |
1355 if (type.getSize() == -1) { | |
1356 type.setSuperclass(agent.getTypeDataBase().lookupType(superclassName)); | |
1357 } else { | |
1358 throw new RuntimeException("unexpected superclass in type definition: " + t.input); | |
1359 } | |
1360 } | |
1361 } else { | |
1362 if (superclassName == null) { | |
1363 throw new RuntimeException("missing superclass in type definition: " + t.input); | |
1364 } | |
1365 if (!type.getSuperclass().getName().equals(superclassName)) { | |
1366 throw new RuntimeException("incorrect superclass in type definition: " + t.input); | |
1367 } | |
1368 } | |
1369 if (type.getSize() != size) { | |
1370 if (type.getSize() == -1) { | |
1371 type.setSize(size); | |
1372 } | |
1373 throw new RuntimeException("size mismatch in type definition: " + t.input); | |
1374 } | |
1375 return; | |
1376 } | |
1377 | |
1378 // Create type | |
1379 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase(); | |
1380 db.createType(typeName, superclassName, isOop, isInteger, isUnsigned, size); | |
1381 } else if (t.countTokens() == 1) { | |
1382 Type type = agent.getTypeDataBase().lookupType(t.nextToken()); | |
1383 dumpType(type); | |
1384 } else { | |
1385 Iterator i = agent.getTypeDataBase().getTypes(); | |
1385 | 1386 // Make sure the types are emitted in an order than can be read back in |
1387 HashSet emitted = new HashSet(); | |
1388 Stack pending = new Stack(); | |
0 | 1389 while (i.hasNext()) { |
1385 | 1390 Type n = (Type)i.next(); |
1391 if (emitted.contains(n.getName())) { | |
1392 continue; | |
1393 } | |
1394 | |
1395 while (n != null && !emitted.contains(n.getName())) { | |
1396 pending.push(n); | |
1397 n = n.getSuperclass(); | |
1398 } | |
1399 while (!pending.empty()) { | |
1400 n = (Type)pending.pop(); | |
1401 dumpType(n); | |
1402 emitted.add(n.getName()); | |
1403 } | |
0 | 1404 } |
1405 } | |
1406 } | |
1407 | |
1408 }, | |
1409 new Command("source", "source filename", true) { | |
1410 public void doit(Tokens t) { | |
1411 if (t.countTokens() != 1) { | |
1412 usage(); | |
1413 return; | |
1414 } | |
1415 String file = t.nextToken(); | |
1416 BufferedReader savedInput = in; | |
1417 try { | |
1418 BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file))); | |
1419 in = input; | |
1420 run(false); | |
1421 } catch (Exception e) { | |
1422 out.println("Error: " + e); | |
1423 if (verboseExceptions) { | |
1424 e.printStackTrace(out); | |
1425 } | |
1426 } finally { | |
1427 in = savedInput; | |
1428 } | |
1429 | |
1430 } | |
1431 }, | |
1385 | 1432 new Command("search", "search [ heap | perm | rawheap | codecache | threads ] value", false) { |
0 | 1433 public void doit(Tokens t) { |
1434 if (t.countTokens() != 2) { | |
1435 usage(); | |
1385 | 1436 return; |
1437 } | |
1438 String type = t.nextToken(); | |
1439 final Address value = VM.getVM().getDebugger().parseAddress(t.nextToken()); | |
1440 final long stride = VM.getVM().getAddressSize(); | |
1441 if (type.equals("threads")) { | |
1442 Threads threads = VM.getVM().getThreads(); | |
1443 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
1444 Address base = thread.getBaseOfStackPointer(); | |
1445 Address end = thread.getLastJavaSP(); | |
1446 if (end == null) continue; | |
1447 if (end.lessThan(base)) { | |
1448 Address tmp = base; | |
1449 base = end; | |
1450 end = tmp; | |
1451 } | |
1452 out.println("Searching " + base + " " + end); | |
1453 while (base != null && base.lessThan(end)) { | |
1454 Address val = base.getAddressAt(0); | |
1455 if (AddressOps.equal(val, value)) { | |
1456 out.println(base); | |
1457 } | |
1458 base = base.addOffsetTo(stride); | |
1459 } | |
1460 } | |
1461 } else if (type.equals("rawheap")) { | |
1462 RawHeapVisitor iterator = new RawHeapVisitor() { | |
1463 public void prologue(long used) { | |
0 | 1464 } |
1385 | 1465 |
1466 public void visitAddress(Address addr) { | |
1467 Address val = addr.getAddressAt(0); | |
0 | 1468 if (AddressOps.equal(val, value)) { |
1385 | 1469 out.println("found at " + addr); |
0 | 1470 } |
1385 | 1471 } |
1472 public void visitCompOopAddress(Address addr) { | |
1473 Address val = addr.getCompOopAddressAt(0); | |
1474 if (AddressOps.equal(val, value)) { | |
1475 out.println("found at " + addr); | |
1476 } | |
0 | 1477 } |
1385 | 1478 public void epilogue() { |
1479 } | |
1480 }; | |
1481 VM.getVM().getObjectHeap().iterateRaw(iterator); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
3939
diff
changeset
|
1482 } else if (type.equals("heap")) { |
1385 | 1483 HeapVisitor iterator = new DefaultHeapVisitor() { |
1484 public boolean doObj(Oop obj) { | |
1485 int index = 0; | |
1486 Address start = obj.getHandle(); | |
1487 long end = obj.getObjectSize(); | |
1488 while (index < end) { | |
1489 Address val = start.getAddressAt(index); | |
0 | 1490 if (AddressOps.equal(val, value)) { |
1385 | 1491 out.println("found in " + obj.getHandle()); |
1492 break; | |
0 | 1493 } |
1385 | 1494 index += 4; |
0 | 1495 } |
1385 | 1496 return false; |
1497 } | |
1498 }; | |
1499 VM.getVM().getObjectHeap().iterate(iterator); | |
1500 } else if (type.equals("codecache")) { | |
1501 CodeCacheVisitor v = new CodeCacheVisitor() { | |
1502 public void prologue(Address start, Address end) { | |
1503 } | |
1504 public void visit(CodeBlob blob) { | |
1505 boolean printed = false; | |
1506 Address base = blob.getAddress(); | |
1507 Address end = base.addOffsetTo(blob.getSize()); | |
1508 while (base != null && base.lessThan(end)) { | |
1509 Address val = base.getAddressAt(0); | |
1510 if (AddressOps.equal(val, value)) { | |
1511 if (!printed) { | |
1512 printed = true; | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1513 try { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1514 blob.printOn(out); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1515 } catch (Exception e) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1516 out.println("Exception printing blob at " + base); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1517 e.printStackTrace(); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
2426
diff
changeset
|
1518 } |
0 | 1519 } |
1385 | 1520 out.println("found at " + base + "\n"); |
0 | 1521 } |
1385 | 1522 base = base.addOffsetTo(stride); |
0 | 1523 } |
1385 | 1524 } |
1525 public void epilogue() { | |
1526 } | |
0 | 1527 |
1528 | |
1385 | 1529 }; |
1530 VM.getVM().getCodeCache().iterate(v); | |
0 | 1531 |
1532 } | |
1533 } | |
1534 }, | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1535 new Command("dumpcodecache", "dumpcodecache", false) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1536 public void doit(Tokens t) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1537 if (t.countTokens() != 0) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1538 usage(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1539 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1540 final PrintStream fout = out; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1541 final HTMLGenerator gen = new HTMLGenerator(false); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1542 CodeCacheVisitor v = new CodeCacheVisitor() { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1543 public void prologue(Address start, Address end) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1544 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1545 public void visit(CodeBlob blob) { |
1748 | 1546 fout.println(gen.genHTML(blob.contentBegin())); |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1547 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1548 public void epilogue() { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1549 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1550 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1551 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1552 }; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1553 VM.getVM().getCodeCache().iterate(v); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1554 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1555 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
196
diff
changeset
|
1556 }, |
0 | 1557 new Command("where", "where { -a | id }", false) { |
1558 public void doit(Tokens t) { | |
1559 if (t.countTokens() != 1) { | |
1560 usage(); | |
1561 } else { | |
1562 String name = t.nextToken(); | |
1563 Threads threads = VM.getVM().getThreads(); | |
1564 boolean all = name.equals("-a"); | |
1565 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
1566 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
1567 thread.printThreadIDOn(new PrintStream(bos)); | |
1568 if (all || bos.toString().equals(name)) { | |
8750 | 1569 out.println("Thread " + bos.toString() + " Address: " + thread.getAddress()); |
0 | 1570 HTMLGenerator gen = new HTMLGenerator(false); |
1385 | 1571 try { |
1572 out.println(gen.genHTMLForJavaStackTrace(thread)); | |
1573 } catch (Exception e) { | |
1574 err.println("Error: " + e); | |
1575 if (verboseExceptions) { | |
1576 e.printStackTrace(err); | |
1577 } | |
1578 } | |
0 | 1579 if (!all) return; |
1580 } | |
1581 } | |
1582 if (!all) out.println("Couldn't find thread " + name); | |
1583 } | |
1584 } | |
1585 }, | |
1385 | 1586 new Command("thread", "thread { -a | id }", false) { |
1587 public void doit(Tokens t) { | |
1588 if (t.countTokens() != 1) { | |
1589 usage(); | |
1590 } else { | |
1591 String name = t.nextToken(); | |
1592 Threads threads = VM.getVM().getThreads(); | |
1593 boolean all = name.equals("-a"); | |
1594 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
1595 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
1596 thread.printThreadIDOn(new PrintStream(bos)); | |
1597 if (all || bos.toString().equals(name)) { | |
8750 | 1598 out.println("Thread " + bos.toString() + " Address " + thread.getAddress()); |
1385 | 1599 if (!all) return; |
1600 } | |
1601 } | |
1602 out.println("Couldn't find thread " + name); | |
1603 } | |
1604 } | |
1605 }, | |
0 | 1606 |
1607 new Command("threads", false) { | |
1608 public void doit(Tokens t) { | |
1609 if (t.countTokens() != 0) { | |
1610 usage(); | |
1611 } else { | |
1612 Threads threads = VM.getVM().getThreads(); | |
1613 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
1614 thread.printThreadIDOn(out); | |
1615 out.println(" " + thread.getThreadName()); | |
1616 } | |
1617 } | |
1618 } | |
1619 }, | |
1620 | |
1621 new Command("livenmethods", false) { | |
1622 public void doit(Tokens t) { | |
1623 if (t.countTokens() != 0) { | |
1624 usage(); | |
1625 } else { | |
1626 ArrayList nmethods = new ArrayList(); | |
1627 Threads threads = VM.getVM().getThreads(); | |
1628 HTMLGenerator gen = new HTMLGenerator(false); | |
1629 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) { | |
1630 try { | |
1631 for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) { | |
1632 if (vf instanceof CompiledVFrame) { | |
1633 NMethod c = ((CompiledVFrame)vf).getCode(); | |
1634 if (!nmethods.contains(c)) { | |
1635 nmethods.add(c); | |
1636 out.println(gen.genHTML(c)); | |
1637 } | |
1638 } | |
1639 } | |
1640 } catch (Exception e) { | |
1641 e.printStackTrace(); | |
1642 } | |
1643 } | |
1644 } | |
1645 } | |
1646 }, | |
1647 new Command("universe", false) { | |
1648 public void doit(Tokens t) { | |
1649 if (t.countTokens() != 0) { | |
1650 usage(); | |
1651 } else { | |
1652 Universe u = VM.getVM().getUniverse(); | |
1653 out.println("Heap Parameters:"); | |
1654 u.heap().printOn(out); | |
1655 } | |
1656 } | |
1657 }, | |
1658 new Command("verbose", "verbose true | false", true) { | |
1659 public void doit(Tokens t) { | |
1660 if (t.countTokens() != 1) { | |
1661 usage(); | |
1662 } else { | |
1663 verboseExceptions = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1664 } | |
1665 } | |
1666 }, | |
1667 new Command("assert", "assert true | false", true) { | |
1668 public void doit(Tokens t) { | |
1669 if (t.countTokens() != 1) { | |
1670 usage(); | |
1671 } else { | |
1672 Assert.ASSERTS_ENABLED = Boolean.valueOf(t.nextToken()).booleanValue(); | |
1673 } | |
1674 } | |
1675 }, | |
1676 }; | |
1677 | |
1678 private boolean verboseExceptions = false; | |
1679 private ArrayList history = new ArrayList(); | |
1680 private HashMap commands = new HashMap(); | |
1681 private boolean doEcho = false; | |
1682 | |
1683 private Command findCommand(String key) { | |
1684 return (Command)commands.get(key); | |
1685 } | |
1686 | |
1687 public void printPrompt() { | |
1688 out.print("hsdb> "); | |
1689 } | |
1690 | |
1691 private DebuggerInterface debugger; | |
1692 private HotSpotAgent agent; | |
1693 private JSJavaScriptEngine jsengine; | |
1694 private BufferedReader in; | |
1695 private PrintStream out; | |
1696 private PrintStream err; | |
1697 | |
1698 // called before debuggee attach | |
1699 private void preAttach() { | |
1700 // nothing for now.. | |
1701 } | |
1702 | |
1703 // called after debuggee attach | |
1704 private void postAttach() { | |
1705 // create JavaScript engine and start it | |
1706 jsengine = new JSJavaScriptEngine() { | |
1707 private ObjectReader reader = new ObjectReader(); | |
1708 private JSJavaFactory factory = new JSJavaFactoryImpl(); | |
1709 public ObjectReader getObjectReader() { | |
1710 return reader; | |
1711 } | |
1712 public JSJavaFactory getJSJavaFactory() { | |
1713 return factory; | |
1714 } | |
1715 protected void quit() { | |
1716 debugger.detach(); | |
1717 System.exit(0); | |
1718 } | |
1719 protected BufferedReader getInputReader() { | |
1720 return in; | |
1721 } | |
1722 protected PrintStream getOutputStream() { | |
1723 return out; | |
1724 } | |
1725 protected PrintStream getErrorStream() { | |
1726 return err; | |
1727 } | |
1728 }; | |
1729 try { | |
1730 jsengine.defineFunction(this, | |
1731 this.getClass().getMethod("registerCommand", | |
1732 new Class[] { | |
1733 String.class, String.class, String.class | |
1734 })); | |
1735 } catch (NoSuchMethodException exp) { | |
1736 // should not happen, see below...!! | |
1737 exp.printStackTrace(); | |
1738 } | |
1739 jsengine.start(); | |
1740 } | |
1741 | |
1742 public void registerCommand(String cmd, String usage, final String func) { | |
1743 commands.put(cmd, new Command(cmd, usage, false) { | |
1744 public void doit(Tokens t) { | |
1745 final int len = t.countTokens(); | |
1746 Object[] args = new Object[len]; | |
1747 for (int i = 0; i < len; i++) { | |
1748 args[i] = t.nextToken(); | |
1749 } | |
1750 jsengine.call(func, args); | |
1751 } | |
1752 }); | |
1753 } | |
1754 | |
1755 public void setOutput(PrintStream o) { | |
1756 out = o; | |
1757 } | |
1758 | |
1759 public void setErr(PrintStream e) { | |
1760 err = e; | |
1761 } | |
1762 | |
1763 public CommandProcessor(DebuggerInterface debugger, BufferedReader in, PrintStream out, PrintStream err) { | |
1764 this.debugger = debugger; | |
1765 this.agent = debugger.getAgent(); | |
1766 this.in = in; | |
1767 this.out = out; | |
1768 this.err = err; | |
1769 for (int i = 0; i < commandList.length; i++) { | |
1770 Command c = commandList[i]; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
1771 if (commands.get(c.name) != null) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
1772 throw new InternalError(c.name + " has multiple definitions"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1748
diff
changeset
|
1773 } |
0 | 1774 commands.put(c.name, c); |
1775 } | |
1776 if (debugger.isAttached()) { | |
1777 postAttach(); | |
1778 } | |
1779 } | |
1780 | |
1781 | |
1782 public void run(boolean prompt) { | |
1783 // Process interactive commands. | |
1784 while (true) { | |
1785 if (prompt) printPrompt(); | |
1786 String ln = null; | |
1787 try { | |
1788 ln = in.readLine(); | |
1789 } catch (IOException e) { | |
1790 } | |
1791 if (ln == null) { | |
1792 if (prompt) err.println("Input stream closed."); | |
1793 return; | |
1794 } | |
1795 | |
3939 | 1796 executeCommand(ln, prompt); |
0 | 1797 } |
1798 } | |
1799 | |
1385 | 1800 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))"); |
0 | 1801 |
3939 | 1802 public void executeCommand(String ln, boolean putInHistory) { |
0 | 1803 if (ln.indexOf('!') != -1) { |
1804 int size = history.size(); | |
1805 if (size == 0) { | |
1806 ln = ""; | |
1807 err.println("History is empty"); | |
1808 } else { | |
1809 StringBuffer result = new StringBuffer(); | |
1810 Matcher m = historyPattern.matcher(ln); | |
1811 int start = 0; | |
1812 while (m.find()) { | |
1813 if (m.start() > start) { | |
1814 result.append(ln.substring(start, m.start() - start)); | |
1815 } | |
1816 start = m.end(); | |
1817 | |
1818 String cmd = m.group(); | |
1819 if (cmd.equals("!!")) { | |
1820 result.append((String)history.get(history.size() - 1)); | |
1821 } else if (cmd.equals("!!-")) { | |
1822 Tokens item = new Tokens((String)history.get(history.size() - 1)); | |
1823 item.trim(1); | |
1824 result.append(item.join(" ")); | |
1825 } else if (cmd.equals("!*")) { | |
1826 Tokens item = new Tokens((String)history.get(history.size() - 1)); | |
1827 item.nextToken(); | |
1828 result.append(item.join(" ")); | |
1829 } else if (cmd.equals("!$")) { | |
1830 Tokens item = new Tokens((String)history.get(history.size() - 1)); | |
1831 result.append(item.at(item.countTokens() - 1)); | |
1832 } else { | |
1833 String tail = cmd.substring(1); | |
1385 | 1834 switch (tail.charAt(0)) { |
1835 case '0': | |
1836 case '1': | |
1837 case '2': | |
1838 case '3': | |
1839 case '4': | |
1840 case '5': | |
1841 case '6': | |
1842 case '7': | |
1843 case '8': | |
1844 case '9': | |
1845 case '-': { | |
1846 int index = Integer.parseInt(tail); | |
1847 if (index < 0) { | |
1848 index = history.size() + index; | |
1849 } | |
1850 if (index > size) { | |
1851 err.println("No such history item"); | |
1852 } else { | |
1853 result.append((String)history.get(index)); | |
1854 } | |
1855 break; | |
0 | 1856 } |
1385 | 1857 default: { |
1858 for (int i = history.size() - 1; i >= 0; i--) { | |
1859 String s = (String)history.get(i); | |
1860 if (s.startsWith(tail)) { | |
1861 result.append(s); | |
1862 } | |
1863 } | |
1864 } | |
0 | 1865 } |
1866 } | |
1867 } | |
1868 if (result.length() == 0) { | |
1869 err.println("malformed history reference"); | |
1870 ln = ""; | |
1871 } else { | |
1872 if (start < ln.length()) { | |
1873 result.append(ln.substring(start)); | |
1874 } | |
1875 ln = result.toString(); | |
1876 if (!doEcho) { | |
1877 out.println(ln); | |
1878 } | |
1879 } | |
1880 } | |
1881 } | |
1882 | |
1883 if (doEcho) { | |
1884 out.println("+ " + ln); | |
1885 } | |
1886 | |
1887 PrintStream redirect = null; | |
1888 Tokens t = new Tokens(ln); | |
1889 if (t.hasMoreTokens()) { | |
1890 boolean error = false; | |
3939 | 1891 if (putInHistory) history.add(ln); |
0 | 1892 int len = t.countTokens(); |
1893 if (len > 2) { | |
1894 String r = t.at(len - 2); | |
1895 if (r.equals(">") || r.equals(">>")) { | |
1896 boolean append = r.length() == 2; | |
1897 String file = t.at(len - 1); | |
1898 try { | |
1899 redirect = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append))); | |
1900 t.trim(2); | |
1901 } catch (Exception e) { | |
1902 out.println("Error: " + e); | |
1903 if (verboseExceptions) { | |
1904 e.printStackTrace(out); | |
1905 } | |
1906 error = true; | |
1907 } | |
1908 } | |
1909 } | |
1910 if (!error) { | |
1911 PrintStream savedout = out; | |
1912 if (redirect != null) { | |
1913 out = redirect; | |
1914 } | |
1915 try { | |
1916 executeCommand(t); | |
1917 } catch (Exception e) { | |
1918 err.println("Error: " + e); | |
1919 if (verboseExceptions) { | |
1920 e.printStackTrace(err); | |
1921 } | |
1922 } finally { | |
1923 if (redirect != null) { | |
1924 out = savedout; | |
1925 redirect.close(); | |
1926 } | |
1927 } | |
1928 } | |
1929 } | |
1930 } | |
1931 | |
1932 void executeCommand(Tokens args) { | |
1933 String cmd = args.nextToken(); | |
1934 | |
1935 Command doit = findCommand(cmd); | |
1936 | |
1937 /* | |
1938 * Check for an unknown command | |
1939 */ | |
1940 if (doit == null) { | |
1941 out.println("Unrecognized command. Try help..."); | |
1942 } else if (!debugger.isAttached() && !doit.okIfDisconnected) { | |
1943 out.println("Command not valid until the attached to a VM"); | |
1944 } else { | |
1945 try { | |
1946 doit.doit(args); | |
1947 } catch (Exception e) { | |
1948 out.println("Error: " + e); | |
1949 if (verboseExceptions) { | |
1950 e.printStackTrace(out); | |
1951 } | |
1952 } | |
1953 } | |
1954 } | |
1955 } |