Search in sources :

Example 1 with FrameCallbackResult

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

the class TerseStackWalkerCallbacks method frameWalkFunction.

public FrameCallbackResult frameWalkFunction(J9VMThreadPointer walkThread, WalkState walkState) {
    try {
        if (walkState.method.notNull()) {
            J9MethodPointer method = walkState.method;
            J9UTF8Pointer className = StackWalkerUtils.UNTAGGED_METHOD_CP(method).ramClass().romClass().className();
            J9ROMMethodPointer romMethod = J9_ROM_METHOD_FROM_RAM_METHOD(method);
            J9UTF8Pointer name = romMethod.nameAndSignature().name();
            J9UTF8Pointer sig = romMethod.nameAndSignature().signature();
            StackWalkerUtils.swPrintf(walkState, 0, "\t!j9method {3}   {0}.{1}{2}", J9UTF8Helper.stringValue(className), J9UTF8Helper.stringValue(name), J9UTF8Helper.stringValue(sig), walkState.method.getHexAddress());
            return FrameCallbackResult.KEEP_ITERATING;
        }
        if (walkState.pc.getAddress() == J9SF_FRAME_TYPE_JNI_NATIVE_METHOD) {
            StackWalkerUtils.swPrintf(walkState, 0, "\t                        Native method frame");
        } else if (walkState.pc.getAddress() == J9SF_FRAME_TYPE_GENERIC_SPECIAL) {
            StackWalkerUtils.swPrintf(walkState, 0, "\t                        Generic special frame");
        } else if (walkState.pc.getAddress() == J9SF_FRAME_TYPE_METHODTYPE) {
            StackWalkerUtils.swPrintf(walkState, 0, "\t                        MethodType frame");
        } else {
            if (walkState.pc.getAddress() > J9SF_MAX_SPECIAL_FRAME_TYPE) {
                if (walkState.pc.getAddress() == walkState.walkThread.javaVM().callInReturnPC().getAddress() || walkState.pc.getAddress() == (walkState.walkThread.javaVM().callInReturnPC().getAddress() + 3)) {
                    StackWalkerUtils.swPrintf(walkState, 0, "\t                        JNI call-in frame");
                } else {
                    StackWalkerUtils.swPrintf(walkState, 0, "\t                        unknown frame type {0} *{1}", walkState.pc, walkState.pc.getHexAddress());
                }
            } else {
                StackWalkerUtils.swPrintf(walkState, 0, "\t                        known but unhandled frame type {0}", walkState.pc);
            }
        }
    } catch (CorruptDataException e) {
        e.printStackTrace();
    }
    return FrameCallbackResult.KEEP_ITERATING;
}
Also used : J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) J9UTF8Pointer(com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 2 with FrameCallbackResult

use of com.ibm.j9ddr.vm29.j9.stackwalker.FrameCallbackResult 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)2 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)2 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)1 FrameCallbackResult (com.ibm.j9ddr.vm29.j9.stackwalker.FrameCallbackResult)1 WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)1 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)1 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)1 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)1 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)1