annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents f6f3bb0ee072
children 5a98bf7d847b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1385
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.math.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.util.regex.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.Type;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.types.Field;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.HotSpotTypeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.types.basic.BasicType;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.types.CIntegerType;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.compiler.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.interpreter.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.oops.*;
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
43 import sun.jvm.hotspot.opto.*;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
44 import sun.jvm.hotspot.ci.*;
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")) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
637 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
638 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
639 public void visit(Klass k) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
640 if (k instanceof InstanceKlass) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
641 MethodArray methods = ((InstanceKlass)k).getMethods();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
642 for (int i = 0; i < methods.length(); i++) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
643 Method m = methods.at(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
644 MethodData mdo = m.getMethodData();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
645 if (mdo != null) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
646 out.println("MethodData " + mdo.getAddress() + " for " +
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
647 "method " + m.getMethodHolder().getName().asString() + "." +
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
648 m.getName().asString() +
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
649 m.getSignature().asString() + "@" + m.getAddress());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
650 mdo.printDataOn(out);
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
651 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
652 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
653 }
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
654 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
655 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
656 );
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
657 } else {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
658 Address a = VM.getVM().getDebugger().parseAddress(s);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
659 MethodData mdo = (MethodData) Metadata.instantiateWrapperFor(a);
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
660 mdo.printDataOn(out);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
661 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
662 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
663 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
664 },
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
665 new Command("printall", "printall", false) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
666 // Print every MDO in the heap or the one referenced by expression.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
667 public void doit(Tokens t) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
668 if (t.countTokens() != 0) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
669 usage();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
670 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
671 SystemDictionary sysDict = VM.getVM().getSystemDictionary();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
672 sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
673 public void visit(Klass k) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
674 if (k instanceof InstanceKlass && ((InstanceKlass)k).getConstants().getCache() != null) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
675 MethodArray methods = ((InstanceKlass)k).getMethods();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
676 for (int i = 0; i < methods.length(); i++) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
677 Method m = methods.at(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
678 HTMLGenerator gen = new HTMLGenerator(false);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
679 out.println(gen.genHTML(m));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
680 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
681 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
682 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
683 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
684 );
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
685 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
686 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
687 },
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
688 new Command("dumpideal", "dumpideal { -a | id }", false) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
689 // 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
690 public void doit(Tokens t) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
691 if (t.countTokens() != 1) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
692 usage();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
693 } else {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
694 String name = t.nextToken();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
695 boolean all = name.equals("-a");
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
696 Threads threads = VM.getVM().getThreads();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
697 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
698 ByteArrayOutputStream bos = new ByteArrayOutputStream();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
699 thread.printThreadIDOn(new PrintStream(bos));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
700 if (all || bos.toString().equals(name)) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
701 if (thread instanceof CompilerThread) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
702 CompilerThread ct = (CompilerThread)thread;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
703 out.println(ct);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
704 ciEnv env = ct.env();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
705 if (env != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
706 Compile c = env.compilerData();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
707 c.root().dump(9999, out);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
708 } else {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
709 out.println(" not compiling");
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 },
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
717 new Command("dumpcfg", "dumpcfg { -a | id }", false) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
718 // 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
719 public void doit(Tokens t) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
720 if (t.countTokens() != 1) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
721 usage();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
722 } else {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
723 String name = t.nextToken();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
724 boolean all = name.equals("-a");
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
725 Threads threads = VM.getVM().getThreads();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
726 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
727 ByteArrayOutputStream bos = new ByteArrayOutputStream();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
728 thread.printThreadIDOn(new PrintStream(bos));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
729 if (all || bos.toString().equals(name)) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
730 if (thread instanceof CompilerThread) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
731 CompilerThread ct = (CompilerThread)thread;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
732 out.println(ct);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
733 ciEnv env = ct.env();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
734 if (env != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
735 Compile c = env.compilerData();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
736 c.cfg().dump(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 new Command("dumpilt", "dumpilt { -a | id }", false) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
745 // dumps the InlineTree of a C2 compile
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() != 1) {
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 } else {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
750 String name = t.nextToken();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
751 boolean all = name.equals("-a");
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
752 Threads threads = VM.getVM().getThreads();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
753 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
754 ByteArrayOutputStream bos = new ByteArrayOutputStream();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
755 thread.printThreadIDOn(new PrintStream(bos));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
756 if (all || bos.toString().equals(name)) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
757 if (thread instanceof CompilerThread) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
758 CompilerThread ct = (CompilerThread)thread;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
759 ciEnv env = ct.env();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
760 if (env != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
761 Compile c = env.compilerData();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
762 InlineTree ilt = c.ilt();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
763 if (ilt != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
764 ilt.print(out);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
765 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
766 }
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 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
769 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
770 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
771 }
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 new Command("vmstructsdump", "vmstructsdump", false) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
774 public void doit(Tokens t) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
775 if (t.countTokens() != 0) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
776 usage();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
777 return;
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 // 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
781 // be read back.
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
782 Iterator i = agent.getTypeDataBase().getTypes();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
783 // 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
784 HashSet emitted = new HashSet();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
785 Stack pending = new Stack();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
786 while (i.hasNext()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
787 Type n = (Type)i.next();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
788 if (emitted.contains(n.getName())) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
789 continue;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
790 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
791
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
792 while (n != null && !emitted.contains(n.getName())) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
793 pending.push(n);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
794 n = n.getSuperclass();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
795 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
796 while (!pending.empty()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
797 n = (Type)pending.pop();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
798 dumpType(n);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
799 emitted.add(n.getName());
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
800 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
801 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
802 i = agent.getTypeDataBase().getTypes();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
803 while (i.hasNext()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
804 dumpFields((Type)i.next(), false);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
805 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
806 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
807 },
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
808
0
a61af66fc99e Initial load
duke
parents:
diff changeset
809 new Command("inspect", "inspect expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
811 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
813 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
815 SimpleTreeNode node = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
816 if (VM.getVM().getUniverse().heap().isInReserved(a)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 OopHandle handle = a.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
818 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
819 node = new OopTreeNodeAdapter(oop, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 out.println("instance of " + node.getValue() + " @ " + a +
a61af66fc99e Initial load
duke
parents:
diff changeset
822 " (size = " + oop.getObjectSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
823 } else if (VM.getVM().getCodeCache().contains(a)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 CodeBlob blob = VM.getVM().getCodeCache().findBlobUnsafe(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
825 a = blob.headerBegin();
a61af66fc99e Initial load
duke
parents:
diff changeset
826 }
a61af66fc99e Initial load
duke
parents:
diff changeset
827 if (node == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 Type type = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
829 if (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
830 out.println("Type is " + type.getName() + " (size of " + type.getSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
831 node = new CTypeTreeNodeAdapter(a, type, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834 if (node != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 printNode(node);
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 },
a61af66fc99e Initial load
duke
parents:
diff changeset
840 new Command("jhisto", "jhisto", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
841 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
842 ObjectHistogram histo = new ObjectHistogram();
a61af66fc99e Initial load
duke
parents:
diff changeset
843 histo.run(out, err);
a61af66fc99e Initial load
duke
parents:
diff changeset
844 }
a61af66fc99e Initial load
duke
parents:
diff changeset
845 },
a61af66fc99e Initial load
duke
parents:
diff changeset
846 new Command("jstack", "jstack [-v]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 boolean verbose = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852 StackTrace jstack = new StackTrace(verbose, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 jstack.run(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
855 },
a61af66fc99e Initial load
duke
parents:
diff changeset
856 new Command("print", "print expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
858 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
860 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
862 HTMLGenerator gen = new HTMLGenerator(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
863 out.println(gen.genHTML(a));
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866 },
a61af66fc99e Initial load
duke
parents:
diff changeset
867 new Command("printas", "printas type expression", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 if (t.countTokens() != 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
871 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
873 Address a = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
874 CTypeTreeNodeAdapter node = new CTypeTreeNodeAdapter(a, type, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 out.println("pointer to " + type + " @ " + a +
a61af66fc99e Initial load
duke
parents:
diff changeset
877 " (size = " + type.getSize() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
878 printNode(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880 }
a61af66fc99e Initial load
duke
parents:
diff changeset
881 },
a61af66fc99e Initial load
duke
parents:
diff changeset
882 new Command("printstatics", "printstatics [ type ]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
883 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 if (t.countTokens() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
885 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
886 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 out.println("All known static fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
889 printNode(new CTypeTreeNodeAdapter(agent.getTypeDataBase().getTypes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
890 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
891 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
892 out.println("Static fields of " + type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
893 printNode(new CTypeTreeNodeAdapter(type));
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
896 }
a61af66fc99e Initial load
duke
parents:
diff changeset
897 },
a61af66fc99e Initial load
duke
parents:
diff changeset
898 new Command("pmap", "pmap", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
899 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
900 PMap pmap = new PMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
901 pmap.run(out, debugger.getAgent().getDebugger());
a61af66fc99e Initial load
duke
parents:
diff changeset
902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
903 },
a61af66fc99e Initial load
duke
parents:
diff changeset
904 new Command("pstack", "pstack [-v]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
905 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 boolean verbose = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
907 if (t.countTokens() > 0 && t.nextToken().equals("-v")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
908 verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910 PStack pstack = new PStack(verbose, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
911 pstack.run(out, debugger.getAgent().getDebugger());
a61af66fc99e Initial load
duke
parents:
diff changeset
912 }
a61af66fc99e Initial load
duke
parents:
diff changeset
913 },
a61af66fc99e Initial load
duke
parents:
diff changeset
914 new Command("quit", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
915 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
918 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
919 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
920 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
922 }
a61af66fc99e Initial load
duke
parents:
diff changeset
923 },
a61af66fc99e Initial load
duke
parents:
diff changeset
924 new Command("echo", "echo [ true | false ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
925 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
926 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
927 out.println("echo is " + doEcho);
a61af66fc99e Initial load
duke
parents:
diff changeset
928 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 doEcho = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
930 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
931 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
932 }
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934 },
a61af66fc99e Initial load
duke
parents:
diff changeset
935 new Command("versioncheck", "versioncheck [ true | false ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
936 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
937 if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
938 out.println("versioncheck is " +
a61af66fc99e Initial load
duke
parents:
diff changeset
939 (System.getProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck") == null));
a61af66fc99e Initial load
duke
parents:
diff changeset
940 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
941 if (Boolean.valueOf(t.nextToken()).booleanValue()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
942 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", null);
a61af66fc99e Initial load
duke
parents:
diff changeset
943 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
944 System.setProperty("sun.jvm.hotspot.runtime.VM.disableVersionCheck", "true");
a61af66fc99e Initial load
duke
parents:
diff changeset
945 }
a61af66fc99e Initial load
duke
parents:
diff changeset
946 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
948 }
a61af66fc99e Initial load
duke
parents:
diff changeset
949 }
a61af66fc99e Initial load
duke
parents:
diff changeset
950 },
a61af66fc99e Initial load
duke
parents:
diff changeset
951 new Command("scanoops", "scanoops start end [ type ]", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
953 if (t.countTokens() != 2 && t.countTokens() != 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
955 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 long stride = VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
957 Address base = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
958 Address end = VM.getVM().getDebugger().parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
959 Klass klass = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
960 if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961 klass = SystemDictionaryHelper.findInstanceKlass(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963 while (base != null && base.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 long step = stride;
a61af66fc99e Initial load
duke
parents:
diff changeset
965 OopHandle handle = base.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
966 if (RobustOopDeterminator.oopLooksValid(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
967 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
969 if (klass == null || oop.getKlass().isSubtypeOf(klass))
a61af66fc99e Initial load
duke
parents:
diff changeset
970 out.println(handle.toString() + " " + oop.getKlass().getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
971 step = oop.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
972 } catch (UnknownOopException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
973 // ok
a61af66fc99e Initial load
duke
parents:
diff changeset
974 } catch (RuntimeException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
975 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
976 }
a61af66fc99e Initial load
duke
parents:
diff changeset
977 }
a61af66fc99e Initial load
duke
parents:
diff changeset
978 base = base.addOffsetTo(step);
a61af66fc99e Initial load
duke
parents:
diff changeset
979 }
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
982 },
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
983 new Command("intConstant", "intConstant [ name [ value ] ]", true) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
984 public void doit(Tokens t) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
985 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
986 usage();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
987 return;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
988 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
989 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
990 if (t.countTokens() == 1) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
991 out.println("intConstant " + name + " " + db.lookupIntConstant(name));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
992 } else if (t.countTokens() == 0) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
993 Iterator i = db.getIntConstants();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
994 while (i.hasNext()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
995 String name = (String)i.next();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
996 out.println("intConstant " + name + " " + db.lookupIntConstant(name));
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 } else if (t.countTokens() == 2) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
999 String name = t.nextToken();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1000 Integer value = Integer.valueOf(t.nextToken());
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1001 db.addIntConstant(name, value);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1002 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1003 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1004 },
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1005 new Command("longConstant", "longConstant [ name [ value ] ]", true) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1006 public void doit(Tokens t) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1007 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 2) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1008 usage();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1009 return;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1010 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1011 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1012 if (t.countTokens() == 1) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1013 out.println("longConstant " + name + " " + db.lookupLongConstant(name));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1014 } else if (t.countTokens() == 0) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1015 Iterator i = db.getLongConstants();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1016 while (i.hasNext()) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1017 String name = (String)i.next();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1018 out.println("longConstant " + name + " " + db.lookupLongConstant(name));
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1019 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1020 } else if (t.countTokens() == 2) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1021 String name = t.nextToken();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1022 Long value = Long.valueOf(t.nextToken());
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1023 db.addLongConstant(name, value);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1024 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1025 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1026 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 new Command("field", "field [ type [ name fieldtype isStatic offset address ] ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 dumpFields(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 } else if (t.countTokens() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 Iterator i = agent.getTypeDataBase().getTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 dumpFields((Type)i.next());
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 BasicType containingType = (BasicType)agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1043
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 String fieldName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1045
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 // The field's Type must already be in the database -- no exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 Type fieldType = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1048
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 boolean isStatic = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 long offset = Long.parseLong(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 Address staticAddress = parseAddress(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 if (isStatic && staticAddress == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 staticAddress = lookup(containingType.getName() + "::" + fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 // check to see if the field already exists
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 Iterator i = containingType.getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 Field f = (Field) i.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 if (f.getName().equals(fieldName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 if (f.isStatic() != isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 throw new RuntimeException("static/nonstatic mismatch: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 if (!isStatic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 if (f.getOffset() != offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 throw new RuntimeException("bad redefinition of field offset: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 if (!f.getStaticFieldAddress().equals(staticAddress)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 throw new RuntimeException("bad redefinition of field location: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 if (f.getType() != fieldType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 throw new RuntimeException("bad redefinition of field type: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1079
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 // Create field by type
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 db.createField(containingType,
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 fieldName, fieldType,
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 isStatic,
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 staticAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
1087
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1090
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 new Command("tokenize", "tokenize ...", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 while (t.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 out.println("\"" + t.nextToken() + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 new Command("type", "type [ type [ name super isOop isInteger isUnsigned size ] ]", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 if (t.countTokens() != 1 && t.countTokens() != 0 && t.countTokens() != 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 if (t.countTokens() == 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 String typeName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 String superclassName = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 if (superclassName.equals("null")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 superclassName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 boolean isOop = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 boolean isInteger = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 boolean isUnsigned = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 long size = Long.parseLong(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1115
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 BasicType type = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 type = (BasicType)agent.getTypeDataBase().lookupType(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 } catch (RuntimeException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 if (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 if (type.isOopType() != isOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 throw new RuntimeException("oop mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 if (type.isCIntegerType() != isInteger) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 throw new RuntimeException("integer type mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 throw new RuntimeException("unsigned mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 if (type.getSuperclass() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 if (superclassName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 if (type.getSize() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 type.setSuperclass(agent.getTypeDataBase().lookupType(superclassName));
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 throw new RuntimeException("unexpected superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if (superclassName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 throw new RuntimeException("missing superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 if (!type.getSuperclass().getName().equals(superclassName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 throw new RuntimeException("incorrect superclass in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 if (type.getSize() != size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 if (type.getSize() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 type.setSize(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 throw new RuntimeException("size mismatch in type definition: " + t.input);
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1155
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 // Create type
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 db.createType(typeName, superclassName, isOop, isInteger, isUnsigned, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 } else if (t.countTokens() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 Type type = agent.getTypeDataBase().lookupType(t.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 dumpType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 Iterator i = agent.getTypeDataBase().getTypes();
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1164 // 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
1165 HashSet emitted = new HashSet();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1166 Stack pending = new Stack();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 while (i.hasNext()) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1168 Type n = (Type)i.next();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1169 if (emitted.contains(n.getName())) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1170 continue;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1171 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1172
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1173 while (n != null && !emitted.contains(n.getName())) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1174 pending.push(n);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1175 n = n.getSuperclass();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1176 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1177 while (!pending.empty()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1178 n = (Type)pending.pop();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1179 dumpType(n);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1180 emitted.add(n.getName());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1181 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1185
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 new Command("source", "source filename", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 String file = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 BufferedReader savedInput = in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 in = input;
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 run(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 in = savedInput;
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1207
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 },
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1210 new Command("search", "search [ heap | perm | rawheap | codecache | threads ] value", false) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 if (t.countTokens() != 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 usage();
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1214 return;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1215 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1216 String type = t.nextToken();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1217 final Address value = VM.getVM().getDebugger().parseAddress(t.nextToken());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1218 final long stride = VM.getVM().getAddressSize();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1219 if (type.equals("threads")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1220 Threads threads = VM.getVM().getThreads();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1221 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1222 Address base = thread.getBaseOfStackPointer();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1223 Address end = thread.getLastJavaSP();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1224 if (end == null) continue;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1225 if (end.lessThan(base)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1226 Address tmp = base;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1227 base = end;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1228 end = tmp;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1229 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1230 out.println("Searching " + base + " " + end);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1231 while (base != null && base.lessThan(end)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1232 Address val = base.getAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1233 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1234 out.println(base);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1235 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1236 base = base.addOffsetTo(stride);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1237 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1238 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1239 } else if (type.equals("rawheap")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1240 RawHeapVisitor iterator = new RawHeapVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1241 public void prologue(long used) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1243
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1244 public void visitAddress(Address addr) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1245 Address val = addr.getAddressAt(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 if (AddressOps.equal(val, value)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1247 out.println("found at " + addr);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1249 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1250 public void visitCompOopAddress(Address addr) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1251 Address val = addr.getCompOopAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1252 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1253 out.println("found at " + addr);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1254 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1256 public void epilogue() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1257 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1258 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1259 VM.getVM().getObjectHeap().iterateRaw(iterator);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3939
diff changeset
1260 } else if (type.equals("heap")) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1261 HeapVisitor iterator = new DefaultHeapVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1262 public boolean doObj(Oop obj) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1263 int index = 0;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1264 Address start = obj.getHandle();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1265 long end = obj.getObjectSize();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1266 while (index < end) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1267 Address val = start.getAddressAt(index);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 if (AddressOps.equal(val, value)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1269 out.println("found in " + obj.getHandle());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1270 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1272 index += 4;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1274 return false;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1275 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1276 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1277 VM.getVM().getObjectHeap().iterate(iterator);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1278 } else if (type.equals("codecache")) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1279 CodeCacheVisitor v = new CodeCacheVisitor() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1280 public void prologue(Address start, Address end) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1281 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1282 public void visit(CodeBlob blob) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1283 boolean printed = false;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1284 Address base = blob.getAddress();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1285 Address end = base.addOffsetTo(blob.getSize());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1286 while (base != null && base.lessThan(end)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1287 Address val = base.getAddressAt(0);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1288 if (AddressOps.equal(val, value)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1289 if (!printed) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1290 printed = true;
3388
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1291 try {
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1292 blob.printOn(out);
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1293 } catch (Exception e) {
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1294 out.println("Exception printing blob at " + base);
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1295 e.printStackTrace();
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 2426
diff changeset
1296 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1298 out.println("found at " + base + "\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1300 base = base.addOffsetTo(stride);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1302 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1303 public void epilogue() {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1304 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1305
a61af66fc99e Initial load
duke
parents:
diff changeset
1306
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1307 };
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1308 VM.getVM().getCodeCache().iterate(v);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1309
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 },
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1313 new Command("dumpcodecache", "dumpcodecache", false) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1314 public void doit(Tokens t) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1315 if (t.countTokens() != 0) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1316 usage();
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1317 } else {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1318 final PrintStream fout = out;
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1319 final HTMLGenerator gen = new HTMLGenerator(false);
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1320 CodeCacheVisitor v = new CodeCacheVisitor() {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1321 public void prologue(Address start, Address end) {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1322 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1323 public void visit(CodeBlob blob) {
1748
3e8fbc61cee8 6978355: renaming for 6961697
twisti
parents: 1552
diff changeset
1324 fout.println(gen.genHTML(blob.contentBegin()));
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1325 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1326 public void epilogue() {
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1327 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1328
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1329
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1330 };
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1331 VM.getVM().getCodeCache().iterate(v);
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1332 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1333 }
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 196
diff changeset
1334 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 new Command("where", "where { -a | id }", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 String name = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 boolean all = name.equals("-a");
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 thread.printThreadIDOn(new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 if (all || bos.toString().equals(name)) {
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1347 out.println(bos.toString() + " = " + thread.getAddress());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 HTMLGenerator gen = new HTMLGenerator(false);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1349 try {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1350 out.println(gen.genHTMLForJavaStackTrace(thread));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1351 } catch (Exception e) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1352 err.println("Error: " + e);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1353 if (verboseExceptions) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1354 e.printStackTrace(err);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1355 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1356 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 if (!all) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 if (!all) out.println("Couldn't find thread " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 },
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1364 new Command("thread", "thread { -a | id }", false) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1365 public void doit(Tokens t) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1366 if (t.countTokens() != 1) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1367 usage();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1368 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1369 String name = t.nextToken();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1370 Threads threads = VM.getVM().getThreads();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1371 boolean all = name.equals("-a");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1372 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1373 ByteArrayOutputStream bos = new ByteArrayOutputStream();
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1374 thread.printThreadIDOn(new PrintStream(bos));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1375 if (all || bos.toString().equals(name)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1376 out.println(bos.toString() + " = " + thread.getAddress());
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1377 if (!all) return;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1378 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1379 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1380 out.println("Couldn't find thread " + name);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1381 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1382 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1383 },
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1384
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 new Command("threads", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 thread.printThreadIDOn(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 out.println(" " + thread.getThreadName());
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 }
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 new Command("livenmethods", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 ArrayList nmethods = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 HTMLGenerator gen = new HTMLGenerator(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 for (JavaThread thread = threads.first(); thread != null; thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 if (vf instanceof CompiledVFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 NMethod c = ((CompiledVFrame)vf).getCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 if (!nmethods.contains(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 nmethods.add(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 out.println(gen.genHTML(c));
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 new Command("universe", false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 if (t.countTokens() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 Universe u = VM.getVM().getUniverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 out.println("Heap Parameters:");
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 u.heap().printOn(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 new Command("verbose", "verbose true | false", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 verboseExceptions = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 new Command("assert", "assert true | false", true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 if (t.countTokens() != 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 Assert.ASSERTS_ENABLED = Boolean.valueOf(t.nextToken()).booleanValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 },
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1455
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 private boolean verboseExceptions = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 private ArrayList history = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 private HashMap commands = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 private boolean doEcho = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1460
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 private Command findCommand(String key) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 return (Command)commands.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1464
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 public void printPrompt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 out.print("hsdb> ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1468
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 private DebuggerInterface debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 private HotSpotAgent agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 private JSJavaScriptEngine jsengine;
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 private BufferedReader in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 private PrintStream out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 private PrintStream err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1475
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 // called before debuggee attach
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 private void preAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 // nothing for now..
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1480
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 // called after debuggee attach
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 private void postAttach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 // create JavaScript engine and start it
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 jsengine = new JSJavaScriptEngine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 private ObjectReader reader = new ObjectReader();
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 private JSJavaFactory factory = new JSJavaFactoryImpl();
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 public ObjectReader getObjectReader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 return reader;
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 public JSJavaFactory getJSJavaFactory() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 return factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 protected void quit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 debugger.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 protected BufferedReader getInputReader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 return in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 protected PrintStream getOutputStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 return out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 protected PrintStream getErrorStream() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 jsengine.defineFunction(this,
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 this.getClass().getMethod("registerCommand",
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 new Class[] {
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 String.class, String.class, String.class
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 } catch (NoSuchMethodException exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 // should not happen, see below...!!
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 exp.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 jsengine.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1519
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 public void registerCommand(String cmd, String usage, final String func) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 commands.put(cmd, new Command(cmd, usage, false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 public void doit(Tokens t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 final int len = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 Object[] args = new Object[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 args[i] = t.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 jsengine.call(func, args);
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1532
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 public void setOutput(PrintStream o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 out = o;
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1536
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 public void setErr(PrintStream e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 err = e;
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1540
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 public CommandProcessor(DebuggerInterface debugger, BufferedReader in, PrintStream out, PrintStream err) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 this.debugger = debugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 this.agent = debugger.getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 this.in = in;
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 this.out = out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 this.err = err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 for (int i = 0; i < commandList.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 Command c = commandList[i];
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
1549 if (commands.get(c.name) != null) {
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
1550 throw new InternalError(c.name + " has multiple definitions");
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1748
diff changeset
1551 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 commands.put(c.name, c);
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 if (debugger.isAttached()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 postAttach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1558
a61af66fc99e Initial load
duke
parents:
diff changeset
1559
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 public void run(boolean prompt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 // Process interactive commands.
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 if (prompt) printPrompt();
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 String ln = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 ln = in.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 if (ln == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 if (prompt) err.println("Input stream closed.");
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1573
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1574 executeCommand(ln, prompt);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1577
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1578 static Pattern historyPattern = Pattern.compile("((!\\*)|(!\\$)|(!!-?)|(!-?[0-9][0-9]*)|(![a-zA-Z][^ ]*))");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1579
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1580 public void executeCommand(String ln, boolean putInHistory) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 if (ln.indexOf('!') != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 int size = history.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 if (size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 ln = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 err.println("History is empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 StringBuffer result = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 Matcher m = historyPattern.matcher(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 int start = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 while (m.find()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 if (m.start() > start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 result.append(ln.substring(start, m.start() - start));
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 start = m.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
1595
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 String cmd = m.group();
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 if (cmd.equals("!!")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 result.append((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 } else if (cmd.equals("!!-")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 item.trim(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 result.append(item.join(" "));
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 } else if (cmd.equals("!*")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 item.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 result.append(item.join(" "));
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 } else if (cmd.equals("!$")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 Tokens item = new Tokens((String)history.get(history.size() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 result.append(item.at(item.countTokens() - 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 String tail = cmd.substring(1);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1612 switch (tail.charAt(0)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1613 case '0':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1614 case '1':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1615 case '2':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1616 case '3':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1617 case '4':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1618 case '5':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1619 case '6':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1620 case '7':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1621 case '8':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1622 case '9':
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1623 case '-': {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1624 int index = Integer.parseInt(tail);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1625 if (index < 0) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1626 index = history.size() + index;
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1627 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1628 if (index > size) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1629 err.println("No such history item");
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1630 } else {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1631 result.append((String)history.get(index));
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1632 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1633 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 }
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1635 default: {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1636 for (int i = history.size() - 1; i >= 0; i--) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1637 String s = (String)history.get(i);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1638 if (s.startsWith(tail)) {
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1639 result.append(s);
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1640 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1641 }
bc32f286fae0 6945219: minor SA fixes
never
parents: 1040
diff changeset
1642 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 if (result.length() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 err.println("malformed history reference");
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 ln = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 if (start < ln.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 result.append(ln.substring(start));
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 ln = result.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 if (!doEcho) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 out.println(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1660
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 if (doEcho) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 out.println("+ " + ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1664
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 PrintStream redirect = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 Tokens t = new Tokens(ln);
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 if (t.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 boolean error = false;
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 3388
diff changeset
1669 if (putInHistory) history.add(ln);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 int len = t.countTokens();
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 if (len > 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 String r = t.at(len - 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 if (r.equals(">") || r.equals(">>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 boolean append = r.length() == 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 String file = t.at(len - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 redirect = new PrintStream(new BufferedOutputStream(new FileOutputStream(file, append)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 t.trim(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 error = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 if (!error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 PrintStream savedout = out;
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 if (redirect != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 out = redirect;
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 executeCommand(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 err.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 e.printStackTrace(err);
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 if (redirect != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 out = savedout;
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 redirect.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 }
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
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 void executeCommand(Tokens args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 String cmd = args.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1712
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 Command doit = findCommand(cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
1714
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 * Check for an unknown command
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 if (doit == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 out.println("Unrecognized command. Try help...");
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 } else if (!debugger.isAttached() && !doit.okIfDisconnected) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 out.println("Command not valid until the attached to a VM");
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 doit.doit(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 out.println("Error: " + e);
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 if (verboseExceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 e.printStackTrace(out);
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 }