annotate agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java @ 11054:38ea2efa32a7

8010278: SA: provide mechanism for using an alternative SA debugger back-end. Reviewed-by: sla, dsamersoff
author kevinw
date Wed, 26 Jun 2013 00:01:20 +0100
parents da91efe96a93
children 7fe6ef09d242
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: 3938
diff changeset
2 * Copyright (c) 2003, 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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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.tools.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.tools.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.soql.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
37 This is command line SOQL (Simple Object Query Language) interpreter.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 */
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public class SOQL extends Tool {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 SOQL soql = new SOQL();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 soql.start(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 soql.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
47 public SOQL() {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
48 super();
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
49 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
50
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
51 public SOQL(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
52 super(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
53 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 6725
diff changeset
54
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 protected SOQLEngine soqlEngine;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 protected BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
a61af66fc99e Initial load
duke
parents:
diff changeset
57 protected PrintStream out = System.out;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static protected String prompt = "soql> ";
a61af66fc99e Initial load
duke
parents:
diff changeset
59 static protected String secondPrompt = "> ";
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 soqlEngine = SOQLEngine.getEngine();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 out.print(prompt);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 String line = in.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (line == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 StringTokenizer st = new StringTokenizer(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (st.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 String cmd = st.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (cmd.equals("select")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 handleSelect(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 } else if (cmd.equals("classes")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 handleClasses(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 } else if (cmd.equals("class")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 handleClass(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else if (cmd.equals("object")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 handleObject(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 } else if (cmd.equals("quit")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 out.println("Bye!");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 } else if (cmd.equals("")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // do nothing ...
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 handleUnknown(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 protected void handleSelect(String query) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 StringBuffer buf = new StringBuffer(query);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 String tmp = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 out.print(secondPrompt);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 tmp = in.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } catch (IOException ioe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (tmp.equals("") || tmp.equals("go"))
a61af66fc99e Initial load
duke
parents:
diff changeset
108 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 buf.append('\n');
a61af66fc99e Initial load
duke
parents:
diff changeset
110 buf.append(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 query = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 soqlEngine.executeQuery(query,
a61af66fc99e Initial load
duke
parents:
diff changeset
116 new ObjectVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public void visit(Object o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (o != null && o instanceof JSJavaObject) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 String oopAddr = ((JSJavaObject)o).getOop().getHandle().toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 out.println(oopAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 out.println((o == null)? "null" : o.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 });
a61af66fc99e Initial load
duke
parents:
diff changeset
126 } catch (SOQLException se) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 se.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 protected void handleClasses(String line) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // just list all InstanceKlasses
a61af66fc99e Initial load
duke
parents:
diff changeset
133 InstanceKlass[] klasses = SystemDictionaryHelper.getAllInstanceKlasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 for (int i = 0; i < klasses.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 out.print(klasses[i].getName().asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
136 out.print(" @");
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3938
diff changeset
137 out.println(klasses[i].getAddress());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 protected void handleClass(String line) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 StringTokenizer st = new StringTokenizer(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 st.nextToken(); // ignore "class"
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (st.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 String className = st.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 InstanceKlass klass = SystemDictionaryHelper.findInstanceKlass(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (klass == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 out.println("class " + className + " not found");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // klass.iterate(new OopPrinter(out), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // base class
a61af66fc99e Initial load
duke
parents:
diff changeset
153 InstanceKlass base = (InstanceKlass) klass.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (base != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 out.println("super");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 out.print("\t");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 out.println(base.getName().asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // list immediate fields only
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3938
diff changeset
161 U2Array fields = klass.getFields();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 3938
diff changeset
162 int numFields = (int) fields.length();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163 ConstantPool cp = klass.getConstants();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 out.println("fields");
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (numFields != 0) {
3938
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
166 for (int f = 0; f < numFields; f++){
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
167 Symbol f_name = klass.getFieldName(f);
e6b1331a51d2 7086585: make Java field injection more flexible
never
parents: 1552
diff changeset
168 Symbol f_sig = klass.getFieldSignature(f);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 StringBuffer sigBuf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 new SignatureConverter(f_sig, sigBuf).dispatchField();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
172 out.print(sigBuf.toString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
173 out.print(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
174 out.println(f_name.asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 out.println("\tno fields in this class");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 out.println("usage: class <name of the class>");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 protected Oop getOopAtAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 OopHandle oopHandle = addr.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return VM.getVM().getObjectHeap().newOop(oopHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 protected void handleObject(String line) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 StringTokenizer st = new StringTokenizer(line);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 st.nextToken(); // ignore "object"
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (st.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 String addrStr = st.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 Address addr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 Debugger dbg = VM.getVM().getDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 addr = dbg.parseAddress(addrStr);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 out.println("invalid address : " + e.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Oop oop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 oop = getOopAtAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 out.println("invalid object : " + e.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (oop != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 oop.iterate(new OopPrinter(out), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 out.println("null object!");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 out.println("usage: object <address>");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 protected void handleUnknown(String line) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 out.println("Unknown command!");
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }