annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 3939:f6f3bb0ee072

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