Search in sources :

Example 36 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class VmCheckCommand method verifyUTF8.

private boolean verifyUTF8(J9UTF8Pointer utf8) throws CorruptDataException {
    if (utf8.isNull()) {
        return false;
    }
    UDATA length = new UDATA(utf8.length());
    U8Pointer utf8Data = utf8.dataEA();
    while (length.longValue() > 0) {
        // not used
        U16 temp = new U16(0);
        U32 lengthRead = decodeUTF8CharN(utf8Data, temp, length);
        if (lengthRead.eq(0)) {
            return false;
        }
        length = length.sub(lengthRead);
        utf8Data = utf8Data.addOffset(lengthRead);
    }
    return true;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) U32(com.ibm.j9ddr.vm29.types.U32) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) U16(com.ibm.j9ddr.vm29.types.U16)

Example 37 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class ShowDumpAgentsCommand method seekDumpAgent.

private J9RASdumpAgentPointer seekDumpAgent(J9JavaVMPointer vm, J9RASdumpAgentPointer agentPtr, J9RASdumpFunctionsPointer dumpFn) throws CorruptDataException {
    J9RASdumpFunctionsPointer func = vm.j9rasDumpFunctions();
    J9RASdumpQueuePointer queue = J9RASdumpQueuePointer.cast(func);
    // Windows 64 bit returns a key of 0xFFFFFFFFFACADEDC
    // Other 64 bit platforms return 0x00000000FACADEDC.
    // Mask off the top bits since the key is 32 bits anyway.
    UDATA reserved = UDATA.roundToSizeofU32(UDATA.cast(queue.facade().reserved()));
    reserved = reserved.bitAnd(0x00000000FFFFFFFFl);
    if (!DUMP_FACADE_KEY.equals(reserved)) {
        // Dump functions have not been configured. (-Xdump:none was probably specified.)#
        return null;
    }
    /*
		 * Sanity check
		 */
    if (!queue.isNull()) {
        J9RASdumpAgentPointer node = agentPtr;
        /* Start from next agent, else start from the beginning */
        node = (node != null && !node.isNull()) ? node.nextPtr() : queue.agents();
        /* Agents with same dumpFn will be found in priority order */
        while (node != null && !node.isNull() && dumpFn != null && !dumpFn.isNull() && node.dumpFn().getAddress() != dumpFn.getAddress()) {
            node = node.nextPtr();
        }
        /* Update the current position */
        agentPtr = node;
        return node;
    }
    /* Blank current position */
    agentPtr = J9RASdumpAgentPointer.NULL;
    return agentPtr;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9RASdumpAgentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RASdumpAgentPointer) J9RASdumpFunctionsPointer(com.ibm.j9ddr.vm29.pointer.generated.J9RASdumpFunctionsPointer) J9RASdumpQueuePointer(com.ibm.j9ddr.vm29.pointer.generated.J9RASdumpQueuePointer)

Example 38 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA 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 39 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class VmCheckCommand method decodeUTF8CharN.

/**
 * Decode the UTF8 character.
 *
 * Decode the input UTF8 character and stores it into result.
 *
 * @param[in] input The UTF8 character
 * @param[out] result buffer for unicode characters
 * @param[in] bytesRemaining number of bytes remaining in input
 *
 * @return The number of UTF8 characters consumed (1,2,3) on success, 0 on
 *         failure
 * @throws CorruptDataException
 * @note Don't read more than bytesRemaining characters.
 * @note If morecharacters are required to fully decode the character,
 *       return failure
 */
U32 decodeUTF8CharN(U8Pointer input, /**
 * not used *
 */
U16 result, UDATA bytesRemaining) throws CorruptDataException {
    U8 c;
    U8Pointer cursor = input;
    if (bytesRemaining.longValue() < 1) {
        return new U32(0);
    }
    c = cursor.at(0);
    cursor = cursor.add(1);
    if (c.eq(0x0)) {
        /* illegal NUL encoding */
        return new U32(0);
    } else if ((c.bitAnd(0x80)).eq(0x0)) {
        // *result = (U_16)c;
        return new U32(1);
    } else if (c.bitAnd(0xE0).eq(0xC0)) {
        /* two byte encoding */
        U16 unicodeC;
        if (bytesRemaining.lt(2)) {
            return new U32(0);
        }
        unicodeC = new U16(c.bitAnd(0x1F).leftShift(6));
        c = cursor.at(0);
        cursor = cursor.add(1);
        unicodeC = unicodeC.add(new U16(unicodeC.add(c.bitAnd(0x3F))));
        if (!c.bitAnd(0xC0).eq(0x80)) {
            return new U32(0);
        }
        // *result = unicodeC;
        return new U32(2);
    } else if (c.bitAnd(0xF0).eq(0xE0)) {
        /* three byte encoding */
        U16 unicodeC;
        if (bytesRemaining.lt(3)) {
            return new U32(0);
        }
        unicodeC = new U16(c.bitAnd(0x0F).leftShift(12));
        c = cursor.at(0);
        cursor = cursor.add(1);
        unicodeC = unicodeC.add(new U16(c.bitAnd(0x3F).leftShift(6)));
        if (!c.bitAnd(0xC0).eq(0x80)) {
            return new U32(0);
        }
        c = cursor.at(0);
        cursor = cursor.add(1);
        unicodeC = unicodeC.add(new U16(c.bitAnd(0x3F)));
        if (!c.bitAnd(0xC0).eq(0x80)) {
            return new U32(0);
        }
        // *result = unicodeC;
        return new U32(3);
    } else {
        return new U32(0);
    }
}
Also used : U8(com.ibm.j9ddr.vm29.types.U8) U32(com.ibm.j9ddr.vm29.types.U32) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer) U16(com.ibm.j9ddr.vm29.types.U16)

