Search in sources :

Example 1 with LongListReferenceIterator

use of com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator in project openj9 by eclipse.

the class HeapdumpCommand method getClassReferences.

/* Reference code reimplemented (rather than using the DTFJ getReferences() API)
	 * because we are trying to match the behaviour of the runtime heapdump rather than
	 * the GC spec. The set of references we're trying to create is different.
	 */
/**
 * Gets the references for the supplied class
 *
 * @param thisJavaClass Class being examined
 */
private ReferenceIterator getClassReferences(JavaClass thisJavaClass) {
    List references = new LinkedList();
    try {
        // Class object instance references
        addReferences(thisJavaClass.getObject(), references);
        // Statics
        addStaticReferences(thisJavaClass, references);
        addProtectionDomainReference(thisJavaClass, references);
        // Constant pool class references
        Iterator constantPoolIt = thisJavaClass.getConstantPoolReferences();
        while (constantPoolIt.hasNext()) {
            Object cpObject = constantPoolIt.next();
            if (cpObject instanceof JavaClass) {
                // Found a class reference, add it to the list
                JavaClass cpJavaClass = (JavaClass) cpObject;
                references.add(new Long(cpJavaClass.getObject().getID().getAddress()));
            }
        }
        // Superclass references
        JavaClass superClass = thisJavaClass.getSuperclass();
        while (null != superClass) {
            references.add(new Long(superClass.getObject().getID().getAddress()));
            superClass = superClass.getSuperclass();
        }
        // Classloader
        JavaClassLoader loader = thisJavaClass.getClassLoader();
        if (loader != null) {
            JavaObject loaderObject = loader.getObject();
            if (loaderObject != null) {
                references.add(new Long(loaderObject.getID().getAddress()));
            } else {
                reportError("Null loader object returned for class: " + thisJavaClass.getName() + "(" + thisJavaClass.getID() + ")", null);
                _numberOfErrors++;
            }
        } else {
            reportError("Null classloader returned for class: " + thisJavaClass.getName() + "(" + thisJavaClass.getID() + ")", null);
            _numberOfErrors++;
        }
    } catch (DTFJException ex) {
        reportError(null, ex);
        _numberOfErrors++;
    }
    return new LongListReferenceIterator(references);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) DTFJException(com.ibm.dtfj.image.DTFJException) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) LinkedList(java.util.LinkedList) List(java.util.List) JavaObject(com.ibm.dtfj.java.JavaObject) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) LinkedList(java.util.LinkedList)

Aggregations

DTFJException (com.ibm.dtfj.image.DTFJException)1 JavaClass (com.ibm.dtfj.java.JavaClass)1 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)1 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1