Search in sources :

Example 11 with JavaClassLoader

use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.

the class InfoClassCommand method printClassDetails.

private void printClassDetails(JavaRuntime jr, String className, JavaClass jc) {
    String spaces = "    ";
    String cdeInfo = "N/A (CorruptDataException occurred)";
    try {
        out.print("name = " + jc.getName());
    } catch (CorruptDataException dce) {
        out.print("name = " + cdeInfo);
    }
    out.print("\n\n\t");
    out.print("ID = " + Utils.toHex(jc.getID()));
    String superClassId;
    try {
        JavaClass superClass = jc.getSuperclass();
        if (null == superClass) {
            superClassId = "<no superclass>";
        } else {
            superClassId = Utils.toHex(superClass.getID());
        }
    } catch (CorruptDataException dce) {
        superClassId = cdeInfo;
    }
    out.print(spaces);
    out.print("superID = " + superClassId);
    // Omitting size of class because that might differ between instances (i.e. arrays)
    String classLoaderId;
    try {
        JavaClassLoader jClassLoader = jc.getClassLoader();
        JavaObject jo = jClassLoader.getObject();
        if (jo != null) {
            classLoaderId = Utils.toHex(jo.getID());
        } else {
            classLoaderId = "<data unavailable>";
        }
    } catch (CorruptDataException cde) {
        classLoaderId = cdeInfo;
    }
    out.print(spaces);
    out.print("\n\t");
    out.print("classLoader = " + classLoaderId);
    String modifiersInfo;
    try {
        modifiersInfo = Utils.getClassModifierString(jc);
    } catch (CorruptDataException cde) {
        modifiersInfo = cdeInfo;
    }
    out.print(spaces);
    out.print("modifiers: " + modifiersInfo);
    out.print("\n\n");
    ClassStatistics d = getClassStatisticsFor(jr, jc);
    out.print("\tnumber of instances:     " + d.getCount() + "\n");
    out.print("\ttotal size of instances on the heap: " + d.getSize() + " bytes");
    out.print("\n\n");
    printClassHierarchy(jc);
    out.print("\n");
    printFields(jc);
    out.print("\n");
    printMethods(jc);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 12 with JavaClassLoader

use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.

the class PHDJavaRuntime method prepClassLoaders.

/**
 * Remember objects associated with class loaders
 * Performance optimization - we can then find these objects on a scan through the heap
 * and remember them, saving a fruitless search of the heap if they only exist in a javacore.
 */
private void prepClassLoaders() {
    if (metaJavaRuntime != null) {
        final PHDJavaClassLoader boot = loaders.get(null);
        for (Iterator it = metaJavaRuntime.getJavaClassLoaders(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof CorruptData)
                continue;
            JavaClassLoader load = (JavaClassLoader) next;
            try {
                JavaObject jo = load.getObject();
                saveExtraObject(boot, jo);
            } catch (CorruptDataException e) {
            }
        }
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 13 with JavaClassLoader

use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.

the class Utils method getClassGivenName.

public static JavaClass[] getClassGivenName(String className, JavaRuntime jr, PrintStream out) {
    Iterator itJavaClassLoader = jr.getJavaClassLoaders();
    List classes = new ArrayList();
    while (itJavaClassLoader.hasNext()) {
        Object nextCl = itJavaClassLoader.next();
        if (!(nextCl instanceof JavaClassLoader)) {
            continue;
        }
        JavaClassLoader jcl = (JavaClassLoader) nextCl;
        Iterator itJavaClass = jcl.getDefinedClasses();
        while (itJavaClass.hasNext()) {
            Object next = itJavaClass.next();
            if (!(next instanceof JavaClass)) {
                continue;
            }
            JavaClass jc = (JavaClass) next;
            String currClassName;
            try {
                currClassName = jc.getName();
                if (currClassName.equals(className)) {
                    classes.add(jc);
                }
            } catch (CorruptDataException e) {
                out.print("\t  <error getting class name while traversing classes: ");
                out.print(Exceptions.getCorruptDataExceptionString());
                out.print(">\n");
                currClassName = null;
            }
        }
    }
    if (classes.size() > 0) {
        return (JavaClass[]) classes.toArray(new JavaClass[0]);
    } else {
        return null;
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 14 with JavaClassLoader

use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.

the class Utils method getClassGivenAddress.

public static JavaClass getClassGivenAddress(long address, JavaRuntime jr) {
    Iterator itJavaClassLoader = jr.getJavaClassLoaders();
    while (itJavaClassLoader.hasNext()) {
        Object nextCl = itJavaClassLoader.next();
        if (!(nextCl instanceof JavaClassLoader)) {
            continue;
        }
        JavaClassLoader jcl = (JavaClassLoader) nextCl;
        Iterator itJavaClass = jcl.getDefinedClasses();
        while (itJavaClass.hasNext()) {
            Object next = itJavaClass.next();
            if (!(next instanceof JavaClass)) {
                continue;
            }
            if (next instanceof JavaClass) {
                JavaClass jc = (JavaClass) next;
                long currClassAddress = jc.getID().getAddress();
                if (currClassAddress == address) {
                    return jc;
                }
            }
        }
    }
    return null;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 15 with JavaClassLoader

use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.

the class JavaFieldTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    List<Object> ddrClassLoaders = new ArrayList<Object>();
    List<Object> jextractClassLoaders = new ArrayList<Object>();
    fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
    List<Object> ddrClasses = new ArrayList<Object>();
    List<Object> jextractClasses = new ArrayList<Object>();
    for (int i = 0; i < ddrClassLoaders.size(); i++) {
        JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
        JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
        fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
    }
    for (int i = 0; i < ddrClasses.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
        JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
        fillLists(ddrObjects, ddrClass.getDeclaredFields(), jextractObjects, jextractClass.getDeclaredFields(), JavaClassTest.DECLARED_FIELDS_SORT_ORDER);
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList)

Aggregations

JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)32 JavaClass (com.ibm.dtfj.java.JavaClass)24 Iterator (java.util.Iterator)16 JavaObject (com.ibm.dtfj.java.JavaObject)15 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)14 ArrayList (java.util.ArrayList)7 CorruptData (com.ibm.dtfj.image.CorruptData)6 JavaReference (com.ibm.dtfj.java.JavaReference)3 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)3 List (java.util.List)3 DTFJException (com.ibm.dtfj.image.DTFJException)2 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImagePointer (com.ibm.dtfj.image.ImagePointer)2 JavaMethod (com.ibm.dtfj.java.JavaMethod)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 PortableHeapDumpListener (com.ibm.dtfj.phd.parser.PortableHeapDumpListener)2 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)2 J9DDRDTFJUtils.corruptIterator (com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator)2 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)2 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)2