Search in sources :

Example 11 with J9ROMMethodPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer 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 12 with J9ROMMethodPointer

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

the class StackmapCommand method run.

/**
 *  Java representation of j9dbgext.c#dbgext_stackmap function.
 *
 *  @param  command DDR extension command of stackmap.
 *                  It is supposed to be "stackmap" if this method is being called.
 *  @param  args    Arguments passed to !stackmap DDR extension.
 *                  Only one argument is expected since !stackmap expects only the address.
 *  @param  context Current context that DDR is running on.
 *  @param  out     Print stream to write the output.
 *
 *  @return void
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length != 1) {
        printUsage(out);
        return;
    }
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        if (null == vm) {
            out.println("vm can not be found.");
        }
        long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
        U8Pointer pc = U8Pointer.cast(address);
        CommandUtils.dbgPrint(out, "Searching for PC=%d in VM=%s...\n", pc.longValue(), vm.getHexAddress());
        J9MethodPointer remoteMethod = J9JavaVMHelper.getMethodFromPC(vm, pc);
        if (remoteMethod.notNull()) {
            int[] stackMap = new int[MAX_STACKSLOTS_COUNT / INT_SIZE_IN_BITS];
            int leftMostBitIntMask = 1 << (INT_SIZE_IN_BITS - 1);
            CommandUtils.dbgPrint(out, "Found method %s !j9method %s\n", J9MethodHelper.getName(remoteMethod), remoteMethod.getHexAddress());
            UDATA offsetPC = new UDATA(pc.sub(U8Pointer.cast(remoteMethod.bytecodes())));
            CommandUtils.dbgPrint(out, "Relative PC = %d\n", offsetPC.longValue());
            J9ClassPointer localClass = J9_CLASS_FROM_CP(remoteMethod.constantPool());
            long methodIndex = new UDATA(remoteMethod.sub(localClass.ramMethods())).longValue();
            CommandUtils.dbgPrint(out, "Method index is %d\n", methodIndex);
            J9ROMMethodPointer localROMMethod = J9ROMCLASS_ROMMETHODS(localClass.romClass());
            while (methodIndex != 0) {
                localROMMethod = ROMHelp.nextROMMethod(localROMMethod);
                --methodIndex;
            }
            CommandUtils.dbgPrint(out, "Using ROM method %s\n", localROMMethod.getHexAddress());
            /*
				 * This call will return the depth of the stack or errorcode in case of a failure.
				 */
            int errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, null, 0);
            if (0 > errorCode) {
                CommandUtils.dbgPrint(out, "Stack map failed, error code = %d\n", errorCode);
            } else {
                int stackMapIndex = 0;
                if (0 != errorCode) {
                    /* This call to j9stackmap_StackBitsForPC will fill the stackMap */
                    errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, stackMap, errorCode);
                    int currentDescription = stackMap[stackMapIndex];
                    int descriptionInt = 0;
                    CommandUtils.dbgPrint(out, "Stack map (%d slots mapped): ", errorCode);
                    long bitsRemaining = errorCode % INT_SIZE_IN_BITS;
                    if (bitsRemaining != 0) {
                        descriptionInt = currentDescription << (INT_SIZE_IN_BITS - bitsRemaining);
                        currentDescription++;
                    }
                    while (errorCode != 0) {
                        if (bitsRemaining == 0) {
                            descriptionInt = currentDescription;
                            currentDescription = stackMap[++stackMapIndex];
                            bitsRemaining = INT_SIZE_IN_BITS;
                        }
                        CommandUtils.dbgPrint(out, "%d", (descriptionInt & (leftMostBitIntMask)) != 0 ? 1 : 0);
                        descriptionInt = descriptionInt << 1;
                        --bitsRemaining;
                        --errorCode;
                    }
                    CommandUtils.dbgPrint(out, "\n");
                } else {
                    CommandUtils.dbgPrint(out, "Stack is empty\n");
                }
            }
        } else {
            CommandUtils.dbgPrint(out, "Not found\n");
        }
    } catch (CorruptDataException e) {
    }
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 13 with J9ROMMethodPointer

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

