use of com.ibm.dtfj.java.JavaClassLoader in project openj9 by eclipse.
the class JavaReferenceTest 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);
List<Object> ddrClasses = new ArrayList<Object>();
List<Object> jextractClasses = new ArrayList<Object>();
for (int i = 0; i < ddrClassLoaders.size(); i++) {
JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
}
for (int i = 0; i < ddrClasses.size(); i++) {
JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
fillLists(ddrObjects, ddrClass.getReferences(), jextractObjects, jextractClass.getReferences(), JavaClassTest.REFERENCES_SORT_ORDER);
}
}
use of com.ibm.dtfj.java.JavaClassLoader 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;
}
use of com.ibm.dtfj.java.JavaClassLoader 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;
}
use of com.ibm.dtfj.java.JavaClassLoader 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;
}
use of com.ibm.dtfj.java.JavaClassLoader 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();
}
Aggregations