Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/test/jdi/sagdoit.java
38764 views
/*1* Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import com.sun.jdi.*;25import java.util.*;262728// This just contains a bunch of methods that call various JDI methods.29// It is called from the sagtest.java jtreg test to get this info for the standard30// JDI and from the sagclient.java test to get this info for the SA JDI.3132class comparator implements Comparator {3334public int compare(Object o1, Object o2) {35ReferenceType rt1 = (ReferenceType)o1;36ReferenceType rt2 = (ReferenceType)o2;37return rt1.signature().compareTo(rt2.signature());38}3940public boolean equals(Object oo) {41return false;42}43}4445public class sagdoit {4647VirtualMachine myVm;48int margin = 0;49static String blanks = " ";50static int nblanks = blanks.length();5152sagdoit(VirtualMachine vm) {53super();54myVm = vm;55}5657void indent(int count) {58margin += count;59}6061void pp(String msg) {62System.out.println(blanks.substring(nblanks - margin) + msg);63}6465public void doAll() {66doThreadGroups();67//System.out.println("NOTE: dumping of class info is disabled in sagdoit.java");68//System.out.println(" just to keep the output small while working on objects");69doClasses(); //fixme jj: uncomment this to see all class info7071}72public void doThreadGroups() {73doThreadGroupList(myVm.topLevelThreadGroups());74}7576private void doThreadGroupList(List groups) {77// sort; need a comparator78if (groups == null) {79return;80}8182Iterator myIter = groups.iterator();83while(myIter.hasNext()) {84ThreadGroupReference aGroup = (ThreadGroupReference)myIter.next();85doOneThreadGroup(aGroup);86}8788}8990public void doOneThreadGroup(ThreadGroupReference xx) {91pp("threadGroup:" + xx.name());92indent(4);93pp("parent() = " + xx.parent());94pp("threads:");95indent(4);96doThreadList(xx.threads());97indent(-4);98pp("threadGroups:");99indent(4);100doThreadGroupList(xx.threadGroups());101indent(-4);102indent(-4);103}104105public void doThreads() {106doThreadList(myVm.allThreads());107}108109public void doThreadList(List threads) {110if (threads == null) {111return;112}113Iterator myIter = threads.iterator();114while(myIter.hasNext()) {115ThreadReference aThread = (ThreadReference)myIter.next();116doOneThread(aThread);117}118}119120public void doOneThread(ThreadReference xx) {121pp("Thread: " + xx.name());122indent(4);123pp("suspendCount() = " + xx.suspendCount());124125//void stop(ObjectReference throwable) throws InvalidTypeException;126//void interrupt();127pp("status() = " + xx.status());128pp("isSuspended() = " + xx.isSuspended());129pp("isAtBreakpoint() = " + xx.isAtBreakpoint());130131pp("threadGroup() = " + xx.threadGroup());132indent(-4);133134indent(4);135try {136List allFrames = xx.frames();137for (int ii = 0; ii < xx.frameCount(); ii++) {138StackFrame oneFrame = xx.frame(ii);139pp("frame(" + ii + ") = " + oneFrame);140doOneFrame(oneFrame);141}142//List frames(int start, int length) throws IncompatibleThreadStateException;143// unsupported List allMonitors = xx.ownedMonitors();144// unsupported pp("currentContendedMonitor() = " + xx.currentContendedMonitor());145} catch (IncompatibleThreadStateException ee) {146pp("GOT IncompatibleThreadStateException: " + ee);147}148indent(-4);149}150151public void doOneFrame(StackFrame frame) {152153List localVars = null;154try {155localVars = frame.visibleVariables();156} catch (AbsentInformationException ee) {157// we compile with -g so this shouldn't happen158return;159}160indent(4);161for (Iterator it = localVars.iterator(); it.hasNext();) {162LocalVariable lv = (LocalVariable) it.next();163pp("lv name = " + lv.name() +164", type = " + lv.typeName() +165", sig = " + lv.signature() +166", gsig = " + lv.genericSignature() +167", isVis = " + lv.isVisible(frame) +168", isArg = " + lv.isArgument());169}170indent(-4);171}172173public void doClasses() {174List myClasses = myVm.allClasses();175myClasses = new ArrayList(myClasses);176Collections.sort(myClasses, new comparator());177for (int ii = 0; ii < myClasses.size(); ii++) {178// Spec says each is a ReferenceType179//System.out.println("class " + (ii + 1) + " is " + myClasses.get(ii));180ReferenceType aClass = (ReferenceType)myClasses.get(ii);181System.out.println("class " + (ii + 1) + " is " + aClass.signature());182doOneClass(aClass);183// Uncomment this to just do a few classes.184//if ( ii > 4) break;185}186}187188public void doOneClass(ReferenceType xx) {189indent(5);190// inherited from Mirror191pp("toString() = " + xx.toString());192pp("virtualMachine() = " + xx.virtualMachine());193194// inherited from Type195pp("name() = " + xx.name());196pp("signature() = " + xx.signature());197198// ReferenceType fields199doReferenceTypeFields(xx);200201202203204205String className = xx.getClass().getName();206pp("subclass = " + className);207208Class referenceType = null;209Class arrayType = null;210Class classType = null;211Class interfaceType = null;212213try {214referenceType = Class.forName("com.sun.jdi.ReferenceType");215arrayType = Class.forName("com.sun.jdi.ArrayType");216interfaceType = Class.forName("com.sun.jdi.InterfaceType");217classType = Class.forName("com.sun.jdi.ClassType");218} catch (ClassNotFoundException ee) {219}220221222if (referenceType.isInstance(xx)) {223pp("ReferenceType fields");224ReferenceType rr = (ReferenceType)xx;225226if (arrayType.isInstance(xx)) {227pp("ArrayType fields");228}229230if (classType.isInstance(xx)) {231pp("ClassType fields");232}233234if (interfaceType.isInstance(xx)) {235pp("InterfaceType fields");236}237}238indent(-5);239240}241242243public void doReferenceTypeFields(ReferenceType xx) {244Object zz;245pp("classLoader() = " + xx.classLoader());246try {zz =xx.sourceName();} catch(AbsentInformationException ee) { zz = ee;} pp("sourceName() = " + zz);247try {zz =xx.sourceNames("stratum");} catch(AbsentInformationException ee) { zz = ee;} pp("sourceNames() = " + zz);248try {zz =xx.sourcePaths("stratum");} catch(AbsentInformationException ee) { zz = ee;} pp("sourcePaths() = " + zz);249//try {zz =xx.sourceDebugExtension();} catch(AbsentInformationException ee) { zz = ee;} pp("sourceDebugExtension() = " + zz);250//fixme: jj; should sourceDebugExtension throw UnsupportedOperationException?251try {zz =xx.sourceDebugExtension();} catch(Exception ee) { zz = ee;} pp("sourceDebugExtension() = " + zz);252// If xx is an array, this can cause a ClassNotLoadedException on the253// component type. Is that a JDI bug?254pp("isStatic() = " + xx.isStatic());255pp("isAbstract() = " + xx.isAbstract());256pp("isFinal() = " + xx.isFinal());257pp("isPrepared() = " + xx.isPrepared());258pp("isVerified() = " + xx.isVerified());259pp("isInitialized() = " + xx.isInitialized());260pp("failedToInitialize() = " + xx.failedToInitialize());261pp("fields() = " + xx.fields());262pp("visibleFields() = " + xx.visibleFields());263pp("allFields() = " + xx.allFields());264pp("fieldByName(String fieldName) = " + xx.fieldByName("fieldName"));265pp("methods() = " + xx.methods());266267268List meths = xx.methods();269Iterator iter = meths.iterator();270while (iter.hasNext()) {271Method mm = (Method)iter.next();272pp(" name/sig:" + mm.name() + "/" + mm.signature());273}274275pp(" visibleMethods() = " + xx.visibleMethods());276277//if (1 == 1) return;278279pp("allMethods() = " + xx.allMethods());280281282pp("methodsByName(String name) = " + xx.methodsByName("name"));283pp("methodsByName(String name, String signature) = " + xx.methodsByName("name", "signature"));284pp("nestedTypes() = " + xx.nestedTypes());285//pp("getValue(Field field) = " + xx.getValue("field"));286pp("getValue(Field field) = " + "fixme: jjh");287//pp("getValues(List fields) = " + xx.getValues(new List[] = {"fields"}));288pp("getValues(List fields) = " + "fixme: jjh");289pp("classObject() = " + xx.classObject());290//x pp("allLineLocations() = " + xx.allLineLocations());291//x pp("allLineLocations(String stratum, String sourceName) = " + xx.allLineLocations("stratum", "sourceName"));292//x pp("locationsOfLine(int lineNumber) = " + xx.locationsOfLine(89));293//x pp("locationsOfLine(String stratum, String sourceName, int lineNumber) = " + xx.locationsOfLine("stratum", "sourceName", 89));294pp("availableStrata() = " + xx.availableStrata());295pp("defaultStratum() = " + xx.defaultStratum());296pp("equals(Object obj) = " + xx.equals(xx));297pp("hashCode() = " + xx.hashCode());298}299300}301302// try {303// ReferenceType rr = (ReferenceType)xx;304// pp("ReferenceType fields");305306// try {307// ArrayType ff = (ArrayType)xx;308// pp("ArrayType fields");309310// } catch(ClassCastException ee) {311// }312313// try {314// ClassType ff = (ClassType)xx;315// pp("ClassType fields");316317// } catch(ClassCastException ee) {318// }319320// try {321// InterfaceType ff = (InterfaceType)xx;322// pp("InterfaceType fields");323324// } catch(ClassCastException ee) {325// }326327// } catch(ClassCastException ee) {328// }329330331