Search in sources :

Example 31 with JavaClass

use of com.ibm.dtfj.java.JavaClass 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 32 with JavaClass

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

the class JavaClassLoader method getDefinedClasses.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClassLoader#getDefinedClasses()
	 */
public Iterator getDefinedClasses() {
    if (null == _defined) {
        // Loop through the list of all classes building a list of this loader's defined classes.
        // A defined class is a class whose class loader is this loader
        Iterator cached = _javaVM.getClasses();
        long thisID = _id.getAddress();
        _defined = new ArrayList();
        while (cached.hasNext()) {
            Object next = cached.next();
            // corrupt entries by looking at the cached classes via getCachedClasses()
            if (next instanceof CorruptData) {
                continue;
            }
            // Extract the current class
            JavaClass currentClass = (JavaClass) next;
            try {
                // Extract the current class's class loader
                JavaClassLoader currentClassLoader = (JavaClassLoader) currentClass.getClassLoader();
                // old versions of jextract
                if ((currentClassLoader != null) && (currentClassLoader._id.getAddress() == thisID)) {
                    _defined.add(currentClass);
                }
            } catch (CorruptDataException e) {
            // Ignore this one
            }
        }
    }
    return _defined.iterator();
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 33 with JavaClass

use of com.ibm.dtfj.java.JavaClass 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 34 with JavaClass

use of com.ibm.dtfj.java.JavaClass 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 35 with JavaClass

use of com.ibm.dtfj.java.JavaClass 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

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