Search in sources :

Example 26 with J9ROMClassPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer 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 27 with J9ROMClassPointer

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

the class VmCheckCommand method verifyJ9ClassHeader.

private boolean verifyJ9ClassHeader(J9JavaVMPointer javaVM, PrintStream out, J9ClassPointer classPointer) throws CorruptDataException {
    boolean passed = true;
    J9ROMClassPointer romClass = classPointer.romClass();
    String rootClasses = "java.lang.Object";
    if (false == J9ClassHelper.hasValidEyeCatcher(classPointer)) {
        reportError(out, "0x99669966 != eyecatcher (0x%s) for class=0x%s", Long.toHexString(classPointer.eyecatcher().longValue()), Long.toHexString(classPointer.getAddress()));
        passed = false;
    }
    if (romClass.isNull()) {
        reportError(out, "NULL == romClass for class=0x%s", Long.toHexString(classPointer.getAddress()));
        passed = false;
    }
    if (classPointer.classLoader().isNull()) {
        reportError(out, "NULL == classLoader for class=0x%s", Long.toHexString(classPointer.getAddress()));
        passed = false;
    }
    long classDepth = J9ClassHelper.classDepth(classPointer).longValue();
    if (classDepth > 0) {
        if (classPointer.superclasses().isNull()) {
            reportError(out, "NULL == superclasses for non-" + rootClasses + " class=0x%s", Long.toHexString(classPointer.getAddress()));
            passed = false;
        } else {
            // Verify that all entries of superclasses[] are non-null.
            for (long i = 0; i < classDepth; i++) {
                if (classPointer.superclasses().at(i).isNull()) {
                    reportError(out, "superclasses[%d] is NULL for class=0x%s", Long.toHexString(classPointer.getAddress()));
                    passed = false;
                    break;
                }
            }
        }
    } else {
        if (classPointer.superclasses().at(-1).notNull()) {
            reportError(out, "superclasses[-1] should be NULL for class=0x%s", Long.toHexString(classPointer.getAddress()));
            passed = false;
        }
    }
    if (classPointer.initializeStatus().eq(J9ClassInitFlags.J9ClassInitSucceeded)) {
        if (classPointer.classObject().isNull()) {
            reportError(out, "NULL == class->classObject for initialized class=0x%s", Long.toHexString(classPointer.getAddress()));
            passed = false;
        }
    }
    if (J9ClassHelper.isObsolete(classPointer)) {
        reportError(out, "clazz=0x%s is obsolete", Long.toHexString(classPointer.getAddress()));
        passed = false;
    }
    if (!romClass.isNull() && !romClass.romConstantPoolCount().eq(0)) {
        J9ConstantPoolPointer constantPool = J9ConstantPoolPointer.cast(classPointer.ramConstantPool());
        J9ClassPointer cpClass = constantPool.ramClass();
        if (!classPointer.eq(cpClass)) {
            reportError(out, "clazz=0x%s not equal clazz->ramConstantPool->ramClass=0x%s", Long.toHexString(classPointer.getAddress()), Long.toHexString(cpClass.getAddress()));
            passed = false;
        }
    }
    return passed;
}
Also used : J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ConstantPoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ConstantPoolPointer)

Example 28 with J9ROMClassPointer

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

the class VmCheckCommand method findSegmentInClassLoaderForAddress.

/**
 * Based on vmchk/checkclasses.c function: findSegmentInClassLoaderForAddress
 *
 * This method searches classloader's segments to find out on which segment this ROMClass lays in.
 * @param classLoader Classloader that romclass is being searched
 * @param romClassPointer ROMClass that is searched in classloader segments
 * @return Classloader segment which has this romclass, otherwise null.
 * @throws CorruptDataException
 */
public J9MemorySegmentPointer findSegmentInClassLoaderForAddress(J9ClassLoaderPointer classLoader, J9ROMClassPointer romClassPointer) throws CorruptDataException {
    MemorySegmentIterator memorySegmentIterator = new MemorySegmentIterator(classLoader.classSegments(), MemorySegmentIterator.MEMORY_ALL_TYPES, true);
    J9MemorySegmentPointer memorySegmentPointer = J9MemorySegmentPointer.NULL;
    J9MemorySegmentPointer foundMemorySegmentPointer = J9MemorySegmentPointer.NULL;
    while (memorySegmentIterator.hasNext()) {
        Object next2 = memorySegmentIterator.next();
        memorySegmentPointer = (J9MemorySegmentPointer) next2;
        if (romClassPointer.getAddress() >= memorySegmentPointer.heapBase().longValue() && romClassPointer.getAddress() < memorySegmentPointer.heapAlloc().longValue()) {
            foundMemorySegmentPointer = memorySegmentPointer;
            break;
        }
    }
    return foundMemorySegmentPointer;
}
Also used : J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) MemorySegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.MemorySegmentIterator)

