Search in sources :

Example 6 with JavaThread

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

the class PHDJavaRuntime method initThreads.

private void initThreads() {
    if (metaJavaRuntime != null) {
        for (Iterator it = metaJavaRuntime.getThreads(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof CorruptData) {
                JavaThread thr = new PHDCorruptJavaThread(space, (CorruptData) next);
                threads.put(thr, thr);
            } else {
                getThread((JavaThread) next);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 7 with JavaThread

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

the class InfoThreadCommand method printThreadBlocker.

private void printThreadBlocker(JavaThread jt) {
    try {
        if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
            out.print("      parked on: ");
            // java.util.concurrent locks
            if (jt.getBlockingObject() == null) {
                out.print("<unknown>");
            } else {
                JavaObject jo = jt.getBlockingObject();
                String lockID = Long.toHexString(jo.getID().getAddress());
                out.print(jo.getJavaClass().getName() + "@0x" + lockID);
                String ownerThreadName = "<unknown>";
                String ownerThreadID = "<null>";
                out.print(" owner name: ");
                JavaThread lockOwnerThread = Utils.getParkBlockerOwner(jo, ctx.getRuntime());
                if (lockOwnerThread != null) {
                    ownerThreadName = lockOwnerThread.getName();
                    if (lockOwnerThread.getImageThread() != null) {
                        ownerThreadID = lockOwnerThread.getImageThread().getID();
                    }
                } else {
                    // If the owning thread has ended we won't find the JavaThread
                    // We can still get the owning thread name from the java.lang.Thread object itself.
                    // We won't get a thread id.
                    JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(jo, ctx.getRuntime());
                    if (lockOwnerObj != null) {
                        ownerThreadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                    }
                }
                out.print("\"" + ownerThreadName + "\"");
                out.print(" owner id: " + ownerThreadID);
            }
            out.print("\n");
        } else if ((jt.getState() & JavaThread.STATE_IN_OBJECT_WAIT) != 0) {
            out.print("      waiting to be notified on: ");
        } else if ((jt.getState() & JavaThread.STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
            out.print("      waiting to enter: ");
        }
        if ((jt.getState() & JavaThread.STATE_IN_OBJECT_WAIT) != 0 || (jt.getState() & JavaThread.STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
            // java monitors
            MonitorState ms = (MonitorState) monitors.get(jt);
            if (ms == null) {
                out.println("<monitor information not available>");
            } else {
                JavaObject jo = ms.getMonitor().getObject();
                if (null == jo) {
                    // working with a raw monitor
                    String name = ms.getMonitor().getName();
                    if (name.equals("")) {
                        name = "<unnamed>";
                    }
                    out.print("\"" + name + "\"");
                    out.print(" with ID ");
                    out.print(Utils.toHex(ms.getMonitor().getID().getAddress()));
                } else {
                    // working with a Java monitor
                    String lockID = Long.toHexString(jo.getID().getAddress());
                    out.print(jo.getJavaClass().getName() + "@0x" + lockID);
                }
                out.print(" owner name: ");
                if (ms.getMonitor().getOwner() != null) {
                    out.print("\"" + ms.getMonitor().getOwner().getName() + "\"");
                    if (ms.getMonitor().getOwner().getImageThread() != null) {
                        out.print(" owner id: " + ms.getMonitor().getOwner().getImageThread().getID());
                    }
                } else {
                    out.print("<unowned>");
                }
                out.print("\n");
            }
        }
    } catch (CorruptDataException cde) {
        out.print(Exceptions.getCorruptDataExceptionString());
        logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
    } catch (DataUnavailable e) {
        out.print(Exceptions.getDataUnavailableString());
        logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
    } catch (MemoryAccessException e) {
        out.print(Exceptions.getMemoryAccessExceptionString());
        logger.log(Level.FINEST, Exceptions.getMemoryAccessExceptionString(), e);
    }
}
Also used : MonitorState(com.ibm.jvm.dtfjview.commands.helpers.MonitorState) JavaObject(com.ibm.dtfj.java.JavaObject) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 8 with JavaThread

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

the class Utils method getParkBlockerOwner.

/* Find the JavaThread that owns a blocking object by finding the java/lang/Thread
	 * JavaObject of the owner and then looking through the list of JavaThreads to
	 * see who that belongs to. 
	 */
public static JavaThread getParkBlockerOwner(JavaObject blocker, JavaRuntime r) throws CorruptDataException, MemoryAccessException {
    JavaObject ownerObj = getParkBlockerOwnerObject(blocker, r);
    if (ownerObj == null) {
        return null;
    }
    Iterator threads = r.getThreads();
    while (threads.hasNext()) {
        Object lObj = threads.next();
        if (lObj instanceof JavaThread) {
            JavaThread thread = (JavaThread) lObj;
            if (ownerObj.equals(thread.getObject())) {
                return thread;
            }
        }
    }
    return null;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 9 with JavaThread

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

the class InfoLockCommand method showWaiters.

private void showWaiters(JavaMonitor jMonitor) throws CorruptDataException {
    // List any threads waiting on enter or notify for this monitor
    Iterator itEnterWaiter = jMonitor.getEnterWaiters();
    while (itEnterWaiter.hasNext()) {
        Object t = itEnterWaiter.next();
        if (!(t instanceof JavaThread)) {
            continue;
        }
        JavaThread jThread = (JavaThread) t;
        try {
            out.println("\twaiting thread id: " + jThread.getImageThread().getID() + " name: " + jThread.getName());
        } catch (DataUnavailable dae) {
            out.println("\twaiting thread id: <unknown>");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), dae);
        }
    }
    Iterator itNotifyWaiter = jMonitor.getNotifyWaiters();
    while (itNotifyWaiter.hasNext()) {
        Object t = itNotifyWaiter.next();
        if (!(t instanceof JavaThread)) {
            continue;
        }
        JavaThread jThread = (JavaThread) t;
        try {
            out.println("\twaiting thread id: " + jThread.getImageThread().getID() + " name: " + jThread.getName());
        } catch (DataUnavailable dae) {
            out.println("\twaiting thread id: <unknown>");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), dae);
        }
    }
}
Also used : Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject)

Example 10 with JavaThread

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

the class InfoLockCommand method showJavaUtilConcurrentLocks.

private void showJavaUtilConcurrentLocks() {
    // A map of lock objects and their waiting threads.
    Map locksToThreads = new HashMap();
    JavaRuntime jr = ctx.getRuntime();
    Iterator itThread = jr.getThreads();
    while (itThread.hasNext()) {
        try {
            Object o = itThread.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread jt = (JavaThread) o;
            if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
                JavaObject lock = jt.getBlockingObject();
                if (lock != null) {
                    List parkedList = (List) locksToThreads.get(lock);
                    if (parkedList == null) {
                        parkedList = new LinkedList();
                        locksToThreads.put(lock, parkedList);
                    }
                    parkedList.add(jt);
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
    out.println("\njava.util.concurrent locks in use...");
    if (locksToThreads.size() == 0) {
        out.println("\t...None.");
        out.println();
    }
    for (Object e : locksToThreads.entrySet()) {
        try {
            Map.Entry entry = (Map.Entry) e;
            JavaObject lock = (JavaObject) entry.getKey();
            List threads = (List) entry.getValue();
            String threadName = "<unowned>";
            JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
            if (lockOwnerThread != null) {
                threadName = lockOwnerThread.getName();
            } else {
                // If the owning thread has ended we won't find the JavaThread
                // We can still get the owning thread name from the java.lang.Thread object itself.
                JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
                if (lockOwnerObj != null) {
                    threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                } else {
                    threadName = "<unknown>";
                }
            }
            if (threads != null && threads.size() > 0) {
                String lockID = Long.toHexString(lock.getID().getAddress());
                ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
                out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
                for (Object t : threads) {
                    JavaThread waiter = (JavaThread) t;
                    out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (MemoryAccessException ma) {
            out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) LinkedList(java.util.LinkedList) List(java.util.List) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

JavaThread (com.ibm.dtfj.java.JavaThread)22 Iterator (java.util.Iterator)14 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)13 JavaObject (com.ibm.dtfj.java.JavaObject)13 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 CorruptData (com.ibm.dtfj.image.CorruptData)5 ImageThread (com.ibm.dtfj.image.ImageThread)5 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)4 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)4 LinkedList (java.util.LinkedList)4 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaStackFrame (com.ibm.dtfj.java.JavaStackFrame)2 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)2 MonitorState (com.ibm.jvm.dtfjview.commands.helpers.MonitorState)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2