Search in sources :

Example 66 with J9ClassPointer

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

the class ITableSizeCommand method iTableChainSize.

public long iTableChainSize(J9ITablePointer startTable, J9ITablePointer superTable) throws CorruptDataException {
    long size = 0;
    J9ITablePointer iTable = startTable;
    while (!iTable.eq(superTable)) {
        size += J9ITable.SIZEOF;
        J9ClassPointer interfaceClass = iTable.interfaceClass();
        J9ROMClassPointer romClass = interfaceClass.romClass();
        size += (UDATA.SIZEOF * romClass.romMethodCount().intValue());
        iTable = iTable.next();
    }
    return size;
}
Also used : J9ITablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ITablePointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)

Example 67 with J9ClassPointer

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

the class ITableSizeCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    long currentSize = 0;
    long duplicatedSize = 0;
    long extendedSize = 0;
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        ClassSegmentIterator classSegmentIterator = new ClassSegmentIterator(vm.classMemorySegments());
        while (classSegmentIterator.hasNext()) {
            J9ClassPointer clazz = (J9ClassPointer) classSegmentIterator.next();
            int classDepth = clazz.classDepthAndFlags().bitAnd(J9_JAVA_CLASS_DEPTH_MASK).intValue();
            J9ITablePointer superITable = J9ITablePointer.NULL;
            J9ITablePointer startITable = J9ITablePointer.cast(clazz.iTable());
            if (0 != classDepth) {
                PointerPointer superclasses = clazz.superclasses();
                J9ClassPointer superclazz = J9ClassPointer.cast(superclasses.at(classDepth - 1));
                superITable = J9ITablePointer.cast(superclazz.iTable());
            }
            currentSize += iTableChainSize(startITable, superITable);
            duplicatedSize += iTableChainSize(superITable, J9ITablePointer.NULL);
            extendedSize += iTableExtendedSize(startITable, superITable);
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
    long totalSize = duplicatedSize + currentSize;
    double percent = (double) totalSize / (double) currentSize;
    out.append("iTable duplication" + nl);
    out.append("------------------" + nl);
    out.append("current    iTable size : " + currentSize + nl);
    out.append("additional iTable size : " + duplicatedSize + nl);
    out.append("total      iTable size : " + totalSize + nl);
    out.append("growth factor          : " + percent + nl);
    out.append(nl);
    percent = (double) extendedSize / (double) currentSize;
    out.append("iTable contains extends" + nl);
    out.append("-----------------------" + nl);
    out.append("current    iTable size : " + currentSize + nl);
    out.append("new        iTable size : " + extendedSize + nl);
    out.append("growth factor          : " + percent + nl);
    out.append(nl);
}
Also used : ClassSegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator) J9ITablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ITablePointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 68 with J9ClassPointer

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

the class J9ClassShapeCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length != 1) {
        CommandUtils.dbgPrint(out, "Usage: !j9classshape <classAddress>\n");
        return;
    }
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9ClassPointer instanceClass = J9ClassPointer.NULL;
        String classSelector = args[0];
        if (classSelector.matches("\\p{Digit}.*")) {
            /* addresses start with a decimal digit, possibly the '0' in "0x" */
            instanceClass = J9ClassPointer.cast(CommandUtils.parsePointer(classSelector, J9BuildFlags.env_data64));
        } else {
            J9ClassPointer[] candidates = findClassByName(vm, classSelector);
            if (candidates.length == 0) {
                CommandUtils.dbgPrint(out, "No classes matching \"" + classSelector + "\" found\n");
                return;
            } else if (candidates.length > 1) {
                CommandUtils.dbgPrint(out, "Multiple classes matching \"" + classSelector + "\" found\n");
                return;
            } else {
                instanceClass = candidates[0];
                String javaName = J9ClassHelper.getJavaName(instanceClass);
                String hexString = instanceClass.getHexAddress();
                CommandUtils.dbgPrint(out, String.format("!j9class %1$s\n", hexString));
            }
        }
        J9ClassPointer previousSuperclass = J9ClassPointer.NULL;
        String className = J9ClassHelper.getName(instanceClass);
        J9VMThreadPointer mainThread = vm.mainThread();
        boolean lockwordPrinted = true;
        if (J9BuildFlags.thr_lockNursery) {
            lockwordPrinted = false;
        }
        CommandUtils.dbgPrint(out, "Instance fields in %s:\n", className);
        CommandUtils.dbgPrint(out, "\noffset     name\tsignature\t(declaring class)\n");
        if (mainThread.isNull()) {
            /* we cannot print the instance fields without this */
            return;
        }
        long depth = J9ClassHelper.classDepth(instanceClass).longValue();
        for (long superclassIndex = 0; superclassIndex <= depth; superclassIndex++) {
            J9ClassPointer superclass;
            if (superclassIndex == depth) {
                superclass = instanceClass;
            } else {
                superclass = J9ClassPointer.cast(instanceClass.superclasses().at(superclassIndex));
            }
            U32 flags = new U32(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE | J9VM_FIELD_OFFSET_WALK_INCLUDE_HIDDEN);
            Iterator<J9ObjectFieldOffset> iterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(superclass.romClass(), instanceClass, previousSuperclass, flags);
            while (iterator.hasNext()) {
                J9ObjectFieldOffset result = (J9ObjectFieldOffset) iterator.next();
                boolean printField = true;
                boolean isHiddenField = result.isHidden();
                if (J9BuildFlags.thr_lockNursery) {
                    boolean isLockword = (isHiddenField && (result.getOffsetOrAddress().add(J9Object.SIZEOF).eq(superclass.lockOffset())));
                    if (isLockword) {
                        /*
							 * Print the lockword field if it is indeed the
							 * lockword for this instanceClass and we haven't
							 * printed it yet.
							 */
                        printField = !lockwordPrinted && instanceClass.lockOffset().eq(superclass.lockOffset());
                        if (printField) {
                            lockwordPrinted = true;
                        }
                    }
                }
                if (printField) {
                    printShapeField(out, superclass, result.getField(), result.getOffsetOrAddress(), isHiddenField);
                }
            }
            previousSuperclass = superclass;
        }
        CommandUtils.dbgPrint(out, "\nTotal instance size: %d\n", instanceClass.totalInstanceSize().longValue());
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : U32(com.ibm.j9ddr.vm29.types.U32) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) PatternString(com.ibm.j9ddr.util.PatternString) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 69 with J9ClassPointer

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

