Search in sources :

Example 1 with J9ClassRegion

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion in project openj9 by eclipse.

the class LinearDumper method addSlot.

public void addSlot(StructurePointer clazz, SlotType type, AbstractPointer slotPtr, String slotName, String additionalInfo) throws CorruptDataException {
    try {
        J9ROMNameAndSignaturePointer nas;
        long offset;
        /* The slots of the type J9_ROM_UTF8 are changed to have 2 slots:
			 * -J9_SRP_TO_STRING
			 * -J9_ROM_UTF8
			 * This is done because we want to print the SRP field and also print
			 * the UTF8 it is pointing to */
        switch(type) {
            case J9_ROM_UTF8:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, SlotType.J9_SRP_TO_STRING, slotName, additionalInfo, type.getSize(), offset, true));
                VoidPointer srp = SelfRelativePointer.cast(slotPtr).get();
                addUTF8Region(clazz, slotName, additionalInfo, srp);
                break;
            case J9_UTF8:
                addUTF8Region(clazz, slotName, additionalInfo, slotPtr);
                break;
            /* The fields of the type J9_SRPNAS or J9_SRP are changed to have 2 J9_ROM_UTF8
				 * fields for their name and signature separated. */
            case J9_SRPNAS:
                nas = J9ROMNameAndSignaturePointer.cast(SelfRelativePointer.cast(slotPtr).get());
                if (nas.notNull()) {
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                }
                /* Since it is a SRP to a NAS, also print the SRP field. */
                addSlot(clazz, SlotType.J9_SRP, slotPtr, "cpFieldNAS");
                break;
            case J9_NAS:
                nas = J9ROMNameAndSignaturePointer.cast(slotPtr);
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                break;
            case J9_IntermediateClassData:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, ((J9ROMClassPointer) clazz).intermediateClassDataLength().longValue(), offset, true));
                break;
            default:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, type.getSize(), offset, true));
                break;
        }
    } catch (Exception e) {
    }
}
Also used : J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 2 with J9ClassRegion

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion in project openj9 by eclipse.

the class LinearDumper method getAllRegions.

/**
 * Returns a tree of regions and slots. Each slot is under a region. The
 * root element is always null.
 * @param classWalker
 *
 * @return J9ClassRegionNode tree of J9ClassRegion
 * @throws CorruptDataException
 */
public J9ClassRegionNode getAllRegions(ClassWalker classWalker) throws CorruptDataException {
    classWalker.allSlotsInObjectDo(this);
    final StructurePointer clazz = classWalker.getClazz();
    /* Add the UTF8 region */
    if (firstJ9_ROM_UTF8 != Long.MAX_VALUE) {
        addSection(clazz, PointerPointer.cast(firstJ9_ROM_UTF8), lastJ9_ROM_UTF8 - firstJ9_ROM_UTF8, "UTF8", true);
    }
    groupSectionByName(clazz, "methodDebugInfo", false);
    groupSectionByName(clazz, "variableInfo", false);
    /*
		 * the offset is a pointer which points at the end of the current
		 * region, in the case of a region which have no real size, it points at
		 * the beginning of the region
		 */
    AbstractPointer offset = PointerPointer.NULL;
    J9ClassRegionNode currentNode = new J9ClassRegionNode(null);
    Stack<J9ClassRegionNode> parentStack = new Stack<J9ClassRegionNode>();
    J9ClassRegion previousRegion = null;
    Collections.sort(classRegions);
    for (J9ClassRegion region : classRegions) {
        if (isSameRegion(previousRegion, region)) {
            previousRegion = region;
            continue;
        }
        previousRegion = region;
        if (SlotType.J9_SECTION_START == region.getType()) {
            if (region.getComputePadding() && offset.notNull() && !offset.eq(region.getSlotPtr())) {
                currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
            }
            if (region.getComputePadding()) {
                offset = region.getSlotPtr();
            }
            parentStack.push(currentNode);
            J9ClassRegionNode newChild = new J9ClassRegionNode(region);
            currentNode.addChild(newChild);
            currentNode = newChild;
        } else if (SlotType.J9_SECTION_END == region.getType()) {
            if (region.getComputePadding()) {
                long paddingSize = (region.getSlotPtr().getAddress() - offset.getAddress());
                if (paddingSize != 0) {
                    currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
                }
                offset = region.getSlotPtr();
            }
            currentNode = parentStack.pop();
        } else {
            boolean computePadding = false;
            if (currentNode.getNodeValue() != null) {
                computePadding = currentNode.getNodeValue().getComputePadding();
            }
            if (computePadding && offset.notNull() && !offset.eq(region.getSlotPtr())) {
                currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
            }
            if (computePadding) {
                offset = region.getSlotPtr().addOffset(region.length);
            }
            currentNode.addChild(new J9ClassRegionNode(region));
        }
    }
    // Padding after the class and inside the romSize.
    if (clazz instanceof J9ROMClassPointer) {
        long size = J9ROMClassPointer.cast(clazz).romSize().longValue();
        long paddingSize = (clazz.longValue() + size) - offset.longValue();
        if (paddingSize != 0) {
            currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
            // The class padding might be inserted out of order
            Collections.sort(currentNode.getChildren());
        }
    }
    return currentNode;
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) StructurePointer(com.ibm.j9ddr.vm29.pointer.StructurePointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) Stack(java.util.Stack)

Example 3 with J9ClassRegion

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion in project openj9 by eclipse.

the class LinearDumper method groupSectionByName.

/**
 * Find the first and the last section and group them in another section with the same name ending with a "s".
 * For example, it will group all of the methodDebugInfo in a section named methodDebugInfos
 * It is important to note that the function does not check if the sections grouped are contiguous, it will
 * group all sections between the first and the last section even if their names doesn't match.
 *
 * @param clazz
 * @param name name of sections to group
 * @param computePadding
 * @throws CorruptDataException
 */
private void groupSectionByName(final StructurePointer clazz, String name, boolean computePadding) throws CorruptDataException {
    AbstractPointer firstMethodDebugInfo = null;
    AbstractPointer lastMethodDebugInfo = null;
    for (J9ClassRegion region : classRegions) {
        if (SlotType.J9_SECTION_START == region.getType() && region.getName().equals(name)) {
            if (firstMethodDebugInfo == null || region.getSlotPtr().lt(firstMethodDebugInfo)) {
                firstMethodDebugInfo = region.getSlotPtr();
            }
            if (lastMethodDebugInfo == null || region.getSlotPtr().add(region.getLength()).gt(lastMethodDebugInfo)) {
                lastMethodDebugInfo = region.getSlotPtr().addOffset(region.getLength());
            }
        }
    }
    if (firstMethodDebugInfo != null && lastMethodDebugInfo != null) {
        UDATA length = UDATA.cast(lastMethodDebugInfo).sub(UDATA.cast(firstMethodDebugInfo));
        addSection(clazz, PointerPointer.cast(firstMethodDebugInfo), length.longValue(), name + "s", computePadding);
    }
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Example 4 with J9ClassRegion

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion in project openj9 by eclipse.

the class LinearDumper method getRegionDetailString.

private static Object getRegionDetailString(J9ClassRegion region) throws CorruptDataException {
    VoidPointer srp;
    long slotAddress;
    String returnValue = "";
    switch(region.getType()) {
        case J9_SECTION_START:
            returnValue = String.format(" %5d bytes", region.getLength());
            break;
        case J9_RAM_UTF8:
            UDATAPointer slotPtr = UDATAPointer.cast(region.getSlotPtr());
            if (slotPtr.at(0).longValue() != 0) {
                returnValue = J9ObjectHelper.stringValue(J9ObjectPointer.cast(slotPtr.at(0)));
            }
            break;
        case J9_UTF8:
        case J9_ROM_UTF8:
            returnValue = J9UTF8Helper.stringValue(J9UTF8Pointer.cast(region.getSlotPtr()));
            break;
        case J9_iTableMethod:
            /*
			 * This case is special for the iTableMethod, because their pointers
			 * are related to the beginning of the class and are not absolute
			 */
            AbstractPointer classOffset = region.getSlotPtr().subOffset(region.offset);
            slotAddress = region.getSlotPtr().at(0).longValue();
            classOffset = classOffset.addOffset(slotAddress);
            returnValue = region.additionalInfo + " " + classOffset.getHexAddress();
            break;
        case J9_SRP:
            srp = SelfRelativePointer.cast(region.getSlotPtr()).get();
            if (srp.notNull()) {
                returnValue = " -> " + srp.getHexAddress();
            }
            break;
        case J9_WSRP:
            srp = WideSelfRelativePointer.cast(region.getSlotPtr()).get();
            if (srp.notNull()) {
                returnValue = " -> " + srp.getHexAddress();
            }
            break;
        case J9_SRP_TO_STRING:
            srp = SelfRelativePointer.cast(region.getSlotPtr()).get();
            if (srp.notNull()) {
                returnValue = " -> " + srp.getHexAddress();
                returnValue += " " + J9UTF8Helper.stringValue(J9UTF8Pointer.cast(srp));
            }
            break;
        case J9_Padding:
            returnValue = region.length + " byte(s)";
            break;
        case J9_IntermediateClassData:
            returnValue = region.length + " byte(s) " + region.additionalInfo;
            break;
        default:
            String detail = "";
            slotAddress = region.getSlotPtr().at(0).longValue();
            long slotAddressOriginal = slotAddress;
            if ((null != region.additionalInfo) && (region.additionalInfo.length() != 0)) {
                if ("classAndFlags".equals(region.name) && (UDATA.MASK != slotAddress)) {
                    slotAddress = slotAddress & ~J9JavaAccessFlags.J9StaticFieldRefFlagBits;
                }
                detail += region.additionalInfo + (String.format(" 0x%08X", slotAddress));
                /* For special debug extension, more information is shown */
                if ((0 != slotAddress) && (region.additionalInfo.equals("!j9class"))) {
                    try {
                        detail += " - " + J9UTF8Helper.stringValue(J9ClassPointer.cast(slotAddress).romClass().className());
                        if ("classAndFlags".equals(region.name)) {
                            String flags = "";
                            if (0 != (J9JavaAccessFlags.J9StaticFieldRefBaseType & slotAddressOriginal)) {
                                flags += "J9StaticFieldRefBaseType, ";
                            }
                            if (0 != (J9JavaAccessFlags.J9StaticFieldRefDouble & slotAddressOriginal)) {
                                flags += "J9StaticFieldRefDouble, ";
                            }
                            if (0 != (J9JavaAccessFlags.J9StaticFieldRefVolatile & slotAddressOriginal)) {
                                flags += "J9StaticFieldRefVolatile, ";
                            }
                            /* Check there is any flag or not */
                            if (0 < flags.length()) {
                                /*remove last two chars = ", " */
                                flags = flags.substring(0, flags.length() - 2);
                                detail += "\t Flag(s) = " + flags;
                            }
                        }
                    } catch (Exception e) {
                    /* This is only for information purpose, it is ok if an exception was thrown */
                    }
                }
            }
            returnValue = detail;
    }
    return returnValue;
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) UDATAPointer(com.ibm.j9ddr.vm29.pointer.UDATAPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 5 with J9ClassRegion

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion in project openj9 by eclipse.

the class ClassSummaryHelper method appendSizeStat.

private void appendSizeStat(Map<String, Long> sizeStat, J9ClassRegionNode regionNode, String parentName) {
    String section = parentName;
    final J9ClassRegion nodeValue = regionNode.getNodeValue();
    if (nodeValue != null) {
        if (nodeValue.getType() == SlotType.J9_SECTION_START || nodeValue.getType() == SlotType.J9_Padding) {
            section = section + "/" + nodeValue.getName();
            if (sizeStat.containsKey(section)) {
                sizeStat.put(section, new Long(sizeStat.get(section) + nodeValue.getLength()));
            } else {
                sizeStat.put(section, new Long(nodeValue.getLength()));
            }
        }
    }
    for (J9ClassRegionNode classRegionNode : regionNode.getChildren()) {
        appendSizeStat(sizeStat, classRegionNode, section);
    }
}
Also used : J9ClassRegionNode(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode) J9ClassRegion(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion)

Aggregations

AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)3 CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)2 StructurePointer (com.ibm.j9ddr.vm29.pointer.StructurePointer)1 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)1 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)1 J9ROMNameAndSignaturePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer)1 J9ClassRegion (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion)1 J9ClassRegionNode (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode)1 UDATA (com.ibm.j9ddr.vm29.types.UDATA)1 Stack (java.util.Stack)1