Search in sources :

Example 1 with BaseStackWalkerCallbacks

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

the class CheckVMThreadStacks method check.

@Override
public void check() {
    try {
        GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
        while (vmThreadListIterator.hasNext()) {
            J9VMThreadPointer walkThread = vmThreadListIterator.next();
            // GC_VMThreadStackSlotIterator::scanSlots(toScanWalkThread, toScanWalkThread, (void *)&localData, checkStackSlotIterator, false, false);
            WalkState walkState = new WalkState();
            walkState.walkThread = walkThread;
            walkState.flags = J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_DO_NOT_SNIFF_AND_WHACK | J9_STACKWALK_SKIP_INLINES;
            walkState.callBacks = new BaseStackWalkerCallbacks() {

                public void objectSlotWalkFunction(J9VMThreadPointer walkThread, WalkState walkState, PointerPointer objectSlot, VoidPointer stackAddress) {
                    _engine.checkSlotStack(objectSlot, walkThread, stackAddress);
                }
            };
            StackWalker.walkStackFrames(walkState);
        }
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 2 with BaseStackWalkerCallbacks

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

the class CheckVMThreadStacks method print.

@Override
public void print() {
    try {
        GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
        final ScanFormatter formatter = new ScanFormatter(this, "thread stacks");
        while (vmThreadListIterator.hasNext()) {
            J9VMThreadPointer walkThread = vmThreadListIterator.next();
            formatter.section("thread slots", walkThread);
            WalkState walkState = new WalkState();
            walkState.walkThread = walkThread;
            walkState.flags = J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_DO_NOT_SNIFF_AND_WHACK | J9_STACKWALK_SKIP_INLINES;
            walkState.callBacks = new BaseStackWalkerCallbacks() {

                public void objectSlotWalkFunction(J9VMThreadPointer walkThread, WalkState walkState, PointerPointer objectSlot, VoidPointer stackAddress) {
                    try {
                        formatter.entry(objectSlot.at(0));
                    } catch (CorruptDataException e) {
                    }
                }
            };
            StackWalker.walkStackFrames(walkState);
            formatter.endSection();
            formatter.section("thread stack", walkThread);
            dumpStackTrace(walkThread);
            formatter.endSection();
        }
        formatter.end("thread stacks");
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 3 with BaseStackWalkerCallbacks

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

the class JitstackCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (!J9BuildFlags.interp_nativeSupport) {
        CommandUtils.dbgPrint(out, "No JIT in this build\n");
        return;
    }
    try {
        String[] realArgs = null;
        if (args.length != 0) {
            realArgs = args[0].split(",");
        }
        if (args.length == 0 || !((realArgs.length == 3) || (realArgs.length == 4))) {
            CommandUtils.dbgPrint(out, "Usage:\n");
            CommandUtils.dbgPrint(out, "\t!jitstack thread,sp,pc\n");
            CommandUtils.dbgPrint(out, "\t!jitstack thread,sp,pc,els\n");
            CommandUtils.dbgPrint(out, "\tUse !jitstackslots instead of !jitstack to see slot values\n");
            return;
        }
        long address = CommandUtils.parsePointer(realArgs[0], J9BuildFlags.env_data64);
        J9VMThreadPointer thread = J9VMThreadPointer.cast(address);
        StackWalkerUtils.enableVerboseLogging(2, out);
        WalkState walkState = new WalkState();
        address = CommandUtils.parsePointer(realArgs[1], J9BuildFlags.env_data64);
        UDATAPointer sp = UDATAPointer.cast(address);
        address = CommandUtils.parsePointer(realArgs[2], J9BuildFlags.env_data64);
        U8Pointer pc = U8Pointer.cast(address);
        UDATAPointer arg0EA = UDATAPointer.NULL;
        J9MethodPointer literals = J9MethodPointer.NULL;
        J9VMEntryLocalStoragePointer entryLocalStorage = J9VMEntryLocalStoragePointer.NULL;
        if (realArgs.length == 4) {
            address = CommandUtils.parsePointer(realArgs[3], J9BuildFlags.env_data64);
            entryLocalStorage = J9VMEntryLocalStoragePointer.cast(address);
        } else {
            entryLocalStorage = thread.entryLocalStorage();
        }
        walkState.flags = J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET;
        walkState.flags |= J9_STACKWALK_START_AT_JIT_FRAME;
        if (command.equalsIgnoreCase("!jitstackslots")) {
            walkState.flags |= J9_STACKWALK_ITERATE_O_SLOTS;
            // 100 is highly arbitrary but basically means "print everything".
            // It is used in jextract where the message levels have been copied
            // from to begin with, so it should mean we get the same output.
            StackWalkerUtils.enableVerboseLogging(100, out);
        }
        walkState.walkThread = thread;
        walkState.callBacks = new BaseStackWalkerCallbacks();
        walkState.frameFlags = new UDATA(0);
        StackWalkResult result = StackWalker.walkStackFrames(walkState, sp, arg0EA, pc, literals, entryLocalStorage);
        if (result != StackWalkResult.NONE) {
            out.println("Stack walk result: " + result);
        }
        StackWalkerUtils.disableVerboseLogging();
        out.flush();
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) UDATAPointer(com.ibm.j9ddr.vm29.pointer.UDATAPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) StackWalkResult(com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) J9VMEntryLocalStoragePointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMEntryLocalStoragePointer)

Example 4 with BaseStackWalkerCallbacks

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

the class StackWalkCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        UDATAPointer sp = UDATAPointer.NULL;
        UDATAPointer arg0EA = UDATAPointer.NULL;
        U8Pointer pc = U8Pointer.NULL;
        J9MethodPointer literals = J9MethodPointer.NULL;
        J9VMEntryLocalStoragePointer entryLocalStorage = J9VMEntryLocalStoragePointer.NULL;
        String[] realArgs = null;
        if (args.length != 0) {
            realArgs = args[0].split(",");
        }
        if (args.length == 0 || !((realArgs.length == 1) || (realArgs.length == 5) || (realArgs.length == 6))) {
            CommandUtils.dbgPrint(out, "Usage:\n");
            CommandUtils.dbgPrint(out, "\t!stack thread\n");
            CommandUtils.dbgPrint(out, "\t!stack thread,sp,a0,pc,literals\n");
            CommandUtils.dbgPrint(out, "\t!stack thread,sp,a0,pc,literals,els\n");
            CommandUtils.dbgPrint(out, "\tUse !stackslots instead of !stack to see slot values\n");
            if (J9BuildFlags.interp_nativeSupport) {
                CommandUtils.dbgPrint(out, "\tUse !jitstack or !jitstackslots to start the walk at a JIT frame\n");
            }
            // dbgPrintRegisters(1);
            return;
        }
        long address = CommandUtils.parsePointer(realArgs[0], J9BuildFlags.env_data64);
        if (0 == address) {
            /* Parse error is captured in CommandUtils.parsePointer method and message is printed */
            return;
        }
        J9VMThreadPointer thread = J9VMThreadPointer.cast(address);
        StackWalkerUtils.enableVerboseLogging(3, out);
        WalkState walkState = new WalkState();
        walkState.flags = J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET;
        if (realArgs.length >= 5) {
            address = CommandUtils.parsePointer(realArgs[1], J9BuildFlags.env_data64);
            sp = UDATAPointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[2], J9BuildFlags.env_data64);
            arg0EA = UDATAPointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[3], J9BuildFlags.env_data64);
            pc = U8Pointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[4], J9BuildFlags.env_data64);
            literals = J9MethodPointer.cast(address);
        } else {
            sp = thread.sp();
            arg0EA = thread.arg0EA();
            pc = thread.pc();
            literals = thread.literals();
        }
        if (realArgs.length >= 6) {
            address = CommandUtils.parsePointer(realArgs[5], J9BuildFlags.env_data64);
            entryLocalStorage = J9VMEntryLocalStoragePointer.cast(address);
        } else {
            if (J9BuildFlags.interp_nativeSupport) {
                entryLocalStorage = thread.entryLocalStorage();
            }
        }
        if (command.equalsIgnoreCase("!stackslots")) {
            walkState.flags |= J9_STACKWALK_ITERATE_O_SLOTS;
            // 100 is highly arbitrary but basically means "print everything".
            // It is used in jextract where the message levels have been copied
            // from to begin with, so it should mean we get the same output.
            StackWalkerUtils.enableVerboseLogging(100, out);
            walkState.callBacks = new BaseStackWalkerCallbacks();
        } else {
            StackWalkerUtils.enableVerboseLogging(0, out);
            walkState.callBacks = new TerseStackWalkerCallbacks();
            walkState.flags |= J9_STACKWALK_ITERATE_FRAMES;
        }
        walkState.walkThread = thread;
        StackWalkResult result = StackWalker.walkStackFrames(walkState, sp, arg0EA, pc, literals, entryLocalStorage);
        if (result != StackWalkResult.NONE) {
            out.println("Stack walk result: " + result);
        }
        StackWalkerUtils.disableVerboseLogging();
        out.flush();
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) UDATAPointer(com.ibm.j9ddr.vm29.pointer.UDATAPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) StackWalkResult(com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) TerseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.TerseStackWalkerCallbacks) J9VMEntryLocalStoragePointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMEntryLocalStoragePointer)

Example 5 with BaseStackWalkerCallbacks

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

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)5 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)5 WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)5 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)5 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)2 StackWalkResult (com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)2 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)2 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)2 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)2 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)2 J9VMEntryLocalStoragePointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMEntryLocalStoragePointer)2 FrameCallbackResult (com.ibm.j9ddr.vm29.j9.stackwalker.FrameCallbackResult)1 TerseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.TerseStackWalkerCallbacks)1 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)1 UDATA (com.ibm.j9ddr.vm29.types.UDATA)1