Search in sources :

Example 21 with J9ROMMethodPointer

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

the class ByteCodeDumper method dumpBytecodes.

public static IDATA dumpBytecodes(PrintStream out, J9ROMClassPointer romClass, J9ROMMethodPointer romMethod, U32 flags) throws Exception {
    U16 temp;
    UDATA length;
    out.append(String.format("  Argument Count: %d", romMethod.argCount().intValue()));
    out.append(nl);
    temp = romMethod.tempCount();
    out.append(String.format("  Temp Count: %d", temp.intValue()));
    out.append(nl);
    out.append(nl);
    length = ROMHelp.J9_BYTECODE_SIZE_FROM_ROM_METHOD(romMethod);
    if (length.eq(0)) {
        return new IDATA(BCT_ERR_NO_ERROR);
    /* catch abstract methods */
    }
    return j9bcutil_dumpBytecodes(out, romClass, ROMHelp.J9_BYTECODE_START_FROM_ROM_METHOD(romMethod), new UDATA(0), length.sub(1), flags, "");
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) IDATA(com.ibm.j9ddr.vm29.types.IDATA) U16(com.ibm.j9ddr.vm29.types.U16)

Example 22 with J9ROMMethodPointer

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

the class ByteCodeDumper method j9bcutil_dumpBytecodes.

