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