Search in sources :

Example 1 with MonitorState

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

the class InfoThreadCommand method getMonitors.

@SuppressWarnings("rawtypes")
private void getMonitors(JavaRuntime jr) {
    int corruptThreadCount = 0;
    int corruptMonitorCount = 0;
    Iterator itMonitor = jr.getMonitors();
    while (itMonitor.hasNext()) {
        Object obj = itMonitor.next();
        if (obj instanceof CorruptData) {
            corruptMonitorCount++;
            continue;
        }
        JavaMonitor jm = (JavaMonitor) obj;
        Iterator itEnterWaiter = jm.getEnterWaiters();
        while (itEnterWaiter.hasNext()) {
            obj = itEnterWaiter.next();
            if (obj instanceof CorruptData) {
                corruptThreadCount++;
                continue;
            }
            JavaThread jt = (JavaThread) obj;
            monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_ENTER));
        }
        if (corruptThreadCount > 0) {
            String msg = String.format("Warning : %d corrupt thread(s) were found waiting to enter monitor %s", corruptThreadCount, getMonitorName(jm));
            logger.fine(msg);
        }
        corruptThreadCount = 0;
        Iterator itNotifyWaiter = jm.getNotifyWaiters();
        while (itNotifyWaiter.hasNext()) {
            obj = itNotifyWaiter.next();
            if (obj instanceof CorruptData) {
                corruptThreadCount++;
                continue;
            }
            JavaThread jt = (JavaThread) obj;
            monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_BE_NOTIFIED_ON));
        }
        if (corruptThreadCount > 0) {
            String msg = String.format("Warning : %d corrupt thread(s) were found waiting to be notified on monitor %s", corruptThreadCount, getMonitorName(jm));
            logger.fine(msg);
        }
    }
    if (corruptMonitorCount > 0) {
        String msg = String.format("Warning : %d corrupt monitor(s) were found", corruptMonitorCount);
        logger.fine(msg);
    }
}
Also used : MonitorState(com.ibm.jvm.dtfjview.commands.helpers.MonitorState) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 2 with MonitorState

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

Aggregations

JavaObject (com.ibm.dtfj.java.JavaObject)2 JavaThread (com.ibm.dtfj.java.JavaThread)2 MonitorState (com.ibm.jvm.dtfjview.commands.helpers.MonitorState)2 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)1 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)1 Iterator (java.util.Iterator)1