Search in sources :

Example 1 with U64Pointer

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

the class VMConstantPoolCommand method run.

/**
 * Run method for !vmconstantpool extension.
 *
 * @param command  !vmconstantpool
 * @param args	args passed by !vmconstantpool extension.
 * @param context Context
 * @param out PrintStream
 * @throws DDRInteractiveCommandException
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        J9JavaVMPointer javaVM;
        javaVM = J9RASHelper.getVM(DataType.getJ9RASPointer());
        if (args.length == 1) {
            long vmaddress = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
            if (vmaddress != javaVM.getAddress()) {
                out.println(args[0] + " is not a valid j9javavm address. Run !findvm to find out the j9javavm address of the current context");
                return;
            }
        } else if (args.length > 1) {
            printUsage(out);
        }
        J9ConstantPoolPointer jclConstantPool = J9ConstantPoolPointer.cast(javaVM.jclConstantPoolEA());
        J9ROMClassPointer romClass = jclConstantPool.ramClass().romClass();
        int index;
        U32Pointer cpShapeDescription;
        int constPoolCount;
        cpShapeDescription = romClass.cpShapeDescription();
        long cpDescription = cpShapeDescription.at(0).longValue();
        constPoolCount = romClass.romConstantPoolCount().intValue();
        PointerPointer cpEntry = PointerPointer.cast(J9ROMClassHelper.constantPool(romClass));
        long cpDescriptionIndex = 0;
        for (index = 0; index < constPoolCount; index++) {
            if (0 == cpDescriptionIndex) {
                // Load a new description word
                cpDescription = cpShapeDescription.at(0).longValue();
                cpShapeDescription = cpShapeDescription.add(1);
                cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
            }
            long shapeDesc = cpDescription & J9_CP_DESCRIPTION_MASK;
            AbstractPointer ref = PointerPointer.NULL;
            if (shapeDesc == J9CPTYPE_CLASS) {
                ref = J9ROMClassRefPointer.cast(cpEntry);
            } else if (shapeDesc == J9CPTYPE_STRING) {
                ref = J9ROMStringRefPointer.cast(cpEntry);
            } else if ((shapeDesc == J9CPTYPE_INT) || (shapeDesc == J9CPTYPE_FLOAT)) {
                ref = J9ROMConstantPoolItemPointer.cast(cpEntry);
            } else if (shapeDesc == J9CPTYPE_LONG) {
                U64Pointer longPointer = U64Pointer.cast(cpEntry);
                out.println("Long at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.getHexValue() + "\n}");
            } else if (shapeDesc == J9CPTYPE_DOUBLE) {
                U64Pointer longPointer = U64Pointer.cast(cpEntry);
                out.println("Double at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.at(0).longValue() + "\n}");
            } else if ((shapeDesc == J9CPTYPE_INSTANCE_METHOD) || (shapeDesc == J9CPTYPE_STATIC_METHOD) || (shapeDesc == J9CPTYPE_INTERFACE_METHOD) || (shapeDesc == J9CPTYPE_HANDLE_METHOD) || (shapeDesc == J9CPTYPE_FIELD)) {
                long classRefCPIndex;
                if (shapeDesc == J9CPTYPE_FIELD) {
                    ref = J9ROMFieldRefPointer.cast(cpEntry);
                    /* gets the classRefCPIndex to obtain a pointer to the j9romclassref */
                    classRefCPIndex = J9ROMFieldRefPointer.cast(ref).classRefCPIndex().longValue();
                } else {
                    ref = J9ROMFieldRefPointer.cast(cpEntry);
                    classRefCPIndex = J9ROMMethodRefPointer.cast(ref).classRefCPIndex().longValue();
                }
                PointerPointer classRefCPEntry = PointerPointer.cast(J9ROMClassHelper.constantPool(romClass)).addOffset(J9ROMConstantPoolItem.SIZEOF * classRefCPIndex);
                /* gets the DDR output of the item */
                String outString = ref.formatFullInteractive();
                String[] parts = outString.split(nl);
                /* add a debug extension(!j9romclassref) on the second line of the output */
                parts[1] += "(!j9romclassref " + classRefCPEntry.getHexAddress() + ")";
                out.print(join(nl, parts));
            } else if ((shapeDesc == J9CPTYPE_UNUSED) || (shapeDesc == J9CPTYPE_UNUSED8)) {
                U64Pointer longPointer = U64Pointer.cast(cpEntry);
                out.println("Unused at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.at(0).longValue() + "\n}");
            } else if (ref.notNull()) {
                out.println(ref.formatFullInteractive());
            }
            cpEntry = cpEntry.addOffset(J9ROMConstantPoolItem.SIZEOF);
            cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
            cpDescriptionIndex -= 1;
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) U64Pointer(com.ibm.j9ddr.vm29.pointer.U64Pointer) J9ConstantPoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ConstantPoolPointer) U32Pointer(com.ibm.j9ddr.vm29.pointer.U32Pointer)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)1 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)1 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)1 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)1 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)1 U64Pointer (com.ibm.j9ddr.vm29.pointer.U64Pointer)1 J9ConstantPoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ConstantPoolPointer)1 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)1 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)1