Search in sources :

Example 1 with JavaClass

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

the class JExtractXMLGenerator method generateClassloaders.

@SuppressWarnings("unchecked")
private void generateClassloaders(JavaRuntime rt) throws Exception {
    for (Iterator loaders = rt.getJavaClassLoaders(); loaders.hasNext(); ) {
        JavaClassLoader loader = (JavaClassLoader) loaders.next();
        xml.append("<classloader id=\"");
        // xml.append(loader.getID());
        xml.append("\" obj=\"0x");
        xml.append(Long.toHexString(loader.getObject().getID().getAddress()));
        xml.append("\">\n");
        for (Iterator classes = loader.getCachedClasses(); classes.hasNext(); ) {
            JavaClass clazz = (JavaClass) classes.next();
            xml.append("<class id=\"0x");
            xml.append(Long.toHexString(clazz.getID().getAddress()));
            xml.append("\" />\n");
        }
        xml.append("</classloader>\n");
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator)

Example 2 with JavaClass

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

the class NodeJavaVM method didFinishParsing.

public void didFinishParsing() {
    Iterator classLoaders = _runtime.getJavaClassLoaders();
    while (classLoaders.hasNext()) {
        Object potentialClassLoader = classLoaders.next();
        if (potentialClassLoader instanceof JavaClassLoader) {
            JavaClassLoader loader = (JavaClassLoader) potentialClassLoader;
            // sets the associated object
            try {
                Object potentialLoaderObject = loader.getObject();
                if (null != potentialLoaderObject && potentialLoaderObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
                    JavaObject loaderObject = (com.ibm.dtfj.java.j9.JavaObject) potentialLoaderObject;
                    loaderObject.setAssociatedClassLoader(loader);
                    _runtime.addSpecialObject(loaderObject);
                    Iterator classes = loader.getDefinedClasses();
                    while (classes.hasNext()) {
                        Object potentialClass = classes.next();
                        if (potentialClass instanceof JavaClass) {
                            JavaClass theClass = (JavaClass) potentialClass;
                            try {
                                Object potentialClassObject = theClass.getObject();
                                if (null != potentialClassObject && potentialClassObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
                                    JavaObject classObject = (com.ibm.dtfj.java.j9.JavaObject) potentialClassObject;
                                    classObject.setAssociatedClass(theClass);
                                    _runtime.addSpecialObject(classObject);
                                }
                            } catch (CorruptDataException e) {
                            // no reason to skip the other classloaders/classes just because an exception is thrown on one class
                            } catch (IllegalArgumentException e) {
                            // CMVC 173262 : JavaClass.getObject() uses JavaHeap.getObjectAtAddress() which can throw this exception
                            }
                        }
                    }
                }
            } catch (CorruptDataException e) {
            // associated object not set
            }
        }
    }
    Iterator monitors = _runtime.getMonitors();
    while (monitors.hasNext()) {
        Object potentialMonitor = monitors.next();
        if (potentialMonitor instanceof JavaMonitor) {
            JavaMonitor monitor = (JavaMonitor) potentialMonitor;
            // sets the associated object
            Object potentialMonitorObject = monitor.getObject();
            if (null != potentialMonitorObject && potentialMonitorObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
                JavaObject monitorObject = (com.ibm.dtfj.java.j9.JavaObject) potentialMonitorObject;
                monitorObject.setAssociatedMonitor(monitor);
                _runtime.addSpecialObject(monitorObject);
            }
        }
    }
    Iterator threads = _runtime.getThreads();
    while (threads.hasNext()) {
        Object potentialThread = threads.next();
        if (potentialThread instanceof JavaThread) {
            JavaThread thread = (JavaThread) potentialThread;
            // sets the associated object
            try {
                Object potentialThreadObject = thread.getObject();
                if (null != potentialThreadObject && potentialThreadObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
                    JavaObject threadObject = (com.ibm.dtfj.java.j9.JavaObject) potentialThreadObject;
                    threadObject.setAssociatedThread(thread);
                    _runtime.addSpecialObject(threadObject);
                }
            } catch (CorruptDataException e) {
            // associated object not set
            }
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.j9.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaMonitor(com.ibm.dtfj.java.JavaMonitor) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.j9.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.j9.JavaObject)

Example 3 with JavaClass

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

the class XJCommand method printReferences.

/**
 * Print the references from the given object. Omit the first reference: this is always a reference to the
 * object's class.
 */
public static void printReferences(JavaObject jo, PrintStream out) {
    Iterator<?> references = jo.getReferences();
    if (references.hasNext()) {
        // reference to the class, ignore this one
        references.next();
    }
    if (!references.hasNext()) {
        out.print("\t    references: <none>\n ");
        out.print("\t     ");
    } else {
        out.print("\t    references:\n ");
        out.print("\t     ");
        while (references.hasNext()) {
            Object potential_reference = references.next();
            if (potential_reference instanceof JavaReference) {
                JavaReference reference = (JavaReference) potential_reference;
                try {
                    Object target = reference.getTarget();
                    if (target instanceof JavaObject) {
                        out.print(" 0x" + Long.toHexString(((JavaObject) target).getID().getAddress()));
                    } else if (target instanceof JavaClass) {
                        out.print(" 0x" + Long.toHexString(((JavaClass) target).getID().getAddress()));
                    }
                } catch (DataUnavailable e) {
                // don't print anything
                } catch (CorruptDataException e) {
                    out.print(Exceptions.getCorruptDataExceptionString());
                }
            }
        }
    }
    out.print("\n\n");
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 4 with JavaClass

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

the class DTFJJavaObject method getAssociatedClass.

private JavaClass getAssociatedClass() {
    // Retrieve the class loader for this class for using introspection to speed up
    // lookup when lots of classes are loaded by lots of class loaders.
    JavaObject targetClassLoaderObject = null;
    try {
        JavaClass javaLangClass = this.getJavaClass();
        Iterator<?> fields = javaLangClass.getDeclaredFields();
        while (fields.hasNext()) {
            Object o = fields.next();
            if (o instanceof JavaField) {
                JavaField field = (JavaField) o;
                if ("classLoader".equals(field.getName())) {
                    targetClassLoaderObject = (JavaObject) field.get(this);
                    break;
                }
            }
        }
    } catch (CorruptDataException e) {
    // This is only an optimisation to save us walking all class loaders. Continue
    } catch (MemoryAccessException e) {
    // This is only an optimisation to save us walking all class loaders. Continue
    }
    return getAssociatedClass(targetClassLoaderObject);
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 5 with JavaClass

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

the class DTFJJavaFieldInstance method _findClassForName.

/**
 * private method to search all classloaders for a given class
 */
private JavaClass _findClassForName(String candidateClass) throws CorruptDataException {
    DTFJJavaRuntime rt = DTFJContext.getRuntime();
    Iterator allLoaders = rt.getJavaClassLoaders();
    JavaClass subclass = null;
    while (allLoaders.hasNext() && (null == subclass)) {
        JavaClassLoader loader = (JavaClassLoader) allLoaders.next();
        Iterator classes = loader.getDefinedClasses();
        while (classes.hasNext() && (null == subclass)) {
            JavaClass oneClass = (JavaClass) classes.next();
            if (oneClass.getName().equals(candidateClass)) {
                subclass = oneClass;
                break;
            }
        }
    }
    return subclass;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) Iterator(java.util.Iterator)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4