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);
}
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;
}
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;
}
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");
}
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);
}
}
Aggregations