Search in sources :

Example 11 with ObjectMonitor

use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.

the class MonitorsCommand method objectsCommand.

private void objectsCommand(FilterOptions filter, PrintStream out) throws DDRInteractiveCommandException {
    try {
        HashSet<ObjectMonitor> monitors = new HashSet<ObjectMonitor>();
        MonitorTableListIterator iterator = new MonitorTableListIterator();
        MonitorTable previousMonitorTable = null;
        StringBuilder builder = new StringBuilder();
        while (iterator.hasNext()) {
            J9ObjectMonitorPointer objectMonitorPointer = iterator.next();
            MonitorTable currentMonitorTable = iterator.currentMonitorTable();
            ObjectMonitor found = tablePrintHelper(filter, builder, objectMonitorPointer);
            if (null != found) {
                monitors.add(found);
            }
            if (!currentMonitorTable.equals(previousMonitorTable) && (builder.length() > 0)) {
                /* Print header for new monitor table */
                if (null != previousMonitorTable) {
                    out.println();
                }
                out.println(iterator.currentMonitorTable().extraInfo());
                previousMonitorTable = currentMonitorTable;
            }
            out.append(builder);
            builder.setLength(0);
        }
        // Don't forget leftover flatlocked monitors on heap, these have no associated table:
        Iterator<ObjectMonitor> flatMonitorIterator = HeapWalker.getFlatLockedMonitors().iterator();
        while (flatMonitorIterator.hasNext()) {
            ObjectMonitor objMon = flatMonitorIterator.next();
            if (!monitors.contains(objMon)) {
                writeObjectMonitorToBuffer(filter, objMon, builder);
            }
        }
        if (builder.length() > 0) {
            out.append("<Flatlocked Monitors on Heap>\n");
            out.append(builder);
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9ObjectMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectMonitorPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) MonitorTableListIterator(com.ibm.j9ddr.vm29.j9.MonitorTableListIterator) MonitorTable(com.ibm.j9ddr.vm29.j9.MonitorTable) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor) HashSet(java.util.HashSet)

Example 12 with ObjectMonitor

use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.

the class CheckMonitorTable method print.

@Override
public void print() {
    try {
        VoidPointer monitorTableList = VoidPointer.cast(getJavaVM().monitorTableList());
        GCMonitorReferenceIterator monitorReferenceIterator = GCMonitorReferenceIterator.from();
        MonitorTable previousMonitorTable = null;
        ScanFormatter formatter = new ScanFormatter(this, "MonitorTableList", monitorTableList);
        while (monitorReferenceIterator.hasNext()) {
            J9ObjectMonitorPointer objectMonitor = monitorReferenceIterator.next();
            MonitorTable currentMonitorTable = monitorReferenceIterator.currentMonitorTable();
            if (!currentMonitorTable.equals(previousMonitorTable)) {
                if (null != previousMonitorTable) {
                    formatter.endSection();
                }
                formatter.section("MonitorTable", currentMonitorTable.getMonitorTableListEntryPointer());
            }
            J9ThreadAbstractMonitorPointer monitor = J9ThreadAbstractMonitorPointer.cast(objectMonitor.monitor());
            formatter.entry(VoidPointer.cast(monitor.userData()));
            previousMonitorTable = currentMonitorTable;
        }
        if (null != previousMonitorTable) {
            formatter.endSection();
        }
        formatter.end("MonitorTableList", monitorTableList);
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9ObjectMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectMonitorPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) GCMonitorReferenceIterator(com.ibm.j9ddr.vm29.j9.gc.GCMonitorReferenceIterator) MonitorTable(com.ibm.j9ddr.vm29.j9.MonitorTable) J9ThreadAbstractMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer)

Example 13 with ObjectMonitor

use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.

the class DeadlockUtils method readObjectMonitors.

/**
 * Returns a hash map of Object Pointers to their respective mutex (Object Monitor or System Monitor)
 * @param vm
 * @return
 * @throws CorruptDataException
 */
public static HashMap<J9ObjectPointer, Object> readObjectMonitors(J9JavaVMPointer vm) throws CorruptDataException {
    HashMap<J9ObjectPointer, Object> objectMonitorsMap = new HashMap<J9ObjectPointer, Object>();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof ObjectMonitor) {
            ObjectMonitor mon = (ObjectMonitor) current;
            J9ObjectPointer object = mon.getObject();
            objectMonitorsMap.put(object, mon);
        } else if (current instanceof J9ThreadMonitorPointer) {
            // System Monitor
            J9ThreadMonitorPointer mon = (J9ThreadMonitorPointer) current;
            J9ThreadAbstractMonitorPointer lock = J9ThreadAbstractMonitorPointer.cast(mon);
            if (false == lock.userData().eq(0)) {
                // this is an object monitor in the system monitor table
                J9ObjectPointer object = J9ObjectPointer.cast(lock.userData());
                objectMonitorsMap.put(object, mon);
            }
        }
    }
    return objectMonitorsMap;
}
Also used : MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) HashMap(java.util.HashMap) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9ThreadAbstractMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor)

Example 14 with ObjectMonitor

use of com.ibm.j9ddr.vm29.j9.ObjectMonitor in project openj9 by eclipse.

the class DeadlockUtils method findThreadCycle.

/**
 * @param vmThread
 * @param map
 * @throws CorruptDataException
 */
