annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 8750:39432a1cefdd

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