private static IDATA j9bcutil_dumpBytecodes(PrintStream out, J9ROMClassPointer romClass, U8Pointer bytecodes, UDATA walkStartPC, UDATA walkEndPC, U32 flags, String indent) throws Exception {
    J9ROMConstantPoolItemPointer constantPool = J9ROMClassHelper.constantPool(romClass);
    J9ROMConstantPoolItemPointer info;
    J9ROMNameAndSignaturePointer nameAndSig;
    bigEndian = flags.anyBitsIn(BCT_BigEndianOutput);
    UDATA index = new UDATA(0);
    UDATA target = new UDATA(0);
    UDATA start;
    UDATA pc;
    UDATA bc;
    I32 low, high;
    U32 npairs;
    J9ROMMethodPointer romMethod = (J9ROMMethodPointer.cast(bytecodes.sub(J9ROMMethod.SIZEOF)));
    U32 localsCount = new U32(ROMHelp.J9_ARG_COUNT_FROM_ROM_METHOD(romMethod).add(ROMHelp.J9_TEMP_COUNT_FROM_ROM_METHOD(romMethod)));
    int[] resultArray = new int[8192];
    String environment = "0";
    boolean envVarDefined = false;
    int result;
    if (System.getenv().containsKey("j9bcutil_dumpBytecodes")) {
        envVarDefined = true;
        environment = System.getenv().get("j9bcutil_dumpBytecodes");
    }
    pc = new UDATA(walkStartPC);
    // cell address
    bcIndex = bytecodes.add(pc);
    while (pc.lte(walkEndPC)) {
        if (flags.anyBitsIn(BCT_DumpMaps)) {
            for (int j = LOCAL_MAP; j < MAP_COUNT; j++) {
                if (envVarDefined && (!pc.eq(Integer.parseInt(environment)))) {
                    continue;
                }
                boolean wrapLine = false;
                UDATA outputCount = new UDATA(0);
                U8 mapChar = new U8('0');
                switch(j) {
                    case LOCAL_MAP:
                        result = LocalMap.j9localmap_LocalBitsForPC(romMethod, pc, resultArray);
                        mapChar = new U8('l');
                        outputCount = new UDATA(localsCount);
                        break;
                    case DEBUG_MAP:
                        result = DebugLocalMap.j9localmap_DebugLocalBitsForPC(romMethod, pc, resultArray);
                        mapChar = new U8('d');
                        outputCount = new UDATA(localsCount);
                        break;
                    case STACK_MAP:
                        /* First call is to get the stack depth */
                        result = StackMap.j9stackmap_StackBitsForPC(pc, romClass, romMethod, null, 0);
                        mapChar = new U8('s');
                        outputCount = new UDATA(result);
                        break;
                }
                if (outputCount.eq(0)) {
                    out.append(String.format("               %cmap [empty]", (char) mapChar.intValue()));
                } else {
                    out.append(String.format("               %cmap [%5d] =", (char) mapChar.intValue(), outputCount.intValue()));
                }
                for (int i = 0; outputCount.gt(i); i++) {
                    int x = i / 32;
                    if ((i % 8) == 0) {
                        out.append(" ");
                        if (wrapLine) {
                            out.append(nl);
                        }
                    }
                    out.append(String.format("%d ", resultArray[x] & 1));
                    resultArray[x] >>= 1;
                    wrapLine = (((i + 1) % 32) == 0);
                }
                out.append(nl);
            }
        }
        // _GETNEXT_U8(bc, bcIndex);
        // #define _GETNEXT_U8(value, index) (bc = *(bcIndex++))
        // error
        bc = new UDATA(_GETNEXT_U8());
        out.append(String.format("%s%5d %s ", indent, pc.intValue(), BCNames.getName(bc.intValue())));
        start = new UDATA(pc);
        pc = pc.add(1);
        switch(bc.intValue()) {
            case JBbipush:
                index = new UDATA(_GETNEXT_U8());
                out.append(String.format("%d\n", new I8(index).intValue()));
                pc = pc.add(1);
                break;
            case JBsipush:
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d\n", new I16(index).intValue()));
                pc = pc.add(2);
                break;
            case JBldc:
            case JBldcw:
                if (bc.eq(JBldc)) {
                    index = new UDATA(_GETNEXT_U8());
                    pc = pc.add(1);
                } else {
                    index = new UDATA(_GETNEXT_U16());
                    pc = pc.add(2);
                }
                out.append(String.format("%d ", index.intValue()));
                info = constantPool.add(index);
                J9ROMSingleSlotConstantRefPointer romSingleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(info);
                if (!romSingleSlotConstantRef.cpType().eq(BCT_J9DescriptionCpTypeScalar)) {
                    /* this is a string or class constant */
                    if (romSingleSlotConstantRef.cpType().eq(BCT_J9DescriptionCpTypeClass)) {
                        /* ClassRef */
                        out.append("(java.lang.Class) ");
                    } else {
                        /* StringRef */
                        out.append("(java.lang.String) ");
                    }
                    out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
                    out.append(nl);
                } else {
                    /* this is a float/int constant */
                    out.append(String.format("(int/float) 0x%08X", romSingleSlotConstantRef.data().longValue()));
                    out.append(nl);
                }
                break;
            case JBldc2lw:
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d ", index.intValue()));
                info = constantPool.add(index);
                out.append(String.format("(long) 0x%08X%08X\n", bigEndian ? info.slot1().longValue() : info.slot2().longValue(), bigEndian ? info.slot2().longValue() : info.slot1().longValue()));
                pc = pc.add(2);
                break;
            case JBldc2dw:
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d ", index.intValue()));
                info = constantPool.add(index);
                /* this will print incorrectly on Linux ARM! FIX ME! */
                out.append(String.format("(double) 0x%08X%08X\n", bigEndian ? info.slot1().longValue() : info.slot2().longValue(), bigEndian ? info.slot2().longValue() : info.slot1().longValue()));
                pc = pc.add(2);
                break;
            case JBiload:
            case JBlload:
            case JBfload:
            case JBdload:
            case JBaload:
            case JBistore:
            case JBlstore:
            case JBfstore:
            case JBdstore:
            case JBastore:
                index = new UDATA(_GETNEXT_U8());
                pc = pc.add(1);
                out.append(String.format("%d\n", index.intValue()));
                break;
            case JBiloadw:
            case JBlloadw:
            case JBfloadw:
            case JBdloadw:
            case JBaloadw:
            case JBistorew:
            case JBlstorew:
            case JBfstorew:
            case JBdstorew:
            case JBastorew:
                index = new UDATA(_GETNEXT_U16());
                incIndex();
                pc = pc.add(3);
                out.append(String.format("%d\n", index.intValue()));
                break;
            case JBiinc:
                index = new UDATA(_GETNEXT_U8());
                out.append(String.format("%d ", index.intValue()));
                target = new UDATA(_GETNEXT_U8());
                out.append(String.format("%d\n", new I8(target).intValue()));
                pc = pc.add(2);
                break;
            case JBiincw:
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d ", index.intValue()));
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d\n", new I16(index).intValue()));
                incIndex();
                pc = pc.add(5);
                break;
            case JBifeq:
            case JBifne:
            case JBiflt:
            case JBifge:
            case JBifgt:
            case JBifle:
            case JBificmpeq:
            case JBificmpne:
            case JBificmplt:
            case JBificmpge:
            case JBificmpgt:
            case JBificmple:
            case JBifacmpeq:
            case JBifacmpne:
            case JBgoto:
            case JBifnull:
            case JBifnonnull:
                index = new UDATA(_GETNEXT_U16());
                pc = pc.add(2);
                if (OPCODE_RELATIVE_BRANCHES != 0) {
                    target = start.add(new I16(index));
                } else {
                    target = pc.add(new I16(index));
                }
                out.append(String.format("%d\n", target.intValue()));
                break;
            case JBtableswitch:
                switch(start.intValue() % 4) {
                    case 0:
                        incIndex();
                        // fall through
                        pc = pc.add(1);
                    case 1:
                        incIndex();
                        // fall through
                        pc = pc.add(1);
                    case 2:
                        incIndex();
                        // fall through
                        pc = pc.add(1);
                    case 3:
                        break;
                }
                index = new UDATA(_GETNEXT_U32());
                target = start.add(index);
                index = new UDATA(_GETNEXT_U32());
                low = new I32(index);
                index = new UDATA(_GETNEXT_U32());
                high = new I32(index);
                pc = pc.add(12);
                out.append(String.format("low %d high %d\n", low.intValue(), high.intValue()));
                out.append(String.format("        default %10d\n", target.intValue()));
                npairs = new U32(high.sub(low).add(1));
                for (int i = 0; npairs.gt(i); i++) {
                    index = new UDATA(_GETNEXT_U32());
                    target = start.add(index);
                    out.append(String.format("     %10d %10d\n", low.add(i).intValue(), target.intValue()));
                    pc = pc.add(4);
                }
                break;
            case JBlookupswitch:
                switch(start.intValue() % 4) {
                    case 0:
                        incIndex();
                        pc = pc.add(1);
                        break;
                    case 1:
                        incIndex();
                        pc = pc.add(1);
                        break;
                    case 2:
                        incIndex();
                        pc = pc.add(1);
                        break;
                    case 3:
                        break;
                }
                index = new UDATA(_GETNEXT_U32());
                target = start.add(index);
                npairs = new U32(_GETNEXT_U32());
                out.append(String.format("pairs %d\n", npairs.intValue()));
                out.append(String.format("        default %10d\n", target.intValue()));
                pc = pc.add(8);
                for (int i = 0; npairs.gt(i); i++) {
                    index = new UDATA(_GETNEXT_U32());
                    out.append(String.format("     %10d", index.intValue()));
                    index = new UDATA(_GETNEXT_U32());
                    target = start.add(index);
                    out.append(String.format(" %10d\n", target.intValue()));
                    pc = pc.add(8);
                }
                break;
            case JBgetstatic:
            case JBputstatic:
            case JBgetfield:
            case JBputfield:
                index = new UDATA(_GETNEXT_U16());
                info = constantPool.add(index);
                out.append(String.format("%d ", index.intValue()));
                // dump declaringClassName
                J9ROMFieldRefPointer romFieldRef = J9ROMFieldRefPointer.cast(info);
                out.append(J9UTF8Helper.stringValue(J9ROMClassRefPointer.cast(constantPool.add(romFieldRef.classRefCPIndex())).name()));
                nameAndSig = romFieldRef.nameAndSignature();
                out.append(".");
                /* dump name */
                out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
                out.append(" ");
                /* dump signature */
                out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
                out.append(nl);
                pc = pc.add(2);
                break;
            case JBinvokedynamic:
                index = new UDATA(_GETNEXT_U16());
                out.append(String.format("%d ", index.intValue()));
                long callSiteCount = romClass.callSiteCount().longValue();
                SelfRelativePointer callSiteData = SelfRelativePointer.cast(romClass.callSiteData());
                U16Pointer bsmIndices = U16Pointer.cast(callSiteData.addOffset(4 * callSiteCount));
                nameAndSig = J9ROMNameAndSignaturePointer.cast(callSiteData.add(index).get());
                out.append("bsm #" + String.valueOf(bsmIndices.at(index).longValue()));
                /* Bootstrap method index */
                out.append(":");
                out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
                /* dump name */
                out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
                /* dump signature */
                out.append(nl);
                pc = pc.add(4);
                break;
            case JBinvokeinterface2:
                incIndex();
                pc = pc.add(1);
                out.append(nl);
                break;
            case JBinvokehandle:
            case JBinvokehandlegeneric:
            case JBinvokevirtual:
            case JBinvokespecial:
            case JBinvokestatic:
            case JBinvokeinterface:
            case JBinvokespecialsplit:
            case JBinvokestaticsplit:
                if (bcIndex.longValue() == 0) {
                    bcIndex = bcIndex.sub(1);
                }
                index = new UDATA(_GETNEXT_U16());
                if (bc.intValue() == JBinvokestaticsplit) {
                    index = new UDATA(romClass.staticSplitMethodRefIndexes().at(index));
                } else if (bc.intValue() == JBinvokespecialsplit) {
                    index = new UDATA(romClass.specialSplitMethodRefIndexes().at(index));
                }
                info = constantPool.add(index);
                out.append(String.format("%d ", index.intValue()));
                /* dump declaringClassName and signature */
                J9ROMMethodRefPointer romMethodRef = J9ROMMethodRefPointer.cast(info);
                U32 classRefCPIndex = romMethodRef.classRefCPIndex();
                J9ROMConstantPoolItemPointer cpItem = constantPool.add(classRefCPIndex);
                J9ROMClassRefPointer romClassRef = J9ROMClassRefPointer.cast(cpItem);
                String name = J9UTF8Helper.stringValue(romClassRef.name());
                out.append(name);
                nameAndSig = romMethodRef.nameAndSignature();
                out.append(".");
                out.append(J9UTF8Helper.stringValue(nameAndSig.name()));
                /* dump name */
                out.append(J9UTF8Helper.stringValue(nameAndSig.signature()));
                /*
																 * dump
																 * signature
																 */
                out.append(nl);
                pc = pc.add(2);
                break;
            case JBnew:
            case JBnewdup:
            case JBanewarray:
            case JBcheckcast:
            case JBinstanceof:
                index = new UDATA(_GETNEXT_U16());
                info = constantPool.add(index);
                out.append(String.format("%d ", index.intValue()));
                out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
                out.append(nl);
                pc = pc.add(2);
                break;
            case JBnewarray:
                index = new UDATA(_GETNEXT_U8());
                switch(index.intValue()) {
                    case /* T_BOOLEAN */
                    4:
                        out.append("boolean\n");
                        break;
                    case /* T_CHAR */
                    5:
                        out.append("char\n");
                        break;
                    case /* T_FLOAT */
                    6:
                        out.append("float\n");
                        break;
                    case /* T_DOUBLE */
                    7:
                        out.append("double\n");
                        break;
                    case /* T_BYTE */
                    8:
                        out.append("byte\n");
                        break;
                    case /* T_SHORT */
                    9:
                        out.append("short\n");
                        break;
                    case /* T_INT */
                    10:
                        out.append("int\n");
                        break;
                    case /* T_LONG */
                    11:
                        out.append("long\n");
                        break;
                    default:
                        out.append(String.format("(unknown type %d)\n", index.intValue()));
                        break;
                }
                pc = pc.add(1);
                break;
            case JBmultianewarray:
                index = new UDATA(_GETNEXT_U16());
                info = constantPool.add(index);
                out.append(String.format("%d ", index.intValue()));
                index = new UDATA(_GETNEXT_U8());
                out.append(String.format("dims %d ", index.intValue()));
                /* dump name */
                out.append(J9UTF8Helper.stringValue(J9ROMStringRefPointer.cast(info).utf8Data()));
                out.append(nl);
                pc = pc.add(3);
                break;
            case JBgotow:
                index = new UDATA(_GETNEXT_U32());
                pc = pc.add(4);
                if (OPCODE_RELATIVE_BRANCHES != 0) {
                    target = start.add(index);
                } else {
                    target = pc.add(index);
                }
                out.append(String.format("%d\n", target.intValue()));
                break;
            default:
                out.append(nl);
                break;
        }
    }
    return new IDATA(BCT_ERR_NO_ERROR);
}
Also used : J9ROMFieldRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldRefPointer) J9ROMMethodRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodRefPointer) J9ROMClassRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassRefPointer) U8(com.ibm.j9ddr.vm29.types.U8) J9ROMSingleSlotConstantRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMSingleSlotConstantRefPointer) SelfRelativePointer(com.ibm.j9ddr.vm29.pointer.SelfRelativePointer) I32(com.ibm.j9ddr.vm29.types.I32) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) I8(com.ibm.j9ddr.vm29.types.I8) I16(com.ibm.j9ddr.vm29.types.I16) J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) U16Pointer(com.ibm.j9ddr.vm29.pointer.U16Pointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9ROMConstantPoolItemPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer) U32(com.ibm.j9ddr.vm29.types.U32) IDATA(com.ibm.j9ddr.vm29.types.IDATA)

