Search in sources :

Example 71 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA 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 72 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class WhatIsCommand method resetFieldData.

private void resetFieldData() {
    foundCount = 0;
    fieldCount = 0;
    closestAbove = new UDATA(-1);
    closestAboveStack = null;
    closestBelow = new UDATA(0);
    closestBelowStack = null;
    shortestHammingDistance = new UDATA(0);
    shortestHammingDistanceStack = null;
    hammingDistance = Integer.MAX_VALUE;
    /* Clear the fieldAccessorMap to avoid hogging memory */
    fieldAccessorMap.clear();
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Example 73 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class WhatIsCommand method runWhatIs.

private void runWhatIs(String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length == 0) {
        badOrMissingSearchValue(out);
        return;
    }
    long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
    UDATA localSearchValue = new UDATA(address);
    if (localSearchValue.eq(0)) {
        badOrMissingSearchValue(out);
        return;
    }
    if (searchValue == null || !searchValue.eq(localSearchValue)) {
        searchValue = localSearchValue;
    } else {
        out.println("Skip count now " + (++skipCount) + ". Run !whatis 0 to reset it.");
    }
    resetFieldData();
    long startTime = System.currentTimeMillis();
    // Walk from the VM
    J9JavaVMPointer vm = null;
    try {
        vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException("Couldn't get VM", e);
    }
    boolean found = walkStructuresFrom(vm);
    // Walk from each VM thread
    if (!found) {
        try {
            J9VMThreadPointer mainThread = vm.mainThread();
            List<J9VMThreadPointer> threads = new LinkedList<J9VMThreadPointer>();
            if (mainThread.notNull()) {
                J9VMThreadPointer threadCursor = vm.mainThread();
                do {
                    threads.add(threadCursor);
                    threadCursor = threadCursor.linkNext();
                } while (!threadCursor.eq(mainThread) && !found);
                /* Walk the thread list backwards so we will find the match next to the closest thread (prevents walkStructures from doing anything useful with the linkNext list) */
                Collections.reverse(threads);
                for (J9VMThreadPointer thisThread : threads) {
                    found = walkStructuresFrom(thisThread);
                    if (found) {
                        break;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking thread list.");
            e.printStackTrace(out);
        }
    }
    // Walk from each class
    if (!found) {
        try {
            GCClassLoaderIterator it = GCClassLoaderIterator.from();
            OUTER: while (it.hasNext()) {
                J9ClassLoaderPointer loader = it.next();
                Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
                while (classIt.hasNext()) {
                    J9ClassPointer clazz = classIt.next();
                    found = walkStructuresFrom(clazz);
                    if (found) {
                        break OUTER;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking classes.");
            e.printStackTrace(out);
        }
    }
    long stopTime = System.currentTimeMillis();
    if (found) {
        out.println("Match found");
    } else {
        out.println("No match found");
        if (closestAboveStack != null) {
            out.print("Closest above was: ");
            closestAboveStack.dump(out);
            out.print(" at " + closestAbove.getHexValue());
            out.println();
        } else {
            out.println("No values found above search value");
        }
        if (closestBelowStack != null) {
            out.print("Closest below was: ");
            closestBelowStack.dump(out);
            out.print(" at " + closestBelow.getHexValue());
            out.println();
        } else {
            out.println("No values found below search value");
        }
        if (shortestHammingDistanceStack != null) {
            out.print("Value with shortest hamming distance (fewest single-bit changes required) was: ");
            shortestHammingDistanceStack.dump(out);
            out.print(" at " + shortestHammingDistance.getHexValue());
            out.print(". Hamming distance = " + hammingDistance);
            out.println();
        }
        /* Reset search value - so if someone reruns the same (unsuccessful) search again it won't set skipCount to 1 */
        searchValue = null;
    }
    out.println("Searched " + fieldCount + " fields to a depth of " + maxDepth + " in " + (stopTime - startTime) + " ms");
    resetFieldData();
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) LinkedList(java.util.LinkedList) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) Iterator(java.util.Iterator) ClassIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassIterator) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)

Example 74 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class ThreadsCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length == 0) {
        displayThreads(out);
    } else {
        String argument = args[0];
        // dbgext_threads
        if (argument.equalsIgnoreCase("help")) {
            help(out);
        } else {
            out.append("Attached Threads List. For more options, run !threads help\n");
            out.append(nl);
            if (argument.equalsIgnoreCase("stack")) {
                stack(out, context, "");
            } else if (argument.equalsIgnoreCase("stackslots")) {
                stack(out, context, "!stackslots");
            } else if (argument.equalsIgnoreCase("flags")) {
                flags(out);
            } else if (argument.equalsIgnoreCase("debugEventData")) {
                if (J9BuildFlags.interp_debugSupport) {
                    debugEventData(out);
                }
            } else if (argument.equalsIgnoreCase("search")) {
                search(out, new UDATA(Long.decode(args[1])));
            } else if (argument.equalsIgnoreCase("monitors")) {
                monitors(out);
            } else if (argument.equalsIgnoreCase("trace")) {
                trace(out);
            }
        }
    }
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Example 75 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class DumpSegregatedStatsCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (!GCExtensions.isSegregatedHeap()) {
        out.append("Only valid for a segregated heap\n");
        return;
    }
    try {
        /* Get the region pool */
        MM_GCExtensionsPointer extensions = GCExtensions.getGCExtensionsPointer();
        MM_RealtimeGCPointer realtimeGC = MM_RealtimeGCPointer.cast(extensions._globalCollector());
        MM_RegionPoolSegregatedPointer regionPool = realtimeGC._memoryPool()._regionPool();
        /* Get the size classes */
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMGCSizeClassesPointer sizeClasses = vm.realtimeSizeClasses();
        long countTotal = 0;
        long countAvailableSmallTotal = 0;
        long countFullSmallTotal = 0;
        long darkMatterBytesTotal = 0;
        long allocCacheBytesTotal = 0;
        /* arrayOffset is the total offset into a two dimensional array.  Used to walk the 
			 * the array linearly */
        long arrayOffset = J9Consts.J9VMGC_SIZECLASSES_MIN_SMALL * MM_RegionPoolSegregated.NUM_DEFRAG_BUCKETS;
        out.append("sizeClass | full | available           | total | free cell count | dark | cache\n");
        out.append("===============================================================================\n");
        for (long sizeClassIndex = J9Consts.J9VMGC_SIZECLASSES_MIN_SMALL; sizeClassIndex <= J9Consts.J9VMGC_SIZECLASSES_MAX_SMALL; sizeClassIndex++) {
            /* Print the sizeclass */
            UDATA cellSize = sizeClasses.smallCellSizesEA().at(sizeClassIndex);
            out.format("%2d: %5d | ", sizeClassIndex, cellSize.longValue());
            MM_HeapRegionListPointer heapRegionQueue = MM_HeapRegionListPointer.cast(regionPool._smallFullRegionsEA().at(sizeClassIndex));
            long countSmall = getTotalRegions(heapRegionQueue);
            countFullSmallTotal += countSmall;
            /* Print the number of full regions of this size class */
            out.format("%4d | ", countSmall);
            /* The number of free cells of this sizeclass */
            long freeCellCount = 0;
            for (long i = 0; i < MM_RegionPoolSegregated.NUM_DEFRAG_BUCKETS; i++) {
                long count = 0;
                MM_LockingHeapRegionQueuePointer heapRegionList = MM_LockingHeapRegionQueuePointer.cast(regionPool._smallAvailableRegionsEA().add(arrayOffset).at(0));
                for (long j = 0; j < regionPool._splitAvailableListSplitCount().longValue(); j++) {
                    count += getTotalRegions(heapRegionList);
                    freeCellCount += getFreeCellCount(heapRegionList);
                    heapRegionList = heapRegionList.add(1);
                }
                /* increment to the next list */
                arrayOffset += 1;
                countSmall += count;
                countAvailableSmallTotal += count;
                /* Print the number of available regions in this defrag bucket */
                out.format("%4d ", count);
            }
            countTotal += countSmall;
            /* Print the total number of regions of this size class, and the number of free cells */
            out.format("| %5d | %15d |", countSmall, freeCellCount);
            /* Print the percentage of darkmatter in this region */
            long darkMatterCellCount = regionPool._darkMatterCellCountEA().at(sizeClassIndex).longValue();
            darkMatterBytesTotal += darkMatterCellCount * cellSize.longValue();
            out.format("%%%3d | ", countSmall == 0 ? 0 : darkMatterCellCount / (countSmall * cellSize.longValue()));
            /* Calculate the number of bytes in allocation caches */
            long allocCacheSize = 0;
            J9VMThreadPointer mainThread = vm.mainThread();
            if (mainThread.notNull()) {
                J9VMThreadPointer threadCursor = vm.mainThread();
                do {
                    J9VMGCSegregatedAllocationCacheEntryPointer cache = threadCursor.segregatedAllocationCache();
                    cache = cache.add(sizeClassIndex);
                    allocCacheSize += cache.top().longValue() - cache.current().longValue();
                    threadCursor = threadCursor.linkNext();
                } while (!threadCursor.eq(mainThread));
            }
            out.format("%5d\n", allocCacheSize);
            allocCacheBytesTotal += allocCacheSize;
        }
        long regionSize = extensions.heap()._heapRegionManager()._regionSize().longValue();
        out.format("region size %d\n", regionSize);
        long arrayletLeafSize = extensions._omrVM()._arrayletLeafSize().longValue();
        out.format("arraylet leaf size %d\n", arrayletLeafSize);
        out.format("small total (full, available) region count %d (%d, %d)\n", countTotal, countFullSmallTotal, countAvailableSmallTotal);
        long countFullArraylet = getTotalRegions(regionPool._arrayletFullRegions());
        long countAvailArraylet = getTotalRegions(regionPool._arrayletAvailableRegions());
        long countTotalArraylet = countFullArraylet + countAvailArraylet;
        countTotal += countTotalArraylet;
        out.format("arraylet total (full, available) region count %d (%d %d)\n", countTotalArraylet, countFullArraylet, countAvailArraylet);
        long countLarge = getTotalRegions(regionPool._largeFullRegions());
        countTotal += countLarge;
        out.format("large full region count %d\n", countLarge);
        long countFree = getTotalRegions(regionPool._singleFreeList());
        countTotal += countFree;
        out.format("free region count %d\n", countFree);
        long countMultiFree = getTotalRegions(regionPool._multiFreeList());
        countTotal += countMultiFree;
        out.format("multiFree region count %d\n", countMultiFree);
        long countCoalesce = getTotalRegions(regionPool._coalesceFreeList());
        countTotal += countCoalesce;
        out.format("coalesce region count %d\n", countCoalesce);
        long heapSize = countTotal * regionSize;
        out.format("total region count %d, total heap size %d \n", countTotal, heapSize);
        out.format("dark matter total bytes %d (%2.2f%% of heap)\n", darkMatterBytesTotal, 100.0 * darkMatterBytesTotal / heapSize);
        out.format("allocation cache total bytes %d (%2.2f%% of heap)\n", allocCacheBytesTotal, 100.0 * allocCacheBytesTotal / heapSize);
    } catch (CorruptDataException e) {
        e.printStackTrace();
    }
}
Also used : MM_HeapRegionListPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionListPointer) MM_LockingHeapRegionQueuePointer(com.ibm.j9ddr.vm29.pointer.generated.MM_LockingHeapRegionQueuePointer) MM_RegionPoolSegregatedPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_RegionPoolSegregatedPointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9VMGCSegregatedAllocationCacheEntryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMGCSegregatedAllocationCacheEntryPointer) J9VMGCSizeClassesPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMGCSizeClassesPointer) MM_RealtimeGCPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_RealtimeGCPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) MM_GCExtensionsPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_GCExtensionsPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Aggregations

UDATA (com.ibm.j9ddr.vm29.types.UDATA)86 CorruptDataException (com.ibm.j9ddr.CorruptDataException)22 U32 (com.ibm.j9ddr.vm29.types.U32)16 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)14 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)10 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)10 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)9 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)8 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)8 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)7 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)6 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)5 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)4 U16 (com.ibm.j9ddr.vm29.types.U16)4 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)3 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)3 J9ArrayClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ArrayClassPointer)3 J9JITExceptionTablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9JITExceptionTablePointer)3 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)3 IDATA (com.ibm.j9ddr.vm29.types.IDATA)3