1 | /*
|
---|
2 | * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
|
---|
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
---|
4 | *
|
---|
5 | * This code is free software; you can redistribute it and/or modify it
|
---|
6 | * under the terms of the GNU General Public License version 2 only, as
|
---|
7 | * published by the Free Software Foundation.
|
---|
8 | *
|
---|
9 | * This code is distributed in the hope that it will be useful, but WITHOUT
|
---|
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
---|
12 | * version 2 for more details (a copy is included in the LICENSE file that
|
---|
13 | * accompanied this code).
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License version
|
---|
16 | * 2 along with this work; if not, write to the Free Software Foundation,
|
---|
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
18 | *
|
---|
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
---|
20 | * or visit www.oracle.com if you need additional information or have any
|
---|
21 | * questions.
|
---|
22 | *
|
---|
23 | */
|
---|
24 |
|
---|
25 | import com.sun.jdi.*;
|
---|
26 | import java.util.*;
|
---|
27 |
|
---|
28 |
|
---|
29 | // This just contains a bunch of methods that call various JDI methods.
|
---|
30 | // It is called from the sagtest.java jtreg test to get this info for the standard
|
---|
31 | // JDI and from the sagclient.java test to get this info for the SA JDI.
|
---|
32 |
|
---|
33 | class comparator implements Comparator {
|
---|
34 |
|
---|
35 | public int compare(Object o1, Object o2) {
|
---|
36 | ReferenceType rt1 = (ReferenceType)o1;
|
---|
37 | ReferenceType rt2 = (ReferenceType)o2;
|
---|
38 | return rt1.signature().compareTo(rt2.signature());
|
---|
39 | }
|
---|
40 |
|
---|
41 | public boolean equals(Object oo) {
|
---|
42 | return false;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public class sagdoit {
|
---|
47 |
|
---|
48 | VirtualMachine myVm;
|
---|
49 | int margin = 0;
|
---|
50 | static String blanks = " ";
|
---|
51 | static int nblanks = blanks.length();
|
---|
52 |
|
---|
53 | sagdoit(VirtualMachine vm) {
|
---|
54 | super();
|
---|
55 | myVm = vm;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void indent(int count) {
|
---|
59 | margin += count;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void pp(String msg) {
|
---|
63 | System.out.println(blanks.substring(nblanks - margin) + msg);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public void doAll() {
|
---|
67 | doThreadGroups();
|
---|
68 | //System.out.println("NOTE: dumping of class info is disabled in sagdoit.java");
|
---|
69 | //System.out.println(" just to keep the output small while working on objects");
|
---|
70 | doClasses(); //fixme jj: uncomment this to see all class info
|
---|
71 |
|
---|
72 | }
|
---|
73 | public void doThreadGroups() {
|
---|
74 | doThreadGroupList(myVm.topLevelThreadGroups());
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void doThreadGroupList(List groups) {
|
---|
78 | // sort; need a comparator
|
---|
79 | if (groups == null) {
|
---|
80 | return;
|
---|
81 | }
|
---|
82 |
|
---|
83 | Iterator myIter = groups.iterator();
|
---|
84 | while(myIter.hasNext()) {
|
---|
85 | ThreadGroupReference aGroup = (ThreadGroupReference)myIter.next();
|
---|
86 | doOneThreadGroup(aGroup);
|
---|
87 | }
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void doOneThreadGroup(ThreadGroupReference xx) {
|
---|
92 | pp("threadGroup:" + xx.name());
|
---|
93 | indent(4);
|
---|
94 | pp("parent() = " + xx.parent());
|
---|
95 | pp("threads:");
|
---|
96 | indent(4);
|
---|
97 | doThreadList(xx.threads());
|
---|
98 | indent(-4);
|
---|
99 | pp("threadGroups:");
|
---|
100 | indent(4);
|
---|
101 | doThreadGroupList(xx.threadGroups());
|
---|
102 | indent(-4);
|
---|
103 | indent(-4);
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void doThreads() {
|
---|
107 | doThreadList(myVm.allThreads());
|
---|
108 | }
|
---|
109 |
|
---|
110 | public void doThreadList(List threads) {
|
---|
111 | if (threads == null) {
|
---|
112 | return;
|
---|
113 | }
|
---|
114 | Iterator myIter = threads.iterator();
|
---|
115 | while(myIter.hasNext()) {
|
---|
116 | ThreadReference aThread = (ThreadReference)myIter.next();
|
---|
117 | doOneThread(aThread);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void doOneThread(ThreadReference xx) {
|
---|
122 | pp("Thread: " + xx.name());
|
---|
123 | indent(4);
|
---|
124 | pp("suspendCount() = " + xx.suspendCount());
|
---|
125 |
|
---|
126 | //void stop(ObjectReference throwable) throws InvalidTypeException;
|
---|
127 | //void interrupt();
|
---|
128 | pp("status() = " + xx.status());
|
---|
129 | pp("isSuspended() = " + xx.isSuspended());
|
---|
130 | pp("isAtBreakpoint() = " + xx.isAtBreakpoint());
|
---|
131 |
|
---|
132 | pp("threadGroup() = " + xx.threadGroup());
|
---|
133 | indent(-4);
|
---|
134 |
|
---|
135 | indent(4);
|
---|
136 | try {
|
---|
137 | List allFrames = xx.frames();
|
---|
138 | for (int ii = 0; ii < xx.frameCount(); ii++) {
|
---|
139 | StackFrame oneFrame = xx.frame(ii);
|
---|
140 | pp("frame(" + ii + ") = " + oneFrame);
|
---|
141 | doOneFrame(oneFrame);
|
---|
142 | }
|
---|
143 | //List frames(int start, int length) throws IncompatibleThreadStateException;
|
---|
144 | // unsupported List allMonitors = xx.ownedMonitors();
|
---|
145 | // unsupported pp("currentContendedMonitor() = " + xx.currentContendedMonitor());
|
---|
146 | } catch (IncompatibleThreadStateException ee) {
|
---|
147 | pp("GOT IncompatibleThreadStateException: " + ee);
|
---|
148 | }
|
---|
149 | indent(-4);
|
---|
150 | }
|
---|
151 |
|
---|
152 | public void doOneFrame(StackFrame frame) {
|
---|
153 |
|
---|
154 | List localVars = null;
|
---|
155 | try {
|
---|
156 | localVars = frame.visibleVariables();
|
---|
157 | } catch (AbsentInformationException ee) {
|
---|
158 | // we compile with -g so this shouldn't happen
|
---|
159 | return;
|
---|
160 | }
|
---|
161 | indent(4);
|
---|
162 | for (Iterator it = localVars.iterator(); it.hasNext();) {
|
---|
163 | LocalVariable lv = (LocalVariable) it.next();
|
---|
164 | pp("lv name = " + lv.name() +
|
---|
165 | ", type = " + lv.typeName() +
|
---|
166 | ", sig = " + lv.signature() +
|
---|
167 | ", gsig = " + lv.genericSignature() +
|
---|
168 | ", isVis = " + lv.isVisible(frame) +
|
---|
169 | ", isArg = " + lv.isArgument());
|
---|
170 | }
|
---|
171 | indent(-4);
|
---|
172 | }
|
---|
173 |
|
---|
174 | public void doClasses() {
|
---|
175 | List myClasses = myVm.allClasses();
|
---|
176 | myClasses = new ArrayList(myClasses);
|
---|
177 | Collections.sort(myClasses, new comparator());
|
---|
178 | for (int ii = 0; ii < myClasses.size(); ii++) {
|
---|
179 | // Spec says each is a ReferenceType
|
---|
180 | //System.out.println("class " + (ii + 1) + " is " + myClasses.get(ii));
|
---|
181 | ReferenceType aClass = (ReferenceType)myClasses.get(ii);
|
---|
182 | System.out.println("class " + (ii + 1) + " is " + aClass.signature());
|
---|
183 | doOneClass(aClass);
|
---|
184 | // Uncomment this to just do a few classes.
|
---|
185 | //if ( ii > 4) break;
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | public void doOneClass(ReferenceType xx) {
|
---|
190 | indent(5);
|
---|
191 | // inherited from Mirror
|
---|
192 | pp("toString() = " + xx.toString());
|
---|
193 | pp("virtualMachine() = " + xx.virtualMachine());
|
---|
194 |
|
---|
195 | // inherited from Type
|
---|
196 | pp("name() = " + xx.name());
|
---|
197 | pp("signature() = " + xx.signature());
|
---|
198 |
|
---|
199 | // ReferenceType fields
|
---|
200 | doReferenceTypeFields(xx);
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | String className = xx.getClass().getName();
|
---|
207 | pp("subclass = " + className);
|
---|
208 |
|
---|
209 | Class referenceType = null;
|
---|
210 | Class arrayType = null;
|
---|
211 | Class classType = null;
|
---|
212 | Class interfaceType = null;
|
---|
213 |
|
---|
214 | try {
|
---|
215 | referenceType = Class.forName("com.sun.jdi.ReferenceType");
|
---|
216 | arrayType = Class.forName("com.sun.jdi.ArrayType");
|
---|
217 | interfaceType = Class.forName("com.sun.jdi.InterfaceType");
|
---|
218 | classType = Class.forName("com.sun.jdi.ClassType");
|
---|
219 | } catch (ClassNotFoundException ee) {
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | if (referenceType.isInstance(xx)) {
|
---|
224 | pp("ReferenceType fields");
|
---|
225 | ReferenceType rr = (ReferenceType)xx;
|
---|
226 |
|
---|
227 | if (arrayType.isInstance(xx)) {
|
---|
228 | pp("ArrayType fields");
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (classType.isInstance(xx)) {
|
---|
232 | pp("ClassType fields");
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (interfaceType.isInstance(xx)) {
|
---|
236 | pp("InterfaceType fields");
|
---|
237 | }
|
---|
238 | }
|
---|
239 | indent(-5);
|
---|
240 |
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | public void doReferenceTypeFields(ReferenceType xx) {
|
---|
245 | Object zz;
|
---|
246 | pp("classLoader() = " + xx.classLoader());
|
---|
247 | try {zz =xx.sourceName();} catch(AbsentInformationException ee) { zz = ee;} pp("sourceName() = " + zz);
|
---|
248 | try {zz =xx.sourceNames("stratum");} catch(AbsentInformationException ee) { zz = ee;} pp("sourceNames() = " + zz);
|
---|
249 | try {zz =xx.sourcePaths("stratum");} catch(AbsentInformationException ee) { zz = ee;} pp("sourcePaths() = " + zz);
|
---|
250 | //try {zz =xx.sourceDebugExtension();} catch(AbsentInformationException ee) { zz = ee;} pp("sourceDebugExtension() = " + zz);
|
---|
251 | //fixme: jj; should sourceDebugExtension throw UnsupportedOperationException?
|
---|
252 | try {zz =xx.sourceDebugExtension();} catch(Exception ee) { zz = ee;} pp("sourceDebugExtension() = " + zz);
|
---|
253 | // If xx is an array, this can cause a ClassNotLoadedException on the
|
---|
254 | // component type. Is that a JDI bug?
|
---|
255 | pp("isStatic() = " + xx.isStatic());
|
---|
256 | pp("isAbstract() = " + xx.isAbstract());
|
---|
257 | pp("isFinal() = " + xx.isFinal());
|
---|
258 | pp("isPrepared() = " + xx.isPrepared());
|
---|
259 | pp("isVerified() = " + xx.isVerified());
|
---|
260 | pp("isInitialized() = " + xx.isInitialized());
|
---|
261 | pp("failedToInitialize() = " + xx.failedToInitialize());
|
---|
262 | pp("fields() = " + xx.fields());
|
---|
263 | pp("visibleFields() = " + xx.visibleFields());
|
---|
264 | pp("allFields() = " + xx.allFields());
|
---|
265 | pp("fieldByName(String fieldName) = " + xx.fieldByName("fieldName"));
|
---|
266 | pp("methods() = " + xx.methods());
|
---|
267 |
|
---|
268 |
|
---|
269 | List meths = xx.methods();
|
---|
270 | Iterator iter = meths.iterator();
|
---|
271 | while (iter.hasNext()) {
|
---|
272 | Method mm = (Method)iter.next();
|
---|
273 | pp(" name/sig:" + mm.name() + "/" + mm.signature());
|
---|
274 | }
|
---|
275 |
|
---|
276 | pp(" visibleMethods() = " + xx.visibleMethods());
|
---|
277 |
|
---|
278 | //if (1 == 1) return;
|
---|
279 |
|
---|
280 | pp("allMethods() = " + xx.allMethods());
|
---|
281 |
|
---|
282 |
|
---|
283 | pp("methodsByName(String name) = " + xx.methodsByName("name"));
|
---|
284 | pp("methodsByName(String name, String signature) = " + xx.methodsByName("name", "signature"));
|
---|
285 | pp("nestedTypes() = " + xx.nestedTypes());
|
---|
286 | //pp("getValue(Field field) = " + xx.getValue("field"));
|
---|
287 | pp("getValue(Field field) = " + "fixme: jjh");
|
---|
288 | //pp("getValues(List fields) = " + xx.getValues(new List[] = {"fields"}));
|
---|
289 | pp("getValues(List fields) = " + "fixme: jjh");
|
---|
290 | pp("classObject() = " + xx.classObject());
|
---|
291 | //x pp("allLineLocations() = " + xx.allLineLocations());
|
---|
292 | //x pp("allLineLocations(String stratum, String sourceName) = " + xx.allLineLocations("stratum", "sourceName"));
|
---|
293 | //x pp("locationsOfLine(int lineNumber) = " + xx.locationsOfLine(89));
|
---|
294 | //x pp("locationsOfLine(String stratum, String sourceName, int lineNumber) = " + xx.locationsOfLine("stratum", "sourceName", 89));
|
---|
295 | pp("availableStrata() = " + xx.availableStrata());
|
---|
296 | pp("defaultStratum() = " + xx.defaultStratum());
|
---|
297 | pp("equals(Object obj) = " + xx.equals(xx));
|
---|
298 | pp("hashCode() = " + xx.hashCode());
|
---|
299 | }
|
---|
300 |
|
---|
301 | }
|
---|
302 |
|
---|
303 | // try {
|
---|
304 | // ReferenceType rr = (ReferenceType)xx;
|
---|
305 | // pp("ReferenceType fields");
|
---|
306 |
|
---|
307 | // try {
|
---|
308 | // ArrayType ff = (ArrayType)xx;
|
---|
309 | // pp("ArrayType fields");
|
---|
310 |
|
---|
311 | // } catch(ClassCastException ee) {
|
---|
312 | // }
|
---|
313 |
|
---|
314 | // try {
|
---|
315 | // ClassType ff = (ClassType)xx;
|
---|
316 | // pp("ClassType fields");
|
---|
317 |
|
---|
318 | // } catch(ClassCastException ee) {
|
---|
319 | // }
|
---|
320 |
|
---|
321 | // try {
|
---|
322 | // InterfaceType ff = (InterfaceType)xx;
|
---|
323 | // pp("InterfaceType fields");
|
---|
324 |
|
---|
325 | // } catch(ClassCastException ee) {
|
---|
326 | // }
|
---|
327 |
|
---|
328 | // } catch(ClassCastException ee) {
|
---|
329 | // }
|
---|