Search in sources :

Example 1 with ThreadData

use of com.ibm.jvm.dtfjview.commands.helpers.ThreadData 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 ThreadData

use of com.ibm.jvm.dtfjview.commands.helpers.ThreadData in project openj9 by eclipse.

the class InfoThreadCommand method printThreadInfo.

private boolean printThreadInfo(String id, Map threads) {
    Iterator itThread;
    ImageThread it;
    boolean found = false;
    itThread = ctx.getProcess().getThreads();
    while (itThread.hasNext()) {
        Object next = itThread.next();
        if (next instanceof CorruptData) {
            out.print("\n  <corrupt data>");
            continue;
        }
        it = (ImageThread) next;
        // Obtain the native thread ID for this thread, and for zOS also obtain the TCB
        String currentTID = null;
        String currentTCB = null;
        try {
            currentTID = it.getID();
            if (_is_zOS) {
                currentTCB = it.getProperties().getProperty("TCB");
            }
        } catch (CorruptDataException e) {
        // Continue with what we have obtained so far
        }
        // the requested native thread ID or zOS TCB, then go ahead and print out this thread.
        if (null == id || id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
            out.print("  thread id: ");
            out.print(currentTID);
            out.print("\n");
            printRegisters(it);
            out.print("   native stack sections:");
            out.print("\n");
            Iterator itStackSection = it.getStackSections();
            while (itStackSection.hasNext()) {
                Object nextStackSection = itStackSection.next();
                if (nextStackSection instanceof CorruptData) {
                    out.print("    " + Exceptions.getCorruptDataExceptionString() + "\n");
                    continue;
                }
                ImageSection is = (ImageSection) nextStackSection;
                printStackSection(is);
            }
            printStackFrameInfo(it);
            out.print("   properties:");
            out.print("\n");
            printProperties(it);
            out.print("   associated Java thread: ");
            ThreadData td = (ThreadData) threads.remove(currentTID);
            if (null != td) {
                out.print("\n");
                printJavaThreadInfo(td.getThread(), true);
            } else {
                out.print("<no associated Java thread>\n");
            }
            out.print("\n");
            found = true;
        }
    }
    return found;
}
Also used : Iterator(java.util.Iterator) ImageSection(com.ibm.dtfj.image.ImageSection) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 3 with ThreadData

use of com.ibm.jvm.dtfjview.commands.helpers.ThreadData in project openj9 by eclipse.

the class InfoThreadCommand method printAddressSpaceInfo.

private void printAddressSpaceInfo(String id, Map threads) {
    Iterator itAddressSpace;
    ImageAddressSpace ias;
    int asnum = 0;
    if (id == null) {
        // omit header line if we are only printing one thread
        out.print("native threads for address space\n");
    }
    printProcessInfo(id, threads);
    if (!threads.isEmpty()) {
        out.print("\nJava threads not associated with known native threads:\n\n");
        // retrieve any orphaned Java threads from the hashmap
        ArrayList ta = (ArrayList) threads.remove(null);
        if (ta != null) {
            for (int i = 0; i < ta.size(); i++) {
                ThreadData td = (ThreadData) ta.get(i);
                printJavaThreadInfo(td.getThread(), false);
            }
        }
        // If that still hasn't emptied the list we've managed to find id's for threads
        if (!threads.isEmpty()) {
            Iterator remainingThreads = threads.values().iterator();
            while (remainingThreads.hasNext()) {
                ThreadData td = (ThreadData) remainingThreads.next();
                if (td == null) {
                    continue;
                }
                printJavaThreadInfo(td.getThread(), false);
            }
        }
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Aggregations

ThreadData (com.ibm.jvm.dtfjview.commands.helpers.ThreadData)3 Iterator (java.util.Iterator)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaObject (com.ibm.dtfj.java.JavaObject)2 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)2 ArrayList (java.util.ArrayList)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 DTFJException (com.ibm.dtfj.image.DTFJException)1 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)1 ImageSection (com.ibm.dtfj.image.ImageSection)1 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)1 JavaThread (com.ibm.dtfj.java.JavaThread)1 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1