Search in sources :

Example 31 with J9ClassPointer

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

the class VmCheckCommand method checkJ9MethodSanity.

/*
	 *  Based on vmchk/checkmethods.c r1.5
	 * 
	 *	J9Method sanity:
	 *		Bytecode check:
	 *			Ensure (bytecodes - sizeof(J9ROMMethod) is in the right "area" to be a ROM Method.
	 *			Use ROMClass to determine where ROM methods for that class begin.
	 *		Constant pool check:
	 *			Ensure method's constant pool is the same as that of its J9Class.
	 *			Useful to validate that HCR doesn't violate this invariant.
	 *		VTable check:
	 *			If method of a non-interface class has modifier J9AccMethodVTable,
	 *			ensure it exists in the VTable of its J9Class.
	 *			Useful to validate that HCR doesn't violate this invariant.
	 */
private void checkJ9MethodSanity(J9JavaVMPointer vm, PrintStream out) throws CorruptDataException {
    reportMessage(out, "Checking methods");
    // Stolen from RootScaner.scanClasses()
    // GCClassLoaderIterator gcClassLoaderIterator =
    // GCClassLoaderIterator.from();
    GCSegmentIterator segmentIterator = GCSegmentIterator.fromJ9MemorySegmentList(vm.classMemorySegments(), J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
    int count = 0;
    while (segmentIterator.hasNext()) {
        J9MemorySegmentPointer segment = segmentIterator.next();
        GCClassHeapIterator classHeapIterator = GCClassHeapIterator.fromJ9MemorySegment(segment);
        while (classHeapIterator.hasNext()) {
            J9ClassPointer clazz = classHeapIterator.next();
            if (!J9ClassHelper.isObsolete(clazz)) {
                count += verifyClassMethods(vm, out, clazz);
            }
        }
    }
    reportMessage(out, "Checking %d methods done", count);
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) GCClassHeapIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassHeapIterator) GCSegmentIterator(com.ibm.j9ddr.vm29.j9.gc.GCSegmentIterator)

Example 32 with J9ClassPointer

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

the class CheckClassHeap method check.

@Override
public void check() {
    try {
        GCSegmentIterator segmentIterator = GCSegmentIterator.fromJ9MemorySegmentList(_javaVM.classMemorySegments(), J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
        while (segmentIterator.hasNext()) {
            J9MemorySegmentPointer segment = segmentIterator.next();
            _engine.clearPreviousObjects();
            GCClassHeapIterator classHeapIterator = GCClassHeapIterator.fromJ9MemorySegment(segment);
            while (classHeapIterator.hasNext()) {
                J9ClassPointer clazz = classHeapIterator.next();
                if (_engine.checkClassHeap(clazz, segment) != CheckBase.J9MODRON_SLOT_ITERATOR_OK) {
                    return;
                }
                _engine.pushPreviousClass(clazz);
            }
        }
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) GCClassHeapIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassHeapIterator) GCSegmentIterator(com.ibm.j9ddr.vm29.j9.gc.GCSegmentIterator)

Example 33 with J9ClassPointer

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

the class StackmapCommand method run.

/**
 *  Java representation of j9dbgext.c#dbgext_stackmap function.
 *
 *  @param  command DDR extension command of stackmap.
 *                  It is supposed to be "stackmap" if this method is being called.
 *  @param  args    Arguments passed to !stackmap DDR extension.
 *                  Only one argument is expected since !stackmap expects only the address.
 *  @param  context Current context that DDR is running on.
 *  @param  out     Print stream to write the output.
 *
 *  @return void
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length != 1) {
        printUsage(out);
        return;
    }
    try {
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        if (null == vm) {
            out.println("vm can not be found.");
        }
        long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
        U8Pointer pc = U8Pointer.cast(address);
        CommandUtils.dbgPrint(out, "Searching for PC=%d in VM=%s...\n", pc.longValue(), vm.getHexAddress());
        J9MethodPointer remoteMethod = J9JavaVMHelper.getMethodFromPC(vm, pc);
        if (remoteMethod.notNull()) {
            int[] stackMap = new int[MAX_STACKSLOTS_COUNT / INT_SIZE_IN_BITS];
            int leftMostBitIntMask = 1 << (INT_SIZE_IN_BITS - 1);
            CommandUtils.dbgPrint(out, "Found method %s !j9method %s\n", J9MethodHelper.getName(remoteMethod), remoteMethod.getHexAddress());
            UDATA offsetPC = new UDATA(pc.sub(U8Pointer.cast(remoteMethod.bytecodes())));
            CommandUtils.dbgPrint(out, "Relative PC = %d\n", offsetPC.longValue());
            J9ClassPointer localClass = J9_CLASS_FROM_CP(remoteMethod.constantPool());
            long methodIndex = new UDATA(remoteMethod.sub(localClass.ramMethods())).longValue();
            CommandUtils.dbgPrint(out, "Method index is %d\n", methodIndex);
            J9ROMMethodPointer localROMMethod = J9ROMCLASS_ROMMETHODS(localClass.romClass());
            while (methodIndex != 0) {
                localROMMethod = ROMHelp.nextROMMethod(localROMMethod);
                --methodIndex;
            }
            CommandUtils.dbgPrint(out, "Using ROM method %s\n", localROMMethod.getHexAddress());
            /*
				 * This call will return the depth of the stack or errorcode in case of a failure.
				 */
            int errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, null, 0);
            if (0 > errorCode) {
                CommandUtils.dbgPrint(out, "Stack map failed, error code = %d\n", errorCode);
            } else {
                int stackMapIndex = 0;
                if (0 != errorCode) {
                    /* This call to j9stackmap_StackBitsForPC will fill the stackMap */
                    errorCode = StackMap.j9stackmap_StackBitsForPC(offsetPC, localClass.romClass(), localROMMethod, stackMap, errorCode);
                    int currentDescription = stackMap[stackMapIndex];
                    int descriptionInt = 0;
                    CommandUtils.dbgPrint(out, "Stack map (%d slots mapped): ", errorCode);
                    long bitsRemaining = errorCode % INT_SIZE_IN_BITS;
                    if (bitsRemaining != 0) {
                        descriptionInt = currentDescription << (INT_SIZE_IN_BITS - bitsRemaining);
                        currentDescription++;
                    }
                    while (errorCode != 0) {
                        if (bitsRemaining == 0) {
                            descriptionInt = currentDescription;
                            currentDescription = stackMap[++stackMapIndex];
                            bitsRemaining = INT_SIZE_IN_BITS;
                        }
                        CommandUtils.dbgPrint(out, "%d", (descriptionInt & (leftMostBitIntMask)) != 0 ? 1 : 0);
                        descriptionInt = descriptionInt << 1;
                        --bitsRemaining;
                        --errorCode;
                    }
                    CommandUtils.dbgPrint(out, "\n");
                } else {
                    CommandUtils.dbgPrint(out, "Stack is empty\n");
                }
            }
        } else {
            CommandUtils.dbgPrint(out, "Not found\n");
        }
    } catch (CorruptDataException e) {
    }
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 34 with J9ClassPointer

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

