Search in sources :

Example 56 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class PHDJavaRuntime method initClassCache.

private void initClassCache() {
    for (PHDJavaClassLoader ldr : loaders.values()) {
        for (Iterator<JavaClass> it = ldr.getDefinedClasses(); it.hasNext(); ) {
            JavaClass cls = it.next();
            ImagePointer ip = cls.getID();
            if (ip != null) {
                classIdCache.put(ip.getAddress(), cls);
            } else {
                // Some classes have pseudo ids
                for (long l = 1; l <= lastDummyClassAddr(); ++l) {
                    if (cls.equals(ldr.findClass(l))) {
                        classIdCache.put(l, cls);
                    }
                }
            }
        }
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 57 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class PHDJavaRuntime method getObjectAtAddress.

public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException, MemoryAccessException, DataUnavailable {
    // Is it a class object?
    final long addr = address.getAddress();
    JavaClass cls = findClass(addr);
    JavaObject jo;
    if (cls != null) {
        jo = cls.getObject();
        if (jo != null && address.equals(jo.getID()))
            return jo;
    }
    if ((jo = extraObjectsCache.get(addr)) != null) {
        return jo;
    } else {
        // See if we already have this object
        for (PHDJavaHeap heap : heaps) {
            try {
                jo = heap.getCachedObjectAtAddress(address, false);
            } catch (IOException e) {
                throw new DataUnavailable("The requested object could not be read from the PHD file");
            }
            if (jo != null)
                return jo;
        }
        // Return a place holder object, may return corrupt data later
        jo = new PHDJavaObject.Builder(heaps.get(0), addr, null, PHDJavaObject.NO_HASHCODE, -1).build();
    }
    return jo;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) IOException(java.io.IOException)

Example 58 with JavaClass

use of com.ibm.dtfj.java.JavaClass 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)

Example 59 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class HeapdumpCommand method dumpClasses.

/**
 * Walks the runtime classes and passes them through the formatter interface
 */
private void dumpClasses(HeapDumpFormatter formatter, JavaRuntime runtime) throws IOException {
    Iterator classLoaderIt = runtime.getJavaClassLoaders();
    int numberOfClasses = 0;
    ITERATING_LOADERS: while (classLoaderIt.hasNext()) {
        Object potential = classLoaderIt.next();
        if (potential instanceof CorruptData) {
            _numberOfErrors++;
            reportError("CorruptData found in classloader list at address: " + ((CorruptData) potential).getAddress(), null);
            continue ITERATING_LOADERS;
        }
        JavaClassLoader thisClassLoader = (JavaClassLoader) potential;
        Iterator classesIt = thisClassLoader.getDefinedClasses();
        ITERATING_CLASSES: while (classesIt.hasNext()) {
            potential = classesIt.next();
            numberOfClasses++;
            try {
                if (potential instanceof CorruptData) {
                    _numberOfErrors++;
                    reportError("CorruptData found in class list for classloader " + Long.toHexString(thisClassLoader.getObject().getID().getAddress()) + " at address: " + ((CorruptData) potential).getAddress(), null);
                    continue ITERATING_CLASSES;
                }
                JavaClass thisJavaClass = (JavaClass) potential;
                JavaClass superClass = thisJavaClass.getSuperclass();
                JavaObject classObject = thisJavaClass.getObject();
                long instanceSize;
                if (thisJavaClass.isArray()) {
                    instanceSize = 0;
                } else {
                    instanceSize = thisJavaClass.getInstanceSize();
                }
                int hashcode = 0;
                if (_is32BitHash) {
                    // JVMs from 2.6 on, optional 32-bit hashcodes, if object was hashed
                    try {
                        hashcode = classObject != null ? (int) classObject.getPersistentHashcode() : 0;
                    } catch (DataUnavailable ex) {
                    // no persistent hashcode for this object, pass hashcode=0 to the heapdump formatter
                    }
                } else {
                    // JVMs prior to 2.6, all objects should have a 16-bit hashcode
                    hashcode = classObject != null ? (int) classObject.getHashcode() : 0;
                }
                formatter.addClass(classObject.getID().getAddress(), thisJavaClass.getName(), superClass != null ? superClass.getID().getAddress() : 0, classObject != null ? (int) classObject.getSize() : 0, instanceSize, hashcode, getClassReferences(thisJavaClass));
            } catch (DTFJException ex) {
                // Handle CorruptDataException and DataUnavailableException the same way
                _numberOfErrors++;
                reportError(null, ex);
                continue ITERATING_CLASSES;
            }
        }
    }
    _numberOfClasses = numberOfClasses;
    if ((pdSkipCount > 0) && _verbose) {
        out.println("Warning : The protection domain information was not available for " + pdSkipCount + " classes");
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) 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) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 60 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class HeapdumpCommand method addReferences.

/**
 * Extracts the instance references from an object
 * @param object Object being walked
 * @param references List<Long> to add references to
 * @param thisClass Class of object
 */
private void addReferences(JavaObject object, List<Long> references) throws CorruptDataException, MemoryAccessException {
    Iterator it = object.getReferences();
    Object ref = null;
    // discard the first reference which is always to the class
    if (it.hasNext()) {
        // test hasNext() to be on the safe side.
        ref = it.next();
    }
    while (it.hasNext()) {
        ref = it.next();
        if (ref instanceof CorruptData) {
            // can sometimes get a nasty surprise in the list - e.g. a J9DDRCorruptData
            _numberOfErrors++;
            reportError("Corrupt data found at address " + ((CorruptData) ref).getAddress() + " getting references from object at address: " + Long.toHexString(object.getID().getAddress()) + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
            continue;
        }
        if (!(ref instanceof JavaReference)) {
            _numberOfErrors++;
            reportError("Object of unexpected type " + ref.getClass() + " found within references from object at address: " + object.getID().getAddress() + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
            continue;
        } else {
            Object target;
            try {
                target = ((JavaReference) ref).getTarget();
            } catch (DataUnavailable e) {
                _numberOfErrors++;
                reportError("DataUnavailable thrown from call to getTarget() on reference: " + ref, null);
                continue;
            }
            // the following ugliness is necessary as JavaObject and JavaClass both support getID() but do not inherit from a common parent
            if (target instanceof JavaObject) {
                references.add(new Long(((JavaObject) target).getID().getAddress()));
            } else if (target instanceof JavaClass) {
                references.add(new Long(((JavaClass) target).getID().getAddress()));
            } else {
                _numberOfErrors++;
                reportError("Object of unexpected type " + target.getClass() + " returned from call to getTarget() on reference " + ref, null);
            }
        }
    }
}
Also used : JavaReference(com.ibm.dtfj.java.JavaReference) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4