Search in sources :

Example 1 with DTFJException

use of com.ibm.dtfj.image.DTFJException in project openj9 by eclipse.

the class InfoThreadCommand method getJavaThreads.

private Map getJavaThreads(String id) {
    Map threads = new HashMap();
    ManagedRuntime mr = ctx.getRuntime();
    if (mr instanceof JavaRuntime) {
        JavaRuntime jr = (JavaRuntime) mr;
        Iterator itThread = jr.getThreads();
        while (itThread.hasNext()) {
            Object next = itThread.next();
            // skip any corrupt threads
            if (next instanceof CorruptData)
                continue;
            JavaThread jt = (JavaThread) next;
            // Obtain the native thread ID for this thread, and for zOS also obtain the TCB
            String currentTID = null;
            String currentTCB = null;
            try {
                ImageThread it = jt.getImageThread();
                currentTID = it.getID();
                if (_is_zOS) {
                    currentTCB = it.getProperties().getProperty("TCB");
                }
            } catch (DTFJException e) {
            // Continue with what we have obtained so far
            }
            if (null == id) {
                // save all orphaned java threads in a list within the hashmap
                if (null == currentTID) {
                    if (threads.containsKey(null)) {
                        ArrayList ta = (ArrayList) threads.get(null);
                        ta.add(new ThreadData(jt, jr));
                    } else {
                        ArrayList ta = new ArrayList(1);
                        ta.add(new ThreadData(jt, jr));
                        threads.put(null, ta);
                    }
                } else {
                    threads.put(currentTID, new ThreadData(jt, jr));
                }
            } else if (id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
                // We just want the specific Java thread that matches the native thread ID or zOS TCB
                threads.put(currentTID, new ThreadData(jt, jr));
            }
        }
    }
    return threads;
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) DTFJException(com.ibm.dtfj.image.DTFJException) ArrayList(java.util.ArrayList) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 2 with DTFJException

use of com.ibm.dtfj.image.DTFJException 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 3 with DTFJException

use of com.ibm.dtfj.image.DTFJException 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)

Aggregations

DTFJException (com.ibm.dtfj.image.DTFJException)3 JavaObject (com.ibm.dtfj.java.JavaObject)3 Iterator (java.util.Iterator)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)2 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)2 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)2 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 ImageThread (com.ibm.dtfj.image.ImageThread)1 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)1 JavaThread (com.ibm.dtfj.java.JavaThread)1 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)1 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)1 ThreadData (com.ibm.jvm.dtfjview.commands.helpers.ThreadData)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1