Example 29 with J9ROMClassPointer

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

the class VmCheckCommand method verifyJ9ROMClass.

private void verifyJ9ROMClass(PrintStream out, J9JavaVMPointer vm, J9ClassPointer clazz) throws CorruptDataException {
    J9ROMClassPointer romClass = clazz.romClass();
    J9ClassLoaderPointer classLoader = clazz.classLoader();
    J9MemorySegmentPointer segment = findSegmentInClassLoaderForAddress(classLoader, romClass);
    if (!segment.isNull()) {
        long address;
        if (romClass.interfaceCount().longValue() != 0) {
            address = romClass.interfaces().getAddress();
            verifyAddressInSegment(out, vm, segment, address, "romClass->interfaces");
        }
        if (romClass.romMethodCount().longValue() != 0) {
            address = romClass.romMethods().longValue();
            verifyAddressInSegment(out, vm, segment, address, "romClass->romMethods");
        }
        if (romClass.romFieldCount().longValue() != 0) {
            address = romClass.romFields().longValue();
            verifyAddressInSegment(out, vm, segment, address, "romClass->romFields");
        }
        if (romClass.innerClassCount().longValue() != 0) {
            address = romClass.innerClasses().longValue();
            verifyAddressInSegment(out, vm, segment, address, "romClass->innerClasses");
        }
        U32Pointer cpShapeDescription = romClass.cpShapeDescription();
        /* TODO: is !isNull() check required or not? */
        if (!cpShapeDescription.isNull()) {
            address = cpShapeDescription.getAddress();
            verifyAddressInSegment(out, vm, segment, address, "romClass->cpShapeDescription");
        }
    }
    {
        J9UTF8Pointer className = romClass.className();
        J9UTF8Pointer superclassName = romClass.superclassName();
        J9UTF8Pointer outerClassName = romClass.outerClassName();
        if (className.isNull() || !verifyUTF8(className)) {
            reportError(out, "invalid className=0x%s utf8 for romClass=0x%s", Long.toHexString(className.getAddress()), Long.toHexString(romClass.getAddress()));
        }
        if (!superclassName.isNull() && !verifyUTF8(superclassName)) {
            reportError(out, "invalid superclassName=0x%s utf8 for romClass=0x%s", Long.toHexString(superclassName.getAddress()), Long.toHexString(romClass.getAddress()));
        }
        if (!outerClassName.isNull() && !verifyUTF8(outerClassName)) {
            reportError(out, "invalid outerclassName=0x%s utf8 for romClass=0x%s", Long.toHexString(outerClassName.getAddress()), Long.toHexString(romClass.getAddress()));
        }
    }
    U32 ramConstantPoolCount = romClass.ramConstantPoolCount();
    U32 romConstantPoolCount = romClass.romConstantPoolCount();
    if (ramConstantPoolCount.gt(romConstantPoolCount)) {
        reportError(out, "ramConstantPoolCount=%d > romConstantPoolCount=%d for romClass=0x%s", ramConstantPoolCount.longValue(), romConstantPoolCount.longValue(), Long.toHexString(romClass.getAddress()));
    }
}
Also used : U32(com.ibm.j9ddr.vm29.types.U32) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) J9UTF8Pointer(com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer) U32Pointer(com.ibm.j9ddr.vm29.pointer.U32Pointer)

Example 30 with J9ROMClassPointer

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

the class ROMClassesIterator method next.

public J9ROMClassPointer next() {
    ClassAndSegment classAndSegment = getNextClass();
    J9ROMClassPointer clazz = classAndSegment.getClassPointer();
    if (clazz != J9ROMClassPointer.NULL) {
        nextClass = clazz;
        nextSegment = classAndSegment.getSegmentPointer();
    } else {
        throw new NoSuchElementException();
    }
    return nextClass;
}
Also used : J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)27 CorruptDataException (com.ibm.j9ddr.CorruptDataException)16 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)11 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)9 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)8 U32 (com.ibm.j9ddr.vm29.types.U32)8 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)7 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)7 J9ROMNameAndSignaturePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer)6 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)6 ROMClassesIterator (com.ibm.j9ddr.vm29.j9.walkers.ROMClassesIterator)5 J9ROMConstantPoolItemPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer)5 ClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.ClassWalker)5 LinearDumper (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper)5 RomClassWalker (com.ibm.j9ddr.vm29.tools.ddrinteractive.RomClassWalker)5 PatternString (com.ibm.j9ddr.util.PatternString)4 SelfRelativePointer (com.ibm.j9ddr.vm29.pointer.SelfRelativePointer)4 U16Pointer (com.ibm.j9ddr.vm29.pointer.U16Pointer)4 J9ConstantPoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ConstantPoolPointer)4 J9ClassRegionNode (com.ibm.j9ddr.vm29.tools.ddrinteractive.LinearDumper.J9ClassRegionNode)4