Search in sources :

Example 71 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException 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)

Example 72 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class JavaClassComparator method testEquals.

// getClassLoader()
// getComponentType()
// getConstantPoolReferences()
// getDeclaredFields()
// getDeclaredMethods()
// getID()
// getInterfaces()
// getModifiers()
// getName()
// getObject()
// getReferences()
// getSuperclass()
// isArray()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaClass ddrJavaClass = (JavaClass) ddrObject;
    JavaClass jextractJavaClass = (JavaClass) jextractObject;
    JavaObjectComparator javaObjectComparator = new JavaObjectComparator();
    // getClassLoader()
    if ((CLASS_LOADER & members) != 0)
        new JavaClassLoaderComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getClassLoader");
    // isArray()
    if ((IS_ARRAY & members) != 0)
        testJavaEquals(ddrJavaClass, jextractJavaClass, "isArray");
    // getComponentType()
    if ((COMPONENT_TYPE & members) != 0) {
        try {
            if (ddrJavaClass.isArray()) {
                new JavaClassComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getComponentType");
            }
        } catch (CorruptDataException e) {
            fail("Problem comparing JavaClass");
        }
    }
    // getConstantPoolReferences()
    if ((CONSTANT_POOL_REFERENCES & members) != 0)
        javaObjectComparator.testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getConstantPoolReferences", JavaObject.class);
    // getDeclaredFields
    if ((DECLARED_FIELDS & members) != 0)
        new JavaFieldComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getDeclaredFields", JavaField.class);
    // getDeclaredMethods
    if ((DECLARED_METHODS & members) != 0)
        new JavaMethodComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getDeclaredMethods", JavaMethod.class);
    // getID()
    if ((ID & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getID");
    // getInterfaces()
    if ((INTERFACES & members) != 0)
        testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getInterfaces", String.class);
    // getModifiers()
    if ((MODIFIERS & members) != 0)
        testJavaEquals(ddrJavaClass, jextractJavaClass, "getModifiers");
    // getName()
    if ((NAME & members) != 0) {
        testJavaEquals(ddrJavaClass, jextractJavaClass, "getName");
    }
    // getObject()
    if ((OBJECT & members) != 0)
        javaObjectComparator.testJavaEquals(ddrJavaClass, jextractJavaClass, "getObject");
    // getReferneces()
    if ((REFERENCES & members) != 0)
        new JavaReferenceComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getReferneces", JavaReference.class);
    // getSuperclass()
    if ((SUPERCLASS & members) != 0)
        testComparatorEquals(ddrJavaClass, jextractJavaClass, "getSuperclass");
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaReference(com.ibm.dtfj.java.JavaReference) JavaField(com.ibm.dtfj.java.JavaField) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) JavaMethod(com.ibm.dtfj.java.JavaMethod)

Example 73 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class ImageRegisterTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    // Extract registers from all threads
    List<Object> ddrThreads = new LinkedList<Object>();
    List<Object> jextractThreads = new LinkedList<Object>();
    Comparator<Object> c = new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            if (o1 instanceof ImageThread && o2 instanceof ImageThread) {
                ImageThread t1 = (ImageThread) o1;
                ImageThread t2 = (ImageThread) o2;
                try {
                    return t1.getID().compareTo(t2.getID());
                } catch (CorruptDataException e) {
                    return 0;
                }
            } else {
                return 0;
            }
        }
    };
    fillLists(ddrThreads, ddrProcess.getThreads(), jextractThreads, jextractProcess.getThreads(), c);
    assertEquals("Different numbers of threads", jextractThreads.size(), ddrThreads.size());
    Collections.sort(ddrThreads, c);
    Collections.sort(jextractThreads, c);
    for (Object o : ddrThreads) {
        if (o instanceof ImageThread) {
            ImageThread t = (ImageThread) o;
            Iterator<?> it = t.getRegisters();
            slurpIterator(it, ddrObjects);
        }
    }
    for (Object o : jextractThreads) {
        if (o instanceof ImageThread) {
            ImageThread t = (ImageThread) o;
            Iterator<?> it = t.getRegisters();
            slurpIterator(it, jextractObjects);
        }
    }
}
Also used : ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) ImageRegisterComparator(com.ibm.j9ddr.view.dtfj.comparators.ImageRegisterComparator) Comparator(java.util.Comparator)

Example 74 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class ImagePointerTest 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);
    for (int i = 0; i < ddrClassLoaders.size(); i++) {
        JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
        JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
        try {
            ddrObjects.add(ddrClassLoader.getObject().getID());
            jextractObjects.add(jextractClassLoader.getObject().getID());
        } catch (CorruptDataException e) {
            fail("Problem initializing test");
        }
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 75 with CorruptDataException

use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.

the class JavaClassTest method anyClassIsArray.

@Test
public void anyClassIsArray() {
    boolean foundArray = false;
    for (int i = 0; i < ddrTestObjects.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrTestObjects.get(i);
        try {
            if (ddrClass.isArray()) {
                foundArray = true;
                break;
            }
        } catch (CorruptDataException e) {
        // Do nothing ... not testing this aspect
        }
    }
    assertTrue("No class under test was an array", foundArray);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Test(org.junit.Test)

Aggregations

CorruptDataException (com.ibm.dtfj.image.CorruptDataException)124 JavaObject (com.ibm.dtfj.java.JavaObject)55 Iterator (java.util.Iterator)49 JavaClass (com.ibm.dtfj.java.JavaClass)41 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)39 CorruptData (com.ibm.dtfj.image.CorruptData)26 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)25 ImagePointer (com.ibm.dtfj.image.ImagePointer)19 CorruptData (com.ibm.dtfj.image.j9.CorruptData)17 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)14 ImageSection (com.ibm.dtfj.image.ImageSection)12 ImageThread (com.ibm.dtfj.image.ImageThread)12 JavaThread (com.ibm.dtfj.java.JavaThread)12 ArrayList (java.util.ArrayList)11 ImageProcess (com.ibm.dtfj.image.ImageProcess)9 JavaField (com.ibm.dtfj.java.JavaField)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 LinkedList (java.util.LinkedList)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)7 JavaMethod (com.ibm.dtfj.java.JavaMethod)7