Search in sources :

Example 16 with JavaClassLoader

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

the class JavaReferenceTest 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.getReferences(), jextractObjects, jextractClass.getReferences(), JavaClassTest.REFERENCES_SORT_ORDER);
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList)

Example 17 with JavaClassLoader

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

the class JavaRuntime method getComponentTypeForClass.

JavaClass getComponentTypeForClass(JavaClass theClass) throws CorruptDataException {
    // CMVC 161798 add check to see if array class set is valid before populating the map
    if ((_arrayClasses != null) && _arrayClassesMap.isEmpty()) {
        // 1st invocation. Build the map
        Iterator i = _arrayClasses.iterator();
        while (i.hasNext()) {
            // CMVC 165884 add check for null classloader
            JavaArrayClass currentClass = (JavaArrayClass) i.next();
            String className = currentClass.getName();
            String classLoaderID = "";
            JavaClassLoader currentClassLoader = currentClass.getClassLoader();
            if (currentClassLoader != null) {
                classLoaderID = currentClassLoader.toString();
            }
            _arrayClassesMap.put(className + classLoaderID, currentClass);
        }
        // don't need _arrayClasses anymore
        _arrayClasses.clear();
        _arrayClasses = null;
    }
    JavaClass componentType = null;
    String componentClassName = theClass.getName().substring(1);
    // CMVC 165884 add check for null classloader
    String classLoaderID = "";
    JavaClassLoader theClassLoader = theClass.getClassLoader();
    if (theClassLoader != null) {
        classLoaderID = theClassLoader.toString();
    }
    Object obj = _arrayClassesMap.get(componentClassName + classLoaderID);
    if (obj instanceof JavaClass) {
        componentType = (JavaClass) obj;
    }
    return componentType;
}
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 18 with JavaClassLoader

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

the class JavaArrayClass method getClassLoader.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClass#getClassLoader()
	 */
public JavaClassLoader getClassLoader() throws CorruptDataException {
    JavaClassLoader cl = super.getClassLoader();
    JavaClass leafClass = getLeafClass();
    if (null == cl && null != leafClass) {
        cl = getLeafClass().getClassLoader();
    }
    return cl;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 19 with JavaClassLoader

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

the class DTFJJavaObject method getAssociatedClass.

private JavaClass getAssociatedClass(JavaObject targetClassLoaderObject) {
    Iterator<?> classloaderIt = DTFJContext.getRuntime().getJavaClassLoaders();
    while (classloaderIt.hasNext()) {
        Object clObj = classloaderIt.next();
        if (clObj instanceof JavaClassLoader) {
            JavaClassLoader loader = (JavaClassLoader) clObj;
            try {
                if (targetClassLoaderObject != null && !loader.getObject().equals(targetClassLoaderObject)) {
                    continue;
                }
            } catch (CorruptDataException e1) {
            // This is an optimisation so if it fails, continue.
            }
            Iterator<?> classesIt = loader.getDefinedClasses();
            while (classesIt.hasNext()) {
                Object classObj = classesIt.next();
                if (classObj instanceof JavaClass) {
                    JavaClass clazz = (JavaClass) classObj;
                    try {
                        if (clazz.getObject().equals(this)) {
                            return clazz;
                        }
                    } catch (CorruptDataException e) {
                    // Deliberately do nothing. If this is the class we're interesting in, we'll
                    // insert a CorruptData object later when it isn't found. If it's not the class
                    // we want, we don't need to worry
                    }
                }
            }
        }
    }
    return null;
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) 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)

Example 20 with JavaClassLoader

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

the class DTFJJavaObject method getReferences.

@SuppressWarnings("rawtypes")
public Iterator getReferences() {
    boolean isClass = false;
    boolean isClassLoader = false;
    boolean isWeakReference = false;
    boolean isSoftReference = false;
    boolean isPhantomReference = false;
    if (null == references) {
        references = new LinkedList<Object>();
        try {
            // find this object's class
            JavaClass jClass = getJavaClass();
            // add a reference to the object's class
            if (null != jClass) {
                JavaReference ref = new DTFJJavaReference(this, jClass, "Class", JavaReference.REFERENCE_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                references.add(ref);
            }
            if (isArray()) {
                if (isObjectArray()) {
                    addObjectArrayReferences();
                }
            } else {
                isClass = (jClass != null) && jClass.getName().equals("java/lang/Class");
                List<JavaClass> superClasses = new LinkedList<JavaClass>();
                // Do superclass walk
                while (jClass != null) {
                    String className = jClass.getName();
                    isClassLoader |= className.equals("java/lang/ClassLoader");
                    isWeakReference |= className.equals("java/lang/ref/WeakReference");
                    isSoftReference |= className.equals("java/lang/ref/SoftReference");
                    isPhantomReference |= className.equals("java/lang/ref/PhantomReference");
                    superClasses.add(jClass);
                    jClass = jClass.getSuperclass();
                }
                int reachability = isWeakReference ? JavaReference.REACHABILITY_WEAK : isSoftReference ? JavaReference.REACHABILITY_SOFT : isPhantomReference ? JavaReference.REACHABILITY_PHANTOM : JavaReference.REACHABILITY_STRONG;
                for (JavaClass clazz : superClasses) {
                    addFieldReferences(clazz, reachability);
                }
            }
        } catch (CorruptDataException e) {
            // Corrupt data, so add it to the container.
            references.add(e.getCorruptData());
        } catch (Throwable t) {
            CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
            references.add(cd);
        }
        // Now add association-specific references
        if (isClassLoader) {
            try {
                JavaClassLoader associatedClassLoader = getAssociatedClassLoader();
                if (associatedClassLoader != null) {
                    for (Iterator classes = associatedClassLoader.getDefinedClasses(); classes.hasNext(); ) {
                        Object potentialClass = classes.next();
                        if (potentialClass instanceof JavaClass) {
                            JavaClass currentClass = (JavaClass) potentialClass;
                            JavaReference ref = new DTFJJavaReference(this, currentClass, "Loaded class", JavaReference.REFERENCE_LOADED_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                            references.add(ref);
                        }
                    }
                } else {
                    references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Couldn't find associated JavaClassLoader for classloader object " + this));
                }
            } catch (Throwable t) {
                CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
                references.add(cd);
            }
        }
        if (isClass) {
            try {
                JavaClass associatedClass = getAssociatedClass();
                if (associatedClass != null) {
                    JavaReference ref = new DTFJJavaReference(this, associatedClass, "Associated class", JavaReference.REFERENCE_ASSOCIATED_CLASS, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                    references.add(ref);
                } else {
                    // No associated class found. For anonymous classes this is expected, the class is not defined in a classloader.
                    J9ClassPointer j9Class = ConstantPoolHelpers.J9VM_J9CLASS_FROM_HEAPCLASS(object);
                    if (!J9ClassHelper.isAnonymousClass(j9Class)) {
                        // Not an anonymous class, so something is wrong/damaged, add a corrupt data object to the references list
                        references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Couldn't find associated JavaClass for Class object " + this));
                    }
                }
            } catch (Throwable t) {
                CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
                references.add(cd);
            }
        }
    }
    return references.iterator();
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) JavaReference(com.ibm.dtfj.java.JavaReference) JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) J9DDRDTFJUtils.corruptIterator(com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)

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