public static void findThreadCycle(J9ThreadPointer aThread, HashMap<Integer, NativeDeadlockGraphNode> deadlocks, HashMap<J9ObjectPointer, Object> objectMonitorsMap) throws CorruptDataException {
    // Based on JavaCoreDumpWriter::findThreadCycle()
    // Can't stack allocate or (safely) re-purpose an object in Java,
    // so we create a new one on each iteration, this is slightly
    // different from what is done in javadump.cpp
    NativeDeadlockGraphNode node = null;
    NativeDeadlockGraphNode prev = null;
    do {
        // Is there an associated J9VMThread?
        J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(aThread);
        boolean isJavaThread = (null != vmThread) && vmThread.notNull();
        // Enter waiter (blocked) or notify waiter.
        boolean isJavaWaiter = false;
        if (isJavaThread) {
            // There is, so grab all the J9VMThread related information.
            JavaDeadlockGraphNode javaNode = new JavaDeadlockGraphNode();
            javaNode.javaThread = vmThread;
            J9VMThreadPointer owner = null;
            J9ObjectPointer lockObject = null;
            J9ThreadAbstractMonitorPointer lock = null;
            // Functionally equivalent to getVMThreadStateHelper(...) in thrinfo.c
            lockObject = vmThread.blockingEnterObject();
            if ((null != lockObject) && lockObject.notNull()) {
                // This condition hitting means we are in one of the desired states:
                // J9VMTHREAD_STATE_BLOCKED
                // J9VMTHREAD_STATE_WAITING, J9VMTHREAD_STATE_WAITING_TIMED
                // J9VMTHREAD_STATE_PARKED, J9VMTHREAD_STATE_PARKED_TIMED
                isJavaWaiter = true;
                // The original native relies on getVMThreadStateHelper(...)
                // from thrinfo.c to obtain this information, which is analogous
                // to J9VMThreadPointerUtil.getJ9State(...), but we don't actually
                // need all that information.
                Object current = objectMonitorsMap.get(lockObject);
                if (current instanceof ObjectMonitor) {
                    ObjectMonitor mon = (ObjectMonitor) current;
                    owner = mon.getOwner();
                    lock = mon.getInflatedMonitor();
                } else if (current instanceof J9ThreadMonitorPointer) {
                    // System Monitor
                    J9ThreadMonitorPointer mon = (J9ThreadMonitorPointer) current;
                    J9ThreadPointer sysThread = mon.owner();
                    lock = J9ThreadAbstractMonitorPointer.cast(mon);
                    if (sysThread.notNull()) {
                        owner = J9ThreadHelper.getVMThread(sysThread);
                    }
                }
                if ((null == owner) || owner.isNull() || (owner.equals(vmThread))) {
                    // See JAZZ103 63676: There are cases where even if we know there is no
                    // Java deadlock, we should still check for a system deadlock.
                    // We simply deal with this node as a native one from this point on.
                    isJavaWaiter = false;
                } else {
                    // N.B. In the native there are comparisons with J9VMTHREAD_STATE_*
                    // constants as returned by the helper, but here we don't actually need them.
                    javaNode.javaLock = lock;
                    javaNode.lockObject = lockObject;
                    javaNode.cycle = 0;
                    /* Record current thread and update last node */
                    javaNode.nativeThread = vmThread.osThread();
                    deadlocks.put(javaNode.hashCode(), javaNode);
                    if (null != prev) {
                        prev.next = javaNode;
                    }
                    /* Move around the graph */
                    prev = javaNode;
                    /* Peek ahead to see if we're in a possible cycle */
                    prev.next = deadlocks.get(owner.osThread().hashCode());
                    aThread = owner.osThread();
                }
            }
            // Have to keep going for the case of Java thread blocking on system monitor.
            // We have to write the J9Thread info as well.
            node = javaNode;
        }
        if (false == isJavaThread) {
            node = new NativeDeadlockGraphNode();
        }
        // Now get all of the J9Thread fields (even when we are working with a Java thread).
        node.nativeThread = aThread;
        J9ThreadMonitorPointer nativeLock = aThread.monitor();
        J9ThreadPointer owner = null;
        if ((null == nativeLock) || nativeLock.isNull()) {
            if (false == isJavaThread) {
                return;
            }
        } else {
            node.nativeLock = nativeLock;
            owner = nativeLock.owner();
        }
        // to change the pointers, otherwise we have to set them up.
        if (false == isJavaWaiter) {
            deadlocks.put(node.hashCode(), node);
            if (null != prev) {
                prev.next = node;
            }
            if ((null == owner) || owner.isNull() || (owner.equals(aThread))) {
                return;
            } else {
                /* Move around the graph */
                prev = node;
                /* Peek ahead to see if we're in a possible cycle */
                prev.next = deadlocks.get(owner.hashCode());
                aThread = owner;
            }
        }
    } while (// Quit as soon as possible (first node we've already visited).
    null == prev.next);
// The rest of the cycles will be found by multiple calls to findThreadCycle(...)
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9ThreadAbstractMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor)

Aggregations

ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)8 CorruptDataException (com.ibm.j9ddr.CorruptDataException)6 J9ObjectMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectMonitorPointer)6 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)6 J9ThreadAbstractMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer)6 J9ThreadMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)4 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)3 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)3 MonitorTable (com.ibm.j9ddr.vm29.j9.MonitorTable)2 GCMonitorReferenceIterator (com.ibm.j9ddr.vm29.j9.gc.GCMonitorReferenceIterator)2 MonitorIterator (com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator)2 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)2 MonitorTableListIterator (com.ibm.j9ddr.vm29.j9.MonitorTableListIterator)1 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)1 GCHeapRegionIterator (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator)1 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)1 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)1 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)1 MM_GCExtensionsPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_GCExtensionsPointer)1 MM_HeapRegionManagerPointer (com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionManagerPointer)1