the class ObjectRefsCommand method dumpHeapReferences.

/**
 * Write the on heap references stanza to the output stream.
 * @param vm
 * @param targetObject
 * @param out
 * @throws CorruptDataException
 */
private void dumpHeapReferences(J9JavaVMPointer vm, J9ObjectPointer targetObject, PrintStream out) throws CorruptDataException {
    if (GCExtensions.isVLHGC()) {
        Table table = new Table("On Heap References");
        table.row("object (!j9object)", "field (!j9object)", "!mm_heapregiondescriptorvlhgc", "AC (type)");
        /* iterate over all heap regions */
        GCHeapRegionIterator regionIterator = GCHeapRegionIterator.from();
        while (regionIterator.hasNext()) {
            GCHeapRegionDescriptor region = regionIterator.next();
            if (region.containsObjects()) {
                MM_HeapRegionDescriptorVLHGCPointer vlhgcRegion = MM_HeapRegionDescriptorVLHGCPointer.cast(region.getHeapRegionDescriptorPointer());
                MM_AllocationContextTarokPointer currentAllocationContextTarok = vlhgcRegion._allocateData()._owningContext();
                /* iterate over all objects in region */
                GCObjectHeapIterator heapObjectIterator = region.objectIterator(true, false);
                while (heapObjectIterator.hasNext()) {
                    J9ObjectPointer currentObject = heapObjectIterator.next();
                    /* Iterate over the object's fields and list any that point at @ref targetObject */
                    GCObjectIterator fieldIterator = GCObjectIterator.fromJ9Object(currentObject, false);
                    while (fieldIterator.hasNext()) {
                        J9ObjectPointer currentTargetObject = fieldIterator.next();
                        if (currentTargetObject.eq(targetObject)) {
                            /* found a reference to our targetObject, add it to the table */
                            J9ClassPointer objectClass = J9ObjectHelper.clazz(currentObject);
                            String objectClassString = J9ClassHelper.getJavaName(objectClass);
                            table.row(currentObject.getHexAddress() + " //" + objectClassString, currentTargetObject.getHexAddress(), vlhgcRegion.getHexAddress(), currentAllocationContextTarok.getHexAddress() + " (" + currentAllocationContextTarok._allocationContextType() + ")");
                        }
                    }
                }
            }
        }
        table.render(out);
    }
}
Also used : GCHeapRegionDescriptor(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor) Table(com.ibm.j9ddr.tools.ddrinteractive.Table) MM_HeapRegionDescriptorVLHGCPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_HeapRegionDescriptorVLHGCPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCHeapRegionIterator(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator) GCObjectHeapIterator(com.ibm.j9ddr.vm29.j9.gc.GCObjectHeapIterator) GCObjectIterator(com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator) MM_AllocationContextTarokPointer(com.ibm.j9ddr.vm29.pointer.generated.MM_AllocationContextTarokPointer) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 70 with J9ClassPointer

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