Example 23 with J9ROMMethodPointer

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

the class RomClassWalker method allSlotsInBytecodesDo.

private void allSlotsInBytecodesDo(J9ROMMethodPointer method) throws CorruptDataException {
    U8Pointer pc, bytecodes;
    /* bytecodeSizeLow already walked */
    long length = ROMHelp.J9_BYTECODE_SIZE_FROM_ROM_METHOD(method).longValue();
    if (length == 0) {
        return;
    }
    pc = bytecodes = ROMHelp.J9_BYTECODE_START_FROM_ROM_METHOD(method);
    while ((pc.getAddress() - bytecodes.getAddress()) < length) {
        int bc = (int) pc.at(0).intValue();
        try {
            classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, BCNames.getName(bc));
        } catch (Exception e) {
        }
        pc = pc.add(1);
        I32 low;
        I32 high;
        long i;
        switch(bc) {
            /* Single 8-bit argument, no flip. */
            case BCNames.JBbipush:
            case BCNames.JBldc:
            case BCNames.JBiload:
            case BCNames.JBlload:
            case BCNames.JBfload:
            case BCNames.JBdload:
            case BCNames.JBaload:
            case BCNames.JBistore:
            case BCNames.JBlstore:
            case BCNames.JBfstore:
            case BCNames.JBdstore:
            case BCNames.JBastore:
            case BCNames.JBnewarray:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
                break;
            /* Single 16-bit argument */
            case BCNames.JBinvokeinterface2:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
            /* Deliberate fall through */
            case BCNames.JBsipush:
            case BCNames.JBldcw:
            case BCNames.JBldc2dw:
            case BCNames.JBldc2lw:
            case BCNames.JBiloadw:
            case BCNames.JBlloadw:
            case BCNames.JBfloadw:
            case BCNames.JBdloadw:
            case BCNames.JBaloadw:
            case BCNames.JBistorew:
            case BCNames.JBlstorew:
            case BCNames.JBfstorew:
            case BCNames.JBdstorew:
            case BCNames.JBastorew:
            case BCNames.JBifeq:
            case BCNames.JBifne:
            case BCNames.JBiflt:
            case BCNames.JBifge:
            case BCNames.JBifgt:
            case BCNames.JBifle:
            case BCNames.JBificmpeq:
            case BCNames.JBificmpne:
            case BCNames.JBificmplt:
            case BCNames.JBificmpge:
            case BCNames.JBificmpgt:
            case BCNames.JBificmple:
            case BCNames.JBifacmpeq:
            case BCNames.JBifacmpne:
            case BCNames.JBgoto:
            case BCNames.JBifnull:
            case BCNames.JBifnonnull:
            case BCNames.JBgetstatic:
            case BCNames.JBputstatic:
            case BCNames.JBgetfield:
            case BCNames.JBputfield:
            case BCNames.JBinvokevirtual:
            case BCNames.JBinvokespecial:
            case BCNames.JBinvokestatic:
            case BCNames.JBinvokehandle:
            case BCNames.JBinvokehandlegeneric:
            case BCNames.JBnew:
            case BCNames.JBnewdup:
            case BCNames.JBanewarray:
            case BCNames.JBcheckcast:
            case BCNames.JBinstanceof:
            case BCNames.JBinvokestaticsplit:
            case BCNames.JBinvokespecialsplit:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U16, pc, "bcArg16");
                pc = pc.add(2);
                break;
            /* Two 8-bit arguments. */
            case BCNames.JBiinc:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
                break;
            /* Two 16-bit arguments */
            case BCNames.JBiincw:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U16, pc, "bcArg16");
                pc = pc.add(2);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U16, pc, "bcArg16");
                pc = pc.add(2);
                break;
            /* 16-bit argument followed by 8-bit argument */
            case BCNames.JBmultianewarray:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U16, pc, "bcArg16");
                pc = pc.add(2);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                pc = pc.add(1);
                break;
            /* Single 32-bit argument */
            case BCNames.JBgotow:
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                pc = pc.add(4);
                break;
            case BCNames.JBtableswitch:
                int delta = (int) (pc.getAddress() - bytecodes.getAddress() - 1);
                switch(delta % 4) {
                    case 0:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcPad");
                        pc = pc.add(1);
                    case 1:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcPad");
                        pc = pc.add(1);
                    case 2:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcPad");
                        pc = pc.add(1);
                    case 3:
                        break;
                }
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                pc = pc.add(4);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                low = I32Pointer.cast(pc).at(0);
                pc = pc.add(4);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                high = I32Pointer.cast(pc).at(0);
                pc = pc.add(4);
                for (i = 0; i <= high.sub(low).longValue(); ++i) {
                    classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                    pc = pc.add(4);
                }
                break;
            case BCNames.JBlookupswitch:
                int delta2 = (int) (pc.getAddress() - bytecodes.getAddress() - 1);
                switch(delta2 % 4) {
                    case 0:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                        pc = pc.add(1);
                    case 1:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                        pc = pc.add(1);
                    case 2:
                        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcArg8");
                        pc = pc.add(1);
                    case 3:
                        break;
                }
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                pc = pc.add(4);
                classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                i = U32Pointer.cast(pc).at(0).longValue();
                pc = pc.add(4);
                while (i-- > 0) {
                    classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                    pc = pc.add(4);
                    classWalkerCallback.addSlot(clazz, SlotType.J9_U32, pc, "bcArg32");
                    pc = pc.add(4);
                }
                break;
            default:
                break;
        }
    }
    /* Walk the padding bytes. */
    long roundedLength = ROMHelp.J9_ROUNDED_BYTECODE_SIZE_FROM_ROM_METHOD(method).longValue();
    while (length++ < roundedLength) {
        classWalkerCallback.addSlot(clazz, SlotType.J9_U8, pc, "bcSectionPadding");
        pc = pc.add(1);
    }
    classWalkerCallback.addSection(clazz, bytecodes, pc.getAddress() - bytecodes.getAddress(), "methodBytecodes", true);
}
Also used : U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) I32(com.ibm.j9ddr.vm29.types.I32) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 24 with J9ROMMethodPointer

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

