Search in sources :

Example 1 with MonitorIterator

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

the class DumpContendedLoadTable method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (0 != args.length) {
        String argument = args[0];
        if (argument.equalsIgnoreCase("help")) {
            help(out);
            return;
        }
    }
    try {
        J9JavaVMPointer javaVM = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9HashTablePointer contTable = javaVM.contendedLoadTable();
        J9PoolPointer poolPtr = contTable.listNodePool();
        Pool<J9ContendedLoadTableEntryPointer> pool = Pool.fromJ9Pool(poolPtr, J9ContendedLoadTableEntryPointer.class);
        SlotIterator<J9ContendedLoadTableEntryPointer> poolIterator = pool.iterator();
        if (poolIterator.hasNext()) {
            out.println("Active class loads:");
            while (poolIterator.hasNext()) {
                J9ContendedLoadTableEntryPointer entryPointer = poolIterator.next();
                String ldStatus = loadingStatusValues.get(entryPointer.status().longValue());
                if (null == ldStatus) {
                    ldStatus = "ILLEGAL VALUE: " + entryPointer.status();
                }
                J9VMThreadPointer loadingThread = entryPointer.thread();
                out.print(String.format("\tClassname: %s;\n\t\tLoader:  %s; Loading thread: %s %s\n\t\tStatus: %s; Table entry hash 0x%X\n", entryPointer.className().getCStringAtOffset(0, entryPointer.classNameLength().longValue()), entryPointer.classLoader().formatShortInteractive(), J9VMThreadHelper.getName(loadingThread), loadingThread.formatShortInteractive(), ldStatus, entryPointer.hashValue().longValue()));
            }
            MonitorIterator iterator = new MonitorIterator(javaVM);
            while (iterator.hasNext()) {
                Object current = iterator.next();
                if (current instanceof J9ThreadMonitorPointer) {
                    // System Monitor
                    SystemMonitor monitor = SystemMonitor.fromJ9ThreadMonitor((J9ThreadMonitorPointer) current);
                    final String monitorName = monitor.getName();
                    if (monitorName.matches(".*VM class table.*")) {
                        List<J9ThreadPointer> waitingThreads = monitor.getWaitingThreads();
                        if (!waitingThreads.isEmpty()) {
                            out.print("Waiting threads:\n");
                            for (J9ThreadPointer tp : waitingThreads) {
                                J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(tp);
                                if (vmThread.notNull()) {
                                    out.print(String.format("\t%s\t%s\n", vmThread.formatShortInteractive(), J9VMThreadHelper.getName(vmThread)));
                                } else {
                                    out.print(String.format("\t%s\t%s\n", tp.formatShortInteractive(), "[osthread]"));
                                }
                            }
                        }
                        break;
                    }
                }
            }
        } else {
            out.println("No active class loads");
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9HashTablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) SystemMonitor(com.ibm.j9ddr.vm29.j9.SystemMonitor) J9ContendedLoadTableEntryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ContendedLoadTableEntryPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)

Example 2 with MonitorIterator

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

the class MonitorsCommand method printMonitorsForJ9VMThread.

private void printMonitorsForJ9VMThread(PrintStream out, J9JavaVMPointer vm, J9VMThreadPointer thread) throws CorruptDataException {
    FilterOptions defaultFilter = FilterOptions.defaultOption();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof ObjectMonitor) {
            ObjectMonitor objMon = (ObjectMonitor) current;
            // Step 2: Print any monitors that the thread is the owner of:
            if (thread.equals(objMon.getOwner())) {
                out.print("Owns Object Monitor:\n\t");
                writeObjectMonitor(defaultFilter, objMon, out);
            }
            // Step 3: Print any monitors that the thread is blocking on::
            for (J9VMThreadPointer threadPtr : objMon.getBlockedThreads()) {
                if (threadPtr.equals(thread)) {
                    out.print(String.format("Blocking on (Enter Waiter):\n\t"));
                    writeObjectMonitor(defaultFilter, objMon, out);
                }
            }
            // Step 4: Print any monitors that the thread is waiting on:
            for (J9VMThreadPointer threadPtr : objMon.getWaitingThreads()) {
                if (threadPtr.equals(thread)) {
                    out.print(String.format("Waiting on (Notify Waiter):\n\t"));
                    writeObjectMonitor(defaultFilter, objMon, out);
                }
            }
        }
    }
}
Also used : MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) ObjectMonitor(com.ibm.j9ddr.vm29.j9.ObjectMonitor)

Example 3 with MonitorIterator

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

the class MonitorsCommand method printMonitorsForJ9Thread.

private void printMonitorsForJ9Thread(PrintStream out, J9JavaVMPointer vm, J9ThreadPointer osThreadPtr) throws CorruptDataException {
    FilterOptions defaultFilter = FilterOptions.defaultOption();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof J9ThreadMonitorPointer) {
            // System Monitor
            SystemMonitor monitor = SystemMonitor.fromJ9ThreadMonitor((J9ThreadMonitorPointer) current);
            List<J9ThreadPointer> threadList = null;
            // Step 2: Print any monitors that the thread is the owner of:
            J9ThreadPointer ownerPtr = monitor.getOwner();
            if (ownerPtr.notNull() && ownerPtr.equals(osThreadPtr)) {
                out.print("Owns System Monitor:\n\t");
                writeSystemMonitor(defaultFilter, monitor, out);
            }
            // Step 3: Print any monitors that the thread is blocking on:
            threadList = monitor.getBlockedThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Blocking on System Monitor (Enter Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
            // Step 4: Print any monitors that the thread is waiting on:
            threadList = monitor.getWaitingThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Waiting on System Monitor (Notify Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
        }
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) SystemMonitor(com.ibm.j9ddr.vm29.j9.SystemMonitor) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)

Example 4 with MonitorIterator

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

the class MonitorsCommand method systemCommand.

private void systemCommand(FilterOptions filter, PrintStream out) throws DDRInteractiveCommandException {
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        MonitorIterator iterator = new MonitorIterator(vm);
        while (iterator.hasNext()) {
            Object current = iterator.next();
            if (current instanceof J9ThreadMonitorPointer) {
                // System Monitor
                SystemMonitor monitor = SystemMonitor.fromJ9ThreadMonitor((J9ThreadMonitorPointer) current);
                writeSystemMonitor(filter, monitor, out);
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) SystemMonitor(com.ibm.j9ddr.vm29.j9.SystemMonitor) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 5 with MonitorIterator

use of com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator 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)

Aggregations

MonitorIterator (com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator)5 J9ThreadMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)4 SystemMonitor (com.ibm.j9ddr.vm29.j9.SystemMonitor)3 CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)2 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)2 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)2 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)2 J9ContendedLoadTableEntryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ContendedLoadTableEntryPointer)1 J9HashTablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer)1 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)1 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)1 J9ThreadAbstractMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer)1 HashMap (java.util.HashMap)1