Search in sources :

Example 1 with J9ThreadLibraryPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer in project openj9 by eclipse.

the class MonitorsCommand method j9threadCommand.

/**
 * See {@link MonitorsCommand#helpCommand(String[], PrintStream)} for
 * function documentation
 *
 * @param args
 *            command args
 * @param out
 *            the output stream
 * @throws DDRInteractiveCommandException
 */
private void j9threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length < 2) {
        out.println("This command takes one address argument: \"!monitors j9thread <address>\"");
        return;
    }
    try {
        long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
        VoidPointer ptr = VoidPointer.cast(address);
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMThreadPointer mainThread = vm.mainThread();
        if (mainThread.isNull() || mainThread.osThread().isNull() || mainThread.osThread().library().isNull()) {
            throw new CorruptDataException("Cannot locate thread library");
        }
        J9ThreadLibraryPointer lib = mainThread.osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            if (ptr.equals(poolIterator.next())) {
                osThreadPtr = J9ThreadPointer.cast(ptr);
            }
        }
        if (null == osThreadPtr) {
            throw new DDRInteractiveCommandException(String.format("Could not find any j9thread at address %s\n", ptr.getHexAddress()));
        }
        // Is there an associated J9VMThread?
        J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
        // Step 1: Print the general info for the VM and native threads:
        out.println(String.format("%s\t%s\t// %s", osThreadPtr.formatShortInteractive(), vmThread.notNull() ? vmThread.formatShortInteractive() : "<none>", vmThread.notNull() ? J9VMThreadHelper.getName(vmThread) : "[osthread]"));
        printMonitorsForJ9Thread(out, vm, osThreadPtr);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)

Example 2 with J9ThreadLibraryPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer in project openj9 by eclipse.

the class MonitorsCommand method threadCommand.

/**
 * Dumps all monitors that are active for the specified J9Thread/J9VMThread/java.lang.Thread
 * @param args
 * @param out
 * @throws DDRInteractiveCommandException
 */
private void threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length < 2) {
        out.println("This command takes one address argument: \"!monitors thread <address>\"");
        return;
    }
    try {
        long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
        VoidPointer ptr = VoidPointer.cast(address);
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMThreadPointer mainThread = vm.mainThread();
        J9ThreadLibraryPointer lib = mainThread.osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            osThreadPtr = poolIterator.next();
            // Is there an associated J9VMThread?
            J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
            J9ObjectPointer jlThread = null;
            if (vmThread.notNull()) {
                jlThread = vmThread.threadObject();
                if ((null != jlThread) && jlThread.equals(ptr)) {
                    out.println("Found java/lang/Thread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                } else if (vmThread.equals(ptr)) {
                    out.println("Found j9vmthread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                }
            }
            if (osThreadPtr.equals(ptr)) {
                out.println("Found j9thread @ " + ptr.getHexAddress());
                if (vmThread.notNull()) {
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                }
                printMonitorsForJ9Thread(out, vm, osThreadPtr);
                return;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 3 with J9ThreadLibraryPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer in project openj9 by eclipse.

the class DeadlockDetector method findDeadlocks.

/**
 * @param out
 * @throws DDRInteractiveCommandException
 */
public static void findDeadlocks(PrintStream out) throws DDRInteractiveCommandException {
    // Based on JavaCoreDumpWriter::writeDeadLocks()
    // Modified to work for both J9VMThreads and J9Threads.
    HashMap<Integer, NativeDeadlockGraphNode> map = new HashMap<Integer, NativeDeadlockGraphNode>();
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        HashMap<J9ObjectPointer, Object> objectMonitorsMap = DeadlockUtils.readObjectMonitors(vm);
        J9ThreadLibraryPointer lib = vm.mainThread().osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            osThreadPtr = poolIterator.next();
            DeadlockUtils.findThreadCycle(osThreadPtr, map, objectMonitorsMap);
            // Is there an associated J9VMThread?
            J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
            if ((null != vmThread) && (vmThread.notNull()) && vmThread.publicFlags().allBitsIn(J9Consts.J9_PUBLIC_FLAGS_HALT_THREAD_INSPECTION)) {
                break;
            }
        }
        // Identifier for each (independent) cycle.
        int cycle = 0;
        Iterator<Map.Entry<Integer, NativeDeadlockGraphNode>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            NativeDeadlockGraphNode node = iterator.next().getValue();
            cycle++;
            while (null != node) {
                if (node.cycle > 0) {
                    // it means we've looped around!
                    if (node.cycle == cycle) {
                        // Output header for each deadlock:
                        out.println("Deadlock Detected !!!");
                        out.println("---------------------");
                        out.println();
                        NativeDeadlockGraphNode head = node;
                        boolean isCycleRoot = true;
                        do {
                            DeadlockUtils.writeDeadlockNode(node, isCycleRoot, objectMonitorsMap, out);
                            node = node.next;
                            isCycleRoot = false;
                        } while (node != head);
                        out.println(node.toString());
                    }
                    // Skip already visited nodes
                    break;
                } else {
                    node.cycle = cycle;
                }
                node = node.next;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) HashMap(java.util.HashMap) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)3 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)3 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)3 J9ThreadLibraryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)3 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)3 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)3 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)2 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)2 HashMap (java.util.HashMap)1