the class RomClassWalker method allSlotsInROMHeaderDo.

private void allSlotsInROMHeaderDo() throws CorruptDataException {
    classWalkerCallback.addSection(clazz, clazz, J9ROMClass.SIZEOF, "romHeader", true);
    /* walk the immediate fields in the J9ROMClass */
    if (J9ROMClassHelper.isArray(romClass)) {
        addObjectsasSlot(J9ROMArrayClassPointer.cast(romClass));
        return;
    } else {
        addObjectsasSlot(romClass);
    }
    /* walk interfaces SRPs block */
    SelfRelativePointer srpCursor = romClass.interfaces();
    long count = romClass.interfaceCount().longValue();
    classWalkerCallback.addSection(clazz, srpCursor, count * SelfRelativePointer.SIZEOF, "interfacesSRPs", true);
    for (int i = 0; i < count; i++) {
        classWalkerCallback.addSlot(clazz, SlotType.J9_ROM_UTF8, srpCursor, "interfaceUTF8");
        srpCursor = srpCursor.add(1);
    }
    /* walk innner classes SRPs block */
    srpCursor = romClass.innerClasses();
    count = romClass.innerClassCount().intValue();
    classWalkerCallback.addSection(clazz, srpCursor, count * SelfRelativePointer.SIZEOF, "innerClassesSRPs", true);
    for (; count > 0; count--) {
        classWalkerCallback.addSlot(clazz, SlotType.J9_ROM_UTF8, srpCursor, "innerClassNameUTF8");
        srpCursor = srpCursor.add(1);
    }
    /* add CP NAS section */
    J9ROMMethodPointer firstMethod = romClass.romMethods();
    long size = (firstMethod.getAddress() - srpCursor.getAddress());
    classWalkerCallback.addSection(clazz, srpCursor, size, "cpNamesAndSignaturesSRPs", true);
}
Also used : SelfRelativePointer(com.ibm.j9ddr.vm29.pointer.SelfRelativePointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)