the class J9MethodFieldFormatter method postFormat.

/* (non-Javadoc)
	 * @see com.ibm.j9ddr.tools.ddrinteractive.IFieldFormatter#postFormat(java.lang.String, java.lang.String, int, long, java.io.PrintStream, com.ibm.j9ddr.tools.ddrinteractive.Context, com.ibm.j9ddr.tools.ddrinteractive.IStructureFormatter)
	 */
@Override
public FormatWalkResult postFormat(String name, String type, String declaredType, int typeCode, long address, PrintStream out, Context context, IStructureFormatter structureFormatter) throws CorruptDataException {
    if (typeCode == TYPE_STRUCTURE_POINTER && StructureCommandUtil.typeToCommand(type).equals("!j9method")) {
        PointerPointer slotPtr = PointerPointer.cast(address);
        J9MethodPointer method = J9MethodPointer.cast(slotPtr.at(0));
        if (method.isNull()) {
            return FormatWalkResult.KEEP_WALKING;
        }
        out.print(" // ");
        J9ROMMethodPointer j9romMethod = J9MethodHelper.romMethod(method);
        J9ClassPointer clazz = ConstantPoolHelpers.J9_CLASS_FROM_METHOD(method);
        out.print(J9ClassHelper.getName(clazz));
        out.print(".");
        out.print(J9ROMMethodHelper.getName(j9romMethod));
        out.print(J9ROMMethodHelper.getSignature(j9romMethod));
    }
    return FormatWalkResult.KEEP_WALKING;
}
Also used : J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)

Example 14 with J9ROMMethodPointer

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

the class J9MethodStructureFormatter method writeJ9ROMClassAddress.

private static void writeJ9ROMClassAddress(J9MethodPointer method, PrintStream out) {
    out.print("ROM Method: ");
    try {
        J9ROMMethodPointer j9romMethod = J9MethodHelper.romMethod(method);
        out.print("!j9rommethod ");
        out.print(j9romMethod.getHexAddress());
    } catch (CorruptDataException e) {
        out.print("<FAULT>");
    } finally {
        out.println();
    }
}
Also used : J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 15 with J9ROMMethodPointer

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

the class J9MethodStructureFormatter method writeMethodName.

private static void writeMethodName(J9MethodPointer method, PrintStream out) {
    out.print("Signature: ");
    try {
        J9ROMMethodPointer j9romMethod = J9MethodHelper.romMethod(method);
        J9ClassPointer clazz = ConstantPoolHelpers.J9_CLASS_FROM_METHOD(method);
        out.print(J9ClassHelper.getName(clazz));
        out.print(".");
        out.print(J9ROMMethodHelper.getName(j9romMethod));
        out.print(J9ROMMethodHelper.getSignature(j9romMethod));
        out.print(" !bytecodes ");
        out.print(method.getHexAddress());
    } catch (CorruptDataException ex) {
        out.print("<FAULT>");
    } finally {
        out.println();
    }
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Aggregations

J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)22 CorruptDataException (com.ibm.j9ddr.CorruptDataException)10 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)10 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)9 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)7 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)7 U32 (com.ibm.j9ddr.vm29.types.U32)6 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)5 J9ROMNameAndSignaturePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer)5 UDATA (com.ibm.j9ddr.vm29.types.UDATA)5 SelfRelativePointer (com.ibm.j9ddr.vm29.pointer.SelfRelativePointer)4 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)4 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)3 J9ROMClassAndMethod (com.ibm.j9ddr.vm29.j9.walkers.J9ROMClassAndMethod)3 U16 (com.ibm.j9ddr.vm29.types.U16)3 U8 (com.ibm.j9ddr.vm29.types.U8)3 J9ROMFieldShapeIterator (com.ibm.j9ddr.vm29.j9.J9ROMFieldShapeIterator)2 J9ExceptionInfoPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ExceptionInfoPointer)2 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)2 J9ROMConstantPoolItemPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer)2