Search in sources :

Example 6 with WalkState

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

the class MethodForNameCommand method dbgGetMethodsForName.

int dbgGetMethodsForName(PrintStream out, String pattern) throws CorruptDataException {
    int matchCount = 0;
    // J9ClassWalkState walkState;
    String classNeedle, methodNeedle, sigNeedle;
    long classMatchFlags, methodMatchFlags, sigMatchFlags;
    String classStart, nameStart, sigStart;
    if (pattern.indexOf('.') != -1) {
        // skip the .
        nameStart = pattern.substring(pattern.indexOf('.') + 1);
        classStart = pattern.substring(0, pattern.indexOf('.'));
    } else {
        classStart = "*";
        nameStart = pattern;
    }
    if (pattern.indexOf('(') != -1) {
        sigStart = pattern.substring(pattern.indexOf('('));
    } else {
        sigStart = "*";
    }
    StringBuffer needleBuffer = new StringBuffer();
    classMatchFlags = WildCard.parseWildcard(classStart, needleBuffer);
    classNeedle = needleBuffer.toString();
    if (classMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in class name\n");
        return 0;
    }
    needleBuffer = new StringBuffer();
    methodMatchFlags = WildCard.parseWildcard(nameStart, needleBuffer);
    methodNeedle = needleBuffer.toString();
    if (methodMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
        return 0;
    }
    needleBuffer = new StringBuffer();
    sigMatchFlags = WildCard.parseWildcard(sigStart, needleBuffer);
    sigNeedle = needleBuffer.toString();
    if (methodMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
        return 0;
    }
    Hashtable<String, J9ClassPointer> loadedClasses = new Hashtable<String, J9ClassPointer>();
    GCClassLoaderIterator classLoaderIterator = GCClassLoaderIterator.from();
    while (classLoaderIterator.hasNext()) {
        J9ClassLoaderPointer loader = classLoaderIterator.next();
        Iterator<J9ClassPointer> classItterator = ClassIterator.fromJ9Classloader(loader);
        while (classItterator.hasNext()) {
            J9ClassPointer clazz = classItterator.next();
            J9ROMClassPointer romClazz = clazz.romClass();
            String className = J9UTF8Helper.stringValue(romClazz.className());
            if (loadedClasses.containsValue(clazz)) {
                continue;
            } else {
                loadedClasses.put(clazz.toString(), clazz);
            }
            if (WildCard.wildcardMatch(classMatchFlags, classNeedle, className)) {
                J9MethodPointer methodCursor = clazz.ramMethods();
                for (long count = romClazz.romMethodCount().longValue(); count > 0; count--, methodCursor = methodCursor.add(1)) {
                    J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(methodCursor);
                    J9ROMNameAndSignaturePointer nameAndSignature = romMethod.nameAndSignature();
                    String nameUTF = J9UTF8Helper.stringValue(nameAndSignature.name());
                    if (WildCard.wildcardMatch(methodMatchFlags, methodNeedle, nameUTF)) {
                        String sigUTF = J9UTF8Helper.stringValue(nameAndSignature.signature());
                        if (WildCard.wildcardMatch(sigMatchFlags, sigNeedle, sigUTF)) {
                            matchCount++;
                            CommandUtils.dbgPrint(out, String.format("!j9method %s --> %s.%s%s\n", methodCursor.getHexAddress(), className, nameUTF, sigUTF));
                        }
                    }
                }
            }
        }
    }
    return matchCount;
}
Also used : Hashtable(java.util.Hashtable) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)

Example 7 with WalkState

use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState 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 8 with WalkState

use of com.ibm.j9ddr.vm29.j9.stackwalker.WalkState 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 9 with WalkState

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

the class DTFJJavaThread method walkStack.

// this function is the entry point for the stack walking and provides the top level catch for Exceptions and NoSuchFieldErrors
private void walkStack() {
    frames = new LinkedList<Object>();
    WalkState walkState = new WalkState();
    walkState.walkThread = thread;
    walkState.flags = J9_STACKWALK_VISIBLE_ONLY | J9_STACKWALK_INCLUDE_NATIVES | J9_STACKWALK_ITERATE_FRAMES | J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET | J9_STACKWALK_ITERATE_O_SLOTS;
    walkState.callBacks = new StackWalkerCallbacks();
    register((IEventListener) walkState.callBacks);
    StackWalkResult result = StackWalkResult.STACK_CORRUPT;
    try {
        result = StackWalker.walkStackFrames(walkState);
    } catch (Throwable t) {
        J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
        result = StackWalkResult.STACK_CORRUPT;
    }
    unregister((IEventListener) walkState.callBacks);
    if (result != StackWalkResult.NONE) {
        frames.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Bad return from stack walker walking thread 0x" + Long.toHexString(walkState.walkThread.getAddress()) + ". Some stack frames may be missing. Final state = " + result));
    }
}
Also used : BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) JavaObject(com.ibm.dtfj.java.JavaObject) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) StackWalkResult(com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)

Example 10 with WalkState

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

Aggregations

WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)8 CorruptDataException (com.ibm.j9ddr.CorruptDataException)7 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)6 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)6 StackWalkResult (com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)5 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)4 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)4 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)3 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)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 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)2 J9VMEntryLocalStoragePointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMEntryLocalStoragePointer)2 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 JavaObject (com.ibm.dtfj.java.JavaObject)1 GCClassLoaderIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)1 FrameCallbackResult (com.ibm.j9ddr.vm29.j9.stackwalker.FrameCallbackResult)1 IStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.IStackWalkerCallbacks)1