the class RootPathCommand method run.

public void run(String command, String[] args, Context context, final PrintStream out) throws DDRInteractiveCommandException {
    switch(args.length) {
        case 0:
            if (args.length == 0) {
                if (command.equals("!rootpathverbose")) {
                    out.println("verbose output enabled for rootpath command.  run !rootpathnoverbose to disable verbose output");
                    _verboseEnabled = true;
                } else if (command.equals("!rootpathnoverbose")) {
                    out.println("verbose output disabled for rootpath command.  run !rootpathverbose to enable verbose output");
                    _verboseEnabled = false;
                } else {
                    throw new UnsupportedOperationException("Unrecognized command passed to RoothPathCommand");
                }
            }
            break;
        case 1:
            long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
            final J9ObjectPointer objectToFind = J9ObjectPointer.cast(address);
            try {
                J9ClassPointer clazz = J9ObjectHelper.clazz(objectToFind);
                if (!J9ClassHelper.hasValidEyeCatcher(clazz)) {
                    throw new DDRInteractiveCommandException("object class is not valid (eyecatcher is not 0x99669966)");
                }
            } catch (CorruptDataException cde) {
                throw new DDRInteractiveCommandException("memory fault de-referencing address argument", cde);
            }
            try {
                /* Create a custom event listener so that CorruptDataExceptions that are found
				 * while iterating through the live set aren't all printed to the output stream
				 */
                RootPathCommandListener listener = new RootPathCommandListener();
                EventManager.register(listener);
                if (command.equals("!rootpathfindall") || command.equals("!strongrootpathfindall")) {
                    LiveSetWalker.walkLiveSet(new RootPathsFinder(objectToFind, out), RootSetType.STRONG_REACHABLE);
                } else if (command.equals("!anyrootpathfindall")) {
                    LiveSetWalker.walkLiveSet(new RootPathsFinder(objectToFind, out), RootSetType.ALL);
                } else if (command.equals("!weakrootpathfindall")) {
                    LiveSetWalker.walkLiveSet(new RootPathsFinder(objectToFind, out), RootSetType.WEAK_REACHABLE);
                } else if (command.equals("!rootpathfind") || command.equals("!strongrootpathfind")) {
                    RootPathFinder pathFinder = new RootPathFinder(objectToFind, out);
                    LiveSetWalker.walkLiveSet(pathFinder, RootSetType.STRONG_REACHABLE);
                    if (!pathFinder._pathFound) {
                        out.println("No paths from roots found");
                    }
                } else if (command.equals("!anyrootpathfind")) {
                    RootPathFinder pathFinder = new RootPathFinder(objectToFind, out);
                    LiveSetWalker.walkLiveSet(pathFinder, RootSetType.ALL);
                    if (!pathFinder._pathFound) {
                        out.println("No paths from roots found");
                    }
                } else if (command.equals("!weakrootpathfindall")) {
                    RootPathFinder pathFinder = new RootPathFinder(objectToFind, out);
                    LiveSetWalker.walkLiveSet(pathFinder, RootSetType.WEAK_REACHABLE);
                    if (!pathFinder._pathFound) {
                        out.println("No paths from roots found");
                    }
                } else if (command.equals("!isobjectalive")) {
                    ObjectFinderVisitor objectFinder = new ObjectFinderVisitor(objectToFind);
                    LiveSetWalker.walkLiveSet(objectFinder);
                    if (objectFinder._objectFound) {
                        out.println("Object is live");
                    } else {
                        out.println("Object is not live");
                    }
                }
                if (listener._corruptionFound) {
                    out.println("Corruption detected walking live set");
                    if (!_verboseEnabled) {
                        out.println("run !rootpathverbose and re-run command to see corruptions");
                    }
                }
                EventManager.unregister(listener);
            } catch (CorruptDataException cde) {
                throw new DDRInteractiveCommandException("Memory fault while walking live set", cde);
            }
            break;
        default:
            throw new DDRInteractiveCommandException("Invalid number of arguments");
    }
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Aggregations

J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)67 CorruptDataException (com.ibm.j9ddr.CorruptDataException)34 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)16 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)13 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)13 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)12 UDATA (com.ibm.j9ddr.vm29.types.UDATA)12 U32 (com.ibm.j9ddr.vm29.types.U32)11 J9MemorySegmentPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer)9 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)9 ClassSegmentIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator)8 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)8 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)7 NoSuchElementException (java.util.NoSuchElementException)7 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)6 J9ClassLoaderPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer)6 GCClassHeapIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassHeapIterator)5 GCSegmentIterator (com.ibm.j9ddr.vm29.j9.gc.GCSegmentIterator)5 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)5 J9ITablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ITablePointer)5