use of com.ibm.dtfj.java.JavaClass 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.JavaClass in project openj9 by eclipse.
the class JavaClassLoader method getDefinedClasses.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClassLoader#getDefinedClasses()
*/
public Iterator getDefinedClasses() {
if (null == _defined) {
// Loop through the list of all classes building a list of this loader's defined classes.
// A defined class is a class whose class loader is this loader
Iterator cached = _javaVM.getClasses();
long thisID = _id.getAddress();
_defined = new ArrayList();
while (cached.hasNext()) {
Object next = cached.next();
// corrupt entries by looking at the cached classes via getCachedClasses()
if (next instanceof CorruptData) {
continue;
}
// Extract the current class
JavaClass currentClass = (JavaClass) next;
try {
// Extract the current class's class loader
JavaClassLoader currentClassLoader = (JavaClassLoader) currentClass.getClassLoader();
// old versions of jextract
if ((currentClassLoader != null) && (currentClassLoader._id.getAddress() == thisID)) {
_defined.add(currentClass);
}
} catch (CorruptDataException e) {
// Ignore this one
}
}
}
return _defined.iterator();
}
use of com.ibm.dtfj.java.JavaClass 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.JavaClass 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.JavaClass 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