agent/test/jdi/sagdoit.java

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial