annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 6782:5a98bf7d847b

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