Search in sources :

Example 16 with CorruptDataException

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

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

the class DTFJJavaField method equals.

public boolean equals(Object obj) {
    boolean isEqual = false;
    if (obj instanceof JavaField) {
        JavaField field = (JavaField) obj;
        boolean hasSameName;
        try {
            hasSameName = name.equals(field.getName());
        } catch (CorruptDataException cde) {
            hasSameName = false;
        }
        try {
            isEqual = hasSameName && (getClass().equals(field.getClass())) && clazz.equals(field.getDeclaringClass());
        } catch (Throwable t) {
            J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
        }
    }
    return isEqual;
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) IDTFJJavaField(com.ibm.j9ddr.view.dtfj.java.IDTFJJavaField) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 18 with CorruptDataException

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

the class DTFJJavaThread method equals.

public boolean equals(Object object) {
    // note that we can't get image threads on all platforms and in all situations but we still need to return equals correctly
    ImageThread imageThread = null;
    try {
        imageThread = getImageThread();
    } catch (DataUnavailable e) {
    // Do nothing
    } catch (CorruptDataException e) {
    // Do nothing
    }
    boolean isEqual = (null == imageThread) ? (this == object) : false;
    // By definition objects from different images can not be equal
    if ((null != imageThread) && (object instanceof DTFJJavaThread)) {
        DTFJJavaThread local = (DTFJJavaThread) object;
        try {
            isEqual = imageThread.getID().equals(local.getImageThread().getID());
        } catch (CorruptDataException e) {
        // Do nothing
        } catch (DataUnavailable e) {
        // Do nothing
        }
    }
    return isEqual;
}
Also used : DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageThread(com.ibm.dtfj.image.ImageThread) J9DDRStubImageThread(com.ibm.j9ddr.view.dtfj.image.J9DDRStubImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 19 with CorruptDataException

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

the class JavaObjectComparator method testEquals.

// getArraySize()
// getHeap()
// getID()
// getJavaClass()
// getReferences()
// getSections()
// getSize()
// isArray()
// what about
// getHashcode()
// getPersistentHashcode()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaObject ddrJavaObject = (JavaObject) ddrObject;
    JavaObject jextractJavaObject = (JavaObject) jextractObject;
    // isArray()
    if ((IS_ARRAY & members) != 0)
        testJavaEquals(ddrJavaObject, jextractJavaObject, "isArray");
    // getArraySize()
    if ((ARRAY_SIZE & members) != 0) {
        try {
            if (ddrJavaObject.isArray()) {
                testJavaEquals(ddrJavaObject, jextractJavaObject, "getArraySize");
            }
        } catch (CorruptDataException e) {
            fail(String.format("Problem comparing JavaObject %s", ddrJavaObject));
        }
    }
    // getID()
    if ((ID & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrJavaObject, jextractJavaObject, "getID");
    // getJavaClass()
    if ((JAVA_CLASS & members) != 0)
        new JavaClassComparator().testComparatorEquals(ddrJavaObject, jextractJavaObject, "getJavaClass");
    // getReferences()
    if ((REFERENCES & members) != 0)
        new JavaReferenceComparator().testComparatorIteratorEquals(ddrJavaObject, jextractJavaObject, "getReferences", JavaReference.class);
    // getSections()
    if ((SECTIONS & members) != 0)
        new ImageSectionComparator().testComparatorIteratorEquals(ddrJavaObject, jextractJavaObject, "getSections", ImageSection.class);
    // getHeap()
    if ((HEAP & members) != 0)
        new JavaHeapComparator().testComparatorEquals(ddrJavaObject, jextractJavaObject, "getHeap");
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 20 with CorruptDataException

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

the class DTFJComparator method invokeMethod.

@SuppressWarnings("unchecked")
private InvokeResult invokeMethod(Object ddrObject, Object jextractObject, String methodName, Class[] paramTypes, Object[] args) {
    if (assertEqualsIfBothObjectsCorrupt(jextractObject, ddrObject)) {
        return new InvokeResult(null, null, false);
    }
    boolean ddrDataUnavailable = false;
    boolean jextractDataUnavailable = false;
    boolean ddrCorruptData = false;
    boolean jextractCorruptData = false;
    boolean ddrUnsupportedOperation = false;
    @SuppressWarnings("unused") boolean jextractUnsupportedOperation = false;
    Object ddrResult = false;
    Object jextractResult = false;
    Method method;
    Throwable ddrException = null;
    Throwable jextractException = null;
    try {
        method = ddrObject.getClass().getMethod(methodName, paramTypes);
        method.setAccessible(true);
        ddrResult = method.invoke(ddrObject, args);
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", ddrObject.getClass().getName(), methodName));
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", ddrObject.getClass().getName(), methodName));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", ddrObject.getClass().getName(), methodName));
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", ddrObject.getClass().getName(), methodName));
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof DataUnavailable) {
            // e.getCause().printStackTrace();
            ddrException = e.getCause();
            ddrDataUnavailable = true;
        } else if (e.getCause() instanceof CorruptDataException) {
            // e.getCause().printStackTrace();
            ddrException = e.getCause();
            ddrCorruptData = true;
        } else {
            fail(String.format("Unexpected exception %s from method %s.%s()", e.getCause(), ddrObject.getClass().getName(), methodName));
        }
    }
    try {
        method = jextractObject.getClass().getMethod(methodName, paramTypes);
        method.setAccessible(true);
        jextractResult = method.invoke(jextractObject, args);
    } catch (SecurityException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", jextractObject.getClass().getName(), methodName));
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", jextractObject.getClass().getName(), methodName));
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", jextractObject.getClass().getName(), methodName));
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        fail(String.format("Could not find method %s.%s()", jextractObject.getClass().getName(), methodName));
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof DataUnavailable) {
            jextractException = e.getCause();
            jextractDataUnavailable = true;
        } else if (e.getCause() instanceof CorruptDataException) {
            jextractException = e.getCause();
            jextractCorruptData = true;
        } else {
            fail(String.format("Unexpected exception %s from method %s.%s()", e.getCause(), ddrObject.getClass().getName(), methodName));
        }
    }
    if (ddrDataUnavailable && !jextractDataUnavailable) {
        if (ddrException != null) {
            ddrException.printStackTrace();
        }
        if (jextractException != null) {
            jextractException.printStackTrace();
        }
        fail(String.format("%s.%s returned DataUnavailable. JExtract did not.", ddrObject.getClass().getSimpleName(), methodName));
    }
    if (jextractCorruptData && !ddrCorruptData) {
        // in this case DDR found data and jextract threw a corrupt data exception, so mark it as do not test
        return new InvokeResult(ddrResult, jextractResult, false);
    } else {
        assertEquals(String.format("%s.%s() returned CorruptData for %s", ddrObject.getClass().getSimpleName(), methodName, ddrCorruptData ? "DDR" : "JEXTRACT"), jextractCorruptData, ddrCorruptData);
        return new InvokeResult(ddrResult, jextractResult, !jextractDataUnavailable && !ddrDataUnavailable && !ddrCorruptData && !ddrUnsupportedOperation);
    }
}
Also used : Method(java.lang.reflect.Method) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataUnavailable(com.ibm.dtfj.image.DataUnavailable)

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