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