Search in sources :

Example 41 with J9VMThreadPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer 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)

Example 42 with J9VMThreadPointer

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

the class CheckVMThreadStacks method dumpStackTrace.

/* TODO : this is an implementation of the internal VM function dumpStackTrace
	 * and really should be somewhere global and public */
private void dumpStackTrace(J9VMThreadPointer walkThread) {
    WalkState walkState = new WalkState();
    walkState.walkThread = walkThread;
    walkState.flags = J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_ITERATE_FRAMES;
    walkState.callBacks = new BaseStackWalkerCallbacks() {

        public FrameCallbackResult frameWalkFunction(J9VMThreadPointer walkThread, WalkState walkState) {
            String className = "(unknown class)";
            if (walkState.constantPool.notNull()) {
                try {
                    className = J9ClassHelper.getName(walkState.constantPool.ramClass());
                } catch (CorruptDataException e) {
                // TODO Auto-generated catch block
                }
            }
            if (walkState.method.isNull()) {
                getReporter().println(String.format("0x%08X %s (unknown method)", walkState.pc.getAddress(), className));
            } else {
                if (walkState.jitInfo.isNull()) {
                    boolean isNative = false;
                    U8Pointer bytecodes = U8Pointer.NULL;
                    String name = "(corrupt)";
                    String sig = "(corrupt)";
                    try {
                        J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(walkState.method);
                        isNative = romMethod.modifiers().allBitsIn(J9_JAVA_NATIVE);
                        if (!isNative) {
                            bytecodes = J9ROMMethodHelper.bytecodes(romMethod);
                        }
                        name = J9ROMMethodHelper.getName(romMethod);
                        sig = J9ROMMethodHelper.getSignature(romMethod);
                    } catch (CorruptDataException e) {
                    // This should never happen
                    }
                    if (isNative) {
                        getReporter().println(String.format(" NATIVE   %s.%s%s", className, name, sig));
                    } else {
                        getReporter().println(String.format(" %08X %s.%s%s", walkState.pc.sub(bytecodes).longValue(), className, name, sig));
                    }
                } else {
                    boolean isInlined = walkState.inlineDepth != 0;
                    U8Pointer jitPC = walkState.pc;
                    String name = "(corrupt)";
                    String sig = "(corrupt)";
                    try {
                        J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(walkState.method);
                        name = J9UTF8Helper.stringValue(romMethod.nameAndSignature().name());
                        sig = J9UTF8Helper.stringValue(romMethod.nameAndSignature().signature());
                        if (!isInlined) {
                            jitPC = U8Pointer.cast(jitPC.sub(U8Pointer.cast(walkState.method.extra())).longValue());
                        }
                    } catch (CorruptDataException e) {
                    // This should never happen
                    }
                    if (isInlined) {
                        getReporter().println(String.format(" INLINED  %s.%s%s  (@%s)", className, name, sig, formatPointer(walkState.pc)));
                    } else {
                        getReporter().println(String.format(" %08X %s.%s%s  (@%s)", jitPC.getAddress(), className, name, sig, formatPointer(walkState.pc)));
                    }
                }
            }
            return FrameCallbackResult.KEEP_ITERATING;
        }
    };
    StackWalker.walkStackFrames(walkState);
}
Also used : BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) CorruptDataException(com.ibm.j9ddr.CorruptDataException) FrameCallbackResult(com.ibm.j9ddr.vm29.j9.stackwalker.FrameCallbackResult)

Example 43 with J9VMThreadPointer

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

the class CheckVMThreads method print.

@Override
public void print() {
    try {
        GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
        ScanFormatter formatter = new ScanFormatter(this, "VMThread Slots");
        while (vmThreadListIterator.hasNext()) {
            J9VMThreadPointer walkThread = vmThreadListIterator.next();
            formatter.section("thread", walkThread);
            GCVMThreadIterator vmthreadIterator = GCVMThreadIterator.fromJ9VMThread(walkThread);
            while (vmthreadIterator.hasNext()) {
                formatter.entry(vmthreadIterator.next());
            }
            formatter.endSection();
        }
        formatter.end("VMThread Slots");
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) GCVMThreadIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadIterator)

Example 44 with J9VMThreadPointer

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

the class DTFJJavaRuntime method getThreads.

@SuppressWarnings("rawtypes")
public Iterator getThreads() {
    GCVMThreadListIterator threadIterator;
    try {
        threadIterator = GCVMThreadListIterator.from();
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        return corruptIterator(cd);
    }
    List<Object> toIterate = new LinkedList<Object>();
    AddCorruptionToListListener listener = new AddCorruptionToListListener(toIterate);
    register(listener);
    try {
        while (threadIterator.hasNext() && !listener.fatalCorruption()) {
            J9VMThreadPointer next = threadIterator.next();
            if (next != null) {
                toIterate.add(new DTFJJavaThread(next));
            }
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        toIterate.add(cd);
    }
    unregister(listener);
    return toIterate.iterator();
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) JavaObject(com.ibm.dtfj.java.JavaObject) AddCorruptionToListListener(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.AddCorruptionToListListener) LinkedList(java.util.LinkedList)

Aggregations

J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)39 CorruptDataException (com.ibm.j9ddr.CorruptDataException)28 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)16 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)15 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)13 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)9 WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)7 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)6 UDATA (com.ibm.j9ddr.vm29.types.UDATA)6 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)5 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)5 StackWalkResult (com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)4 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)4 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)4 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)3 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)3 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)3 J9ThreadLibraryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)3 LinkedList (java.util.LinkedList)3 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)2