the class VmCheckCommand method verifyObsoleteJ9Class.

private boolean verifyObsoleteJ9Class(J9JavaVMPointer javaVM, PrintStream out, J9ClassPointer classPointer) throws CorruptDataException {
    boolean passed = true;
    J9ClassPointer replacedClass;
    J9ClassPointer currentClass = J9ClassHelper.currentClass(classPointer);
    verifyJ9ClassHeader(javaVM, out, currentClass);
    replacedClass = currentClass.replacedClass();
    while (!replacedClass.isNull()) {
        if (replacedClass.eq(classPointer)) {
            /* Expected case: found classPointer in the list. */
            break;
        }
        replacedClass = replacedClass.replacedClass();
    }
    if (replacedClass.isNull()) {
        reportError(out, "obsolete class=0x%s is not in replaced list on currentClass=0x%s", Long.toHexString(classPointer.getAddress()), Long.toHexString(currentClass.getAddress()));
        passed = false;
    }
    return passed;
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)

Example 35 with J9ClassPointer

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

the class CheckEngine method checkJ9Class.

private int checkJ9Class(J9ClassPointer clazz, J9MemorySegmentPointer segment, int checkFlags) throws CorruptDataException {
    if (clazz.isNull()) {
        return J9MODRON_GCCHK_RC_OK;
    }
    if (clazz.anyBitsIn(J9MODRON_GCCHK_J9CLASS_ALIGNMENT_MASK)) {
        return J9MODRON_GCCHK_RC_CLASS_POINTER_UNALIGNED;
    }
    /* Check that the class header containes the expected values */
    int ret = checkJ9ClassHeader(clazz);
    if (J9MODRON_GCCHK_RC_OK != ret) {
        return ret;
    }
    /* Check that class is not unloaded */
    ret = checkJ9ClassIsNotUnloaded(clazz);
    if (J9MODRON_GCCHK_RC_OK != ret) {
        return ret;
    }
    if ((checkFlags & J9MODRON_GCCHK_VERIFY_RANGE) != J9MODRON_GCCHK_VERIFY_RANGE) {
        UDATA delta = UDATA.cast(segment.heapAlloc()).sub(UDATA.cast(clazz));
        /* Basic check that there is enough room for the object header */
        if (delta.lt(J9Class.SIZEOF)) {
            return J9MODRON_GCCHK_RC_CLASS_INVALID_RANGE;
        }
    }
    return J9MODRON_GCCHK_RC_OK;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA)

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