Example 40 with UDATA

use of com.ibm.j9ddr.vm29.types.UDATA in project openj9 by eclipse.

the class CheckEngine method checkJ9ObjectPointer.

private int checkJ9ObjectPointer(J9ObjectPointer object, J9ObjectPointer[] newObject, GCHeapRegionDescriptor[] regionDesc) throws CorruptDataException {
    newObject[0] = object;
    if (object.isNull()) {
        return J9MODRON_GCCHK_RC_OK;
    }
    regionDesc[0] = findRegionForPointer(object, regionDesc[0]);
    if (regionDesc[0] == null) {
        /* Is the object on the stack? */
        GCVMThreadListIterator threadListIterator = GCVMThreadListIterator.from();
        while (threadListIterator.hasNext()) {
            J9VMThreadPointer vmThread = threadListIterator.next();
            if (isObjectOnStack(object, vmThread.stackObject())) {
                return J9MODRON_GCCHK_RC_STACK_OBJECT;
            }
        }
        UDATA classSlot = UDATA.cast(object.clazz());
        if (classSlot.eq(J9MODRON_GCCHK_J9CLASS_EYECATCHER)) {
            return J9MODRON_GCCHK_RC_OBJECT_SLOT_POINTS_TO_J9CLASS;
        }
        return J9MODRON_GCCHK_RC_NOT_FOUND;
    }
    // if (0 == regionDesc->objectAlignment) {
    if (!regionDesc[0].containsObjects()) {
        /* this is a heap region, but it's not intended for objects (could be free or an arraylet leaf) */
        return J9MODRON_GCCHK_RC_NOT_IN_OBJECT_REGION;
    }
    /* Now we know object is not on stack we can check that it's correctly aligned
		 * for a J9Object.
		 */
    if (object.anyBitsIn(J9MODRON_GCCHK_J9OBJECT_ALIGNMENT_MASK)) {
        return J9MODRON_GCCHK_RC_UNALIGNED;
    }
    if (isMidscavengeFlagSet()) {
        if (GCExtensions.isVLHGC() || (regionDesc[0].getTypeFlags().allBitsIn(MEMORY_TYPE_NEW))) {
            // TODO: ideally, we should only check this in the evacuate segment
            // TODO: do some safety checks first -- is there enough room in the segment?
            GCScavengerForwardedHeader scavengerForwardedHeader = GCScavengerForwardedHeader.fromJ9Object(object);
            if (scavengerForwardedHeader.isForwardedPointer()) {
                newObject[0] = scavengerForwardedHeader.getForwardedObject();
                reportForwardedObject(object, newObject[0]);
                // Replace the object and resume
                object = newObject[0];
                regionDesc[0] = findRegionForPointer(object, regionDesc[0]);
                if (regionDesc[0] == null) {
                    /* Is the object on the stack? */
                    GCVMThreadListIterator threadListIterator = GCVMThreadListIterator.from();
                    while (threadListIterator.hasNext()) {
                        J9VMThreadPointer vmThread = threadListIterator.next();
                        if (isObjectOnStack(object, vmThread.stackObject())) {
                            return J9MODRON_GCCHK_RC_STACK_OBJECT;
                        }
                    }
                    return J9MODRON_GCCHK_RC_NOT_FOUND;
                }
                // if (0 == regionDesc->objectAlignment) {
                if (!regionDesc[0].containsObjects()) {
                    /* this is a heap region, but it's not intended for objects (could be free or an arraylet leaf) */
                    return J9MODRON_GCCHK_RC_NOT_IN_OBJECT_REGION;
                }
                /* make sure the forwarded pointer is also aligned */
                if (object.anyBitsIn(J9MODRON_GCCHK_J9OBJECT_ALIGNMENT_MASK)) {
                    return J9MODRON_GCCHK_RC_UNALIGNED;
                }
            }
        }
    }
    if (isScavengerBackoutFlagSet()) {
        GCScavengerForwardedHeader scavengerForwardedHeader = GCScavengerForwardedHeader.fromJ9Object(object);
        if (scavengerForwardedHeader.isReverseForwardedPointer()) {
            newObject[0] = scavengerForwardedHeader.getReverseForwardedPointer();
            reportForwardedObject(object, newObject[0]);
            // Replace the object and resume
            object = newObject[0];
            regionDesc[0] = findRegionForPointer(object, regionDesc[0]);
            if (regionDesc[0] == null) {
                return J9MODRON_GCCHK_RC_NOT_FOUND;
            }
            if (!regionDesc[0].containsObjects()) {
                /* this is a heap region, but it's not intended for objects (could be free or an arraylet leaf) */
                return J9MODRON_GCCHK_RC_NOT_IN_OBJECT_REGION;
            }
            if (!regionDesc[0].getTypeFlags().allBitsIn(MEMORY_TYPE_NEW)) {
                /* reversed forwarded should point to Evacuate */
                return J9MODRON_GCCHK_RC_REVERSED_FORWARDED_OUTSIDE_EVACUATE;
            }
            /* make sure the forwarded pointer is also aligned */
            if (object.anyBitsIn(J9MODRON_GCCHK_J9OBJECT_ALIGNMENT_MASK)) {
                return J9MODRON_GCCHK_RC_UNALIGNED;
            }
        }
    }
    /* Check that elements of a double array are aligned on an 8-byte boundary.  For continuous
		 * arrays, verifying that the J9Indexable object is aligned on an 8-byte boundary is sufficient.
		 * For arraylets, depending on the layout, elements of the array may be stored on arraylet leafs
		 * or on the spine.  Arraylet leafs should always be aligned on 8-byte boundaries.  Checking both 
		 * the first and last element will ensure that we are always checking that elements are aligned 
		 * on the spine.
		 *  */
    long classShape = -1;
    try {
        classShape = ObjectModel.getClassShape(J9ObjectHelper.clazz(object)).longValue();
    } catch (CorruptDataException cde) {
    /* don't bother to report an error yet -- a later step will catch this. */
    }
    if (classShape == OBJECT_HEADER_SHAPE_DOUBLES) {
        J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
        int size = 0;
        VoidPointer elementPtr = VoidPointer.NULL;
        try {
            size = ObjectModel.getSizeInElements(object).intValue();
        } catch (InvalidDataTypeException ex) {
        // size in elements can not be larger then 2G but it is...
        // We could report an error at this point, but the C version
        // doesn't -- we'll catch it later
        } catch (IllegalArgumentException ex) {
        // We could report an error at this point, but the C version
        // doesn't -- we'll catch it later
        }
        if (0 != size) {
            elementPtr = ObjectModel.getElementAddress(array, 0, U64.SIZEOF);
            if (elementPtr.anyBitsIn(U64.SIZEOF - 1)) {
                return J9MODRON_GCCHK_RC_DOUBLE_ARRAY_UNALIGNED;
            }
            elementPtr = ObjectModel.getElementAddress(array, size - 1, U64.SIZEOF);
            if (elementPtr.anyBitsIn(U64.SIZEOF - 1)) {
                return J9MODRON_GCCHK_RC_DOUBLE_ARRAY_UNALIGNED;
            }
        }
    }
    return J9MODRON_GCCHK_RC_OK;
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) UDATA(com.ibm.j9ddr.vm29.types.UDATA) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9IndexableObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) GCScavengerForwardedHeader(com.ibm.j9ddr.vm29.j9.gc.GCScavengerForwardedHeader) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvalidDataTypeException(com.ibm.j9ddr.InvalidDataTypeException)

Aggregations

UDATA (com.ibm.j9ddr.vm29.types.UDATA)86 CorruptDataException (com.ibm.j9ddr.CorruptDataException)22 U32 (com.ibm.j9ddr.vm29.types.U32)16 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)14 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)10 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)10 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)9 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)8 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)8 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)7 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)6 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)5 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)4 U16 (com.ibm.j9ddr.vm29.types.U16)4 J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)3 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)3 J9ArrayClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ArrayClassPointer)3 J9JITExceptionTablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9JITExceptionTablePointer)3 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)3 IDATA (com.ibm.j9ddr.vm29.types.IDATA)3