Example 25 with J9ROMMethodPointer

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

the class LocalMapCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        if (args.length != 1) {
            CommandUtils.dbgPrint(out, "bad or missing PC\n");
            return;
        }
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        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 localMethod = J9JavaVMHelper.getMethodFromPC(vm, pc);
        if (localMethod.notNull()) {
            int[] localMap = new int[65536 / 32];
            CommandUtils.dbgPrint(out, "Found method %s !j9method %s\n", J9MethodHelper.getName(localMethod), localMethod.getHexAddress());
            UDATA offsetPC = new UDATA(pc.sub(U8Pointer.cast(localMethod.bytecodes())));
            CommandUtils.dbgPrint(out, "Relative PC = %d\n", offsetPC.longValue());
            J9ClassPointer localClass = J9_CLASS_FROM_CP(localMethod.constantPool());
            long methodIndex = new UDATA(localMethod.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());
            U16 tempCount = localROMMethod.tempCount();
            U8 argCount = localROMMethod.argCount();
            long localCount = tempCount.add(argCount).longValue();
            if (localCount > 0) {
                int errorCode = LocalMap.j9localmap_LocalBitsForPC(localROMMethod, offsetPC, localMap);
                if (errorCode != 0) {
                    CommandUtils.dbgPrint(out, "Local map failed, error code = %d\n", errorCode);
                } else {
                    int currentDescription = localMap[(int) ((localCount + 31) / 32)];
                    long descriptionLong = 0;
                    CommandUtils.dbgPrint(out, "Local map (%d slots mapped): local %d --> ", localCount, localCount - 1);
                    long bitsRemaining = localCount % 32;
                    if (bitsRemaining != 0) {
                        descriptionLong = currentDescription << (32 - bitsRemaining);
                        currentDescription--;
                    }
                    while (localCount != 0) {
                        if (bitsRemaining == 0) {
                            descriptionLong = currentDescription;
                            currentDescription--;
                            bitsRemaining = 32;
                        }
                        CommandUtils.dbgPrint(out, "%d", (descriptionLong & (1 << 32)) != 0 ? 1 : 0);
                        descriptionLong = descriptionLong << 1;
                        --bitsRemaining;
                        --localCount;
                    }
                    CommandUtils.dbgPrint(out, " <-- local 0\n");
                }
            } else {
                CommandUtils.dbgPrint(out, "No locals to map\n");
            }
        } else {
            CommandUtils.dbgPrint(out, "Not found\n");
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : U8(com.ibm.j9ddr.vm29.types.U8) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) U16(com.ibm.j9ddr.vm29.types.U16)

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