Search in sources :

Example 81 with DDRInteractiveCommandException

use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.

the class WalkInternTableCommand method run.

/**
 * This method is used to run !walkinterntable command.
 *
 * @param	command 	!walkinterntable
 * @param 	args		Args passed by command !walkinterntable.
 * !walkinterntable prints the usage if no arg is passed, otherwise it accepts valid integer arg.
 * If the arg is not valid, then user is warned and usage is printed.
 * @param 	context
 * @param 	out		PrintStream is used to print the messages in this class.
 * @return	void
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        int userSelection;
        if (args.length == 0) {
            printUsage(out);
        } else if (args.length == 1) {
            if (args[0].trim().equalsIgnoreCase("help")) {
                printUsage(out);
                return;
            }
            try {
                userSelection = Integer.parseInt(args[0]);
                runWalkInternTableSelection(userSelection, out, context, false);
                return;
            } catch (NumberFormatException e) {
                out.append("Error: Invalid Option :" + args[0] + nl);
                printUsage(out);
                return;
            }
        } else {
            out.append("Error: Too many options : ");
            for (int i = 0; i < args.length; i++) {
                out.append(args[i].toString());
                if (i + 1 < args.length) {
                    out.append(", ");
                }
            }
            out.append(nl + "!walkintertable expects none(to print usage and valid args) or one integer arg." + nl);
            printUsage(out);
            return;
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 82 with DDRInteractiveCommandException

use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.

the class WalkInternTableCommand method runSubMenu.

/**
 * This method is used when user requests to go into the sub menu.
 * User stays in the sub menu until he/she requests to exit sub menu.
 * Therefore this method is recursive until exit is requested.
 * @param context	Context
 * @param out	PrintStream
 * @throws DDRInteractiveCommandException
 * @return void
 */
private void runSubMenu(Context context, PrintStream out) throws DDRInteractiveCommandException {
    String userInput;
    BufferedReader reader;
    int userSelection;
    reader = new BufferedReader(new InputStreamReader(System.in));
    out.append("!walkinterntable sub menu command >  " + nl);
    try {
        try {
            userInput = reader.readLine();
        } catch (IOException e) {
            out.append("Exception occured while reading the user input" + nl);
            e.printStackTrace();
            return;
        }
        try {
            if (userInput.compareToIgnoreCase("exit") == 0) {
                out.append("Exiting !walkinterntable sub menu..." + nl);
                return;
            }
            userSelection = Integer.parseInt(userInput);
            runWalkInternTableSelection(userSelection, out, context, true);
        } catch (NumberFormatException e) {
            userInput = userInput.trim();
            if (userInput.toLowerCase().equals("quit")) {
                out.println("To quit, please go back to main menu. (Type \"exit\")" + nl);
            } else {
                String[] components = userInput.split("\\s");
                String[] arguments = new String[components.length - 1];
                for (int i = 1; i < components.length; i++) {
                    arguments[i - 1] = components[i];
                }
                context.execute(components[0].toLowerCase(), arguments, out);
            }
        }
        runSubMenu(context, out);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) IOException(java.io.IOException) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 83 with DDRInteractiveCommandException

use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.

the class StackWalkCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        UDATAPointer sp = UDATAPointer.NULL;
        UDATAPointer arg0EA = UDATAPointer.NULL;
        U8Pointer pc = U8Pointer.NULL;
        J9MethodPointer literals = J9MethodPointer.NULL;
        J9VMEntryLocalStoragePointer entryLocalStorage = J9VMEntryLocalStoragePointer.NULL;
        String[] realArgs = null;
        if (args.length != 0) {
            realArgs = args[0].split(",");
        }
        if (args.length == 0 || !((realArgs.length == 1) || (realArgs.length == 5) || (realArgs.length == 6))) {
            CommandUtils.dbgPrint(out, "Usage:\n");
            CommandUtils.dbgPrint(out, "\t!stack thread\n");
            CommandUtils.dbgPrint(out, "\t!stack thread,sp,a0,pc,literals\n");
            CommandUtils.dbgPrint(out, "\t!stack thread,sp,a0,pc,literals,els\n");
            CommandUtils.dbgPrint(out, "\tUse !stackslots instead of !stack to see slot values\n");
            if (J9BuildFlags.interp_nativeSupport) {
                CommandUtils.dbgPrint(out, "\tUse !jitstack or !jitstackslots to start the walk at a JIT frame\n");
            }
            // dbgPrintRegisters(1);
            return;
        }
        long address = CommandUtils.parsePointer(realArgs[0], J9BuildFlags.env_data64);
        if (0 == address) {
            /* Parse error is captured in CommandUtils.parsePointer method and message is printed */
            return;
        }
        J9VMThreadPointer thread = J9VMThreadPointer.cast(address);
        StackWalkerUtils.enableVerboseLogging(3, out);
        WalkState walkState = new WalkState();
        walkState.flags = J9_STACKWALK_RECORD_BYTECODE_PC_OFFSET;
        if (realArgs.length >= 5) {
            address = CommandUtils.parsePointer(realArgs[1], J9BuildFlags.env_data64);
            sp = UDATAPointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[2], J9BuildFlags.env_data64);
            arg0EA = UDATAPointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[3], J9BuildFlags.env_data64);
            pc = U8Pointer.cast(address);
            address = CommandUtils.parsePointer(realArgs[4], J9BuildFlags.env_data64);
            literals = J9MethodPointer.cast(address);
        } else {
            sp = thread.sp();
            arg0EA = thread.arg0EA();
            pc = thread.pc();
            literals = thread.literals();
        }
        if (realArgs.length >= 6) {
            address = CommandUtils.parsePointer(realArgs[5], J9BuildFlags.env_data64);
            entryLocalStorage = J9VMEntryLocalStoragePointer.cast(address);
        } else {
            if (J9BuildFlags.interp_nativeSupport) {
                entryLocalStorage = thread.entryLocalStorage();
            }
        }
        if (command.equalsIgnoreCase("!stackslots")) {
            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.callBacks = new BaseStackWalkerCallbacks();
        } else {
            StackWalkerUtils.enableVerboseLogging(0, out);
            walkState.callBacks = new TerseStackWalkerCallbacks();
            walkState.flags |= J9_STACKWALK_ITERATE_FRAMES;
        }
        walkState.walkThread = thread;
        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) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) TerseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.TerseStackWalkerCallbacks) J9VMEntryLocalStoragePointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMEntryLocalStoragePointer)

Example 84 with DDRInteractiveCommandException

use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException 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)

Example 85 with DDRInteractiveCommandException

use of com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException in project openj9 by eclipse.

the class WalkJ9PoolCommand method walkJ9Pool.

/**
 * This method walks through each element in the pool and prints each elements' address.
 * Elements can be in the same puddle or different, and this method do not print puddle information.
 *
 * @param address address of the pool
 * @param out print stream
 * @throws DDRInteractiveCommandException
 */
private void walkJ9Pool(long address, PrintStream out) throws DDRInteractiveCommandException {
    try {
        J9PoolPointer j9pool = J9PoolPointer.cast(address);
        Pool pool = Pool.fromJ9Pool(j9pool, VoidPointer.class);
        SlotIterator<VoidPointer> poolIterator = pool.iterator();
        VoidPointer currentElement;
        int i = 0;
        while (poolIterator.hasNext()) {
            currentElement = poolIterator.next();
            out.println(String.format("\t[%d]\t=\t%s", i++, currentElement.getHexAddress()));
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException("Either address is not a valid pool address or pool itself is corrupted.");
    }
}
Also used : J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) Pool(com.ibm.j9ddr.vm29.j9.Pool) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Aggregations

DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)86 CorruptDataException (com.ibm.j9ddr.CorruptDataException)81 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)38 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)16 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)16 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)16 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)11 ClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker)8 LinearDumper (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper)8 ClassSegmentIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator)7 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)6 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)6 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)6 UDATA (com.ibm.j9ddr.vm29.types.UDATA)6 PatternString (com.ibm.j9ddr.util.PatternString)5 ROMClassesIterator (com.ibm.j9ddr.vm29.j9.walkers.ROMClassesIterator)5 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)5 RomClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.RomClassWalker)5 MonitorTable (com.ibm.j9ddr.vm29.j9.MonitorTable)4 MonitorTableListIterator (com.ibm.j9ddr.vm29.j9.MonitorTableListIterator)4