annotate agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java @ 8756:686916dc0439

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