Search in sources :

Example 1 with J9ClassRegionNode

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode 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 2 with J9ClassRegionNode

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

the class RomClassSummaryCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        boolean requiredLocal = false;
        boolean requiredShared = false;
        boolean required16bitnas = false;
        J9SharedClassConfigPointer sc = J9SharedClassConfigPointer.NULL;
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        long startAddress = 0, endAddress = 0;
        if ((args != null) && (args.length >= 1)) {
            if (args[0].equals("shared")) {
                requiredShared = true;
            } else if (args[0].equals("local")) {
                requiredLocal = true;
            } else if (args[0].equals("16bitnas")) {
                required16bitnas = true;
            } else {
                out.println("USAGE: !romclasssummary [local|shared] [16bitnas]");
                return;
            }
            if ((args.length >= 2) && (args[1].equals("16bitnas"))) {
                required16bitnas = true;
            }
            if (requiredShared || requiredLocal) {
                sc = vm.sharedClassConfig();
                if (requiredShared && sc.isNull()) {
                    out.println("The request for '" + args[0] + " classes' failed, because " + "shared classes were not enabled on that dump file.");
                    return;
                }
                if (sc.notNull()) {
                    startAddress = UDATA.cast(sc.cacheDescriptorList().romclassStartAddress()).longValue();
                    J9SharedCacheHeaderPointer header = sc.cacheDescriptorList().cacheStartAddress();
                    endAddress = UDATA.cast(header).add(header.segmentSRP()).longValue();
                }
            }
        }
        ClassSummaryHelper classSummaryHelper = new ClassSummaryHelper(preferredOrder);
        Statistics statistics = new Statistics();
        ROMClassesIterator classSegmentIterator = new ROMClassesIterator(out, vm.classMemorySegments());
        while (classSegmentIterator.hasNext()) {
            J9ROMClassPointer classPointer = (J9ROMClassPointer) classSegmentIterator.next();
            if (requiredShared || requiredLocal) {
                boolean isShared;
                if (sc.notNull()) {
                    long classAddress = classPointer.getAddress();
                    isShared = classAddress >= startAddress && classAddress < endAddress;
                } else {
                    isShared = false;
                }
                if (requiredShared && !isShared)
                    continue;
                if (requiredLocal && isShared)
                    continue;
            }
            ClassWalker classWalker = new RomClassWalker(classPointer, context);
            LinearDumper linearDumper = new LinearDumper();
            J9ClassRegionNode allRegionsNode = linearDumper.getAllRegions(classWalker);
            classSummaryHelper.addRegionsForClass(allRegionsNode);
            if (required16bitnas) {
                statistics.add(allRegionsNode);
            }
        }
        classSummaryHelper.printStatistics(out);
        if (statistics.nameAndSignatureSRP16bitSize != -1) {
            out.println();
            out.println("<Total 16bit nameAndSignatureSRPs Size>");
            out.println(statistics.nameAndSignatureSRP16bitSize);
        }
        if (statistics.nameAndSignatureSRPCount != -1 && statistics.cpFieldNASCount != -1) {
            out.println();
            out.println("<Shared nameAndSignatureSRPs>");
            // nameAndSignatureSRPCount is divided by 2, because there is a name and a signature per NAS field
            out.println(statistics.cpFieldNASCount - statistics.nameAndSignatureSRPCount / 2);
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9SharedClassConfigPointer(com.ibm.j9ddr.vm29.pointer.generated.J9SharedClassConfigPointer) ROMClassesIterator(com.ibm.j9ddr.vm29.j9.walkers.ROMClassesIterator) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9SharedCacheHeaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9SharedCacheHeaderPointer) RomClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RomClassWalker) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ClassRegionNode(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode) LinearDumper(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) ClassSummaryHelper(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassSummaryHelper) ClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker) RomClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RomClassWalker)

Example 3 with J9ClassRegionNode

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

the class QueryRomClassCommand method queryROMClass.

private void queryROMClass(PrintStream out, J9ROMClassPointer romClass, String query, J9ClassRegionNode allRegionsNode) throws CorruptDataException {
    /* /methods/method[3]/methodBytecodes */
    String[] parts = query.split("/");
    for (String part : parts) {
        if (part.length() != 0) {
            String sectionName;
            int index;
            if (part.endsWith("]")) {
                Pattern p = Pattern.compile("^(.*)\\[(\\d*)\\]");
                Matcher m = p.matcher(part);
                m.find();
                sectionName = m.group(1).trim();
                index = Integer.parseInt(m.group(2).trim());
            } else {
                sectionName = part;
                index = 0;
            }
            final List<J9ClassRegionNode> children = allRegionsNode.getChildren();
            if (children.size() <= index) {
                out.println("Error: section not found or bad formatting");
                printUsage(out);
                return;
            }
            for (J9ClassRegionNode classRegionNode : children) {
                if (classRegionNode.getNodeValue() != null) {
                    if (classRegionNode.getNodeValue().getName().equals(sectionName)) {
                        if (index-- == 0) {
                            allRegionsNode = classRegionNode;
                            continue;
                        }
                    }
                }
            }
        }
    }
    CommandUtils.dbgPrint(out, String.format("ROM Class '%s' at %s:\n\n", J9UTF8Helper.stringValue(romClass.className()), romClass.getHexAddress()));
    LinearDumper.printAllRegions(out, romClass, 9, allRegionsNode, 0);
}
Also used : Pattern(java.util.regex.Pattern) J9ClassRegionNode(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode) Matcher(java.util.regex.Matcher)

Example 4 with J9ClassRegionNode

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

the class RamClassSummaryCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        ClassSummaryHelper classSummaryHelper = new ClassSummaryHelper(preferredOrder);
        ClassSegmentIterator classSegmentIterator = new ClassSegmentIterator(vm.classMemorySegments());
        while (classSegmentIterator.hasNext()) {
            J9ClassPointer classPointer = (J9ClassPointer) classSegmentIterator.next();
            numberOfClasses++;
            ClassWalker classWalker = new RamClassWalker(classPointer, context);
            LinearDumper linearDumper = new LinearDumper();
            J9ClassRegionNode allRegionsNode = linearDumper.getAllRegions(classWalker);
            classSummaryHelper.addRegionsForClass(allRegionsNode);
        }
        classSummaryHelper.printStatistics(out);
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : ClassSegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator) J9ClassRegionNode(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) LinearDumper(com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) ClassSummaryHelper(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassSummaryHelper) ClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker) RamClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RamClassWalker) RamClassWalker(com.ibm.j9ddr.vm29.tools.ddrinteractive.RamClassWalker) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 5 with J9ClassRegionNode

use of com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode 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

J9ClassRegionNode (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode)6 CorruptDataException (com.ibm.j9ddr.CorruptDataException)4 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)4 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)4 ClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker)4 LinearDumper (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper)4 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)3 RomClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.RomClassWalker)3 ROMClassesIterator (com.ibm.j9ddr.vm29.j9.walkers.ROMClassesIterator)2 ClassSummaryHelper (com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassSummaryHelper)2 ClassSegmentIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator)1 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)1 StructurePointer (com.ibm.j9ddr.vm29.pointer.StructurePointer)1 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)1 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)1 J9SharedCacheHeaderPointer (com.ibm.j9ddr.vm29.pointer.generated.J9SharedCacheHeaderPointer)1 J9SharedClassConfigPointer (com.ibm.j9ddr.vm29.pointer.generated.J9SharedClassConfigPointer)1 J9ClassRegion (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegion)1 RamClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.RamClassWalker)1 ParseException (java.text.ParseException)1