Search in sources :

Example 6 with J9IndexableObjectPointer

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

the class J9ObjectHelper method stringValue.

public static String stringValue(J9ObjectPointer objPointer) throws CorruptDataException {
    if (!J9ObjectHelper.getClassName(objPointer).equals("java/lang/String")) {
        throw new IllegalArgumentException();
    }
    // No synchronization needed here because the type of java/lang/String.value is immutable
    if (isStringBackedByByteArray == null) {
        try {
            getObjectField(objPointer, getFieldOffset(objPointer, "value", "[B"));
            isStringBackedByByteArray = new Boolean(true);
        } catch (NoSuchElementException e) {
            getObjectField(objPointer, getFieldOffset(objPointer, "value", "[C"));
            isStringBackedByByteArray = new Boolean(false);
        }
    }
    J9ObjectPointer valueObject = isStringBackedByByteArray.booleanValue() ? getObjectField(objPointer, getFieldOffset(objPointer, "value", "[B")) : getObjectField(objPointer, getFieldOffset(objPointer, "value", "[C"));
    if (valueObject.isNull()) {
        return "<Uninitialized String>";
    }
    int offset = 0;
    int count = getIntField(objPointer, getFieldOffset(objPointer, "count", "I"));
    boolean isStringCompressed = false;
    AlgorithmVersion version = AlgorithmVersion.getVersionOf(AlgorithmVersion.STRING_COMPRESSION_VERSION);
    switch(version.getAlgorithmVersion()) {
        case 1:
            boolean enableCompression = getBooleanField(objPointer, getFieldOffset(objPointer, "enableCompression", "Z"));
            if (enableCompression) {
                if (count >= 0) {
                    isStringCompressed = true;
                } else {
                    count = count & 0x7FFFFFFF;
                }
            }
            break;
        default:
            offset = getIntField(objPointer, getFieldOffset(objPointer, "offset", "I"));
            break;
    }
    char[] charValue = new char[count];
    J9IndexableObjectPointer valueArray = J9IndexableObjectPointer.cast(valueObject);
    if (isStringBackedByByteArray.booleanValue()) {
        byte[] value = (byte[]) J9IndexableObjectHelper.getData(valueArray);
        if (isStringCompressed) {
            for (int i = 0; i < count; ++i) {
                charValue[i] = byteToCharUnsigned(getByteFromArrayByIndex(value, i));
            }
        } else {
            for (int i = 0; i < count; ++i) {
                charValue[i] = getCharFromArrayByIndex(value, i);
            }
        }
    } else {
        char[] value = (char[]) J9IndexableObjectHelper.getData(valueArray);
        if (isStringCompressed) {
            for (int i = 0; i < count; ++i) {
                charValue[i] = byteToCharUnsigned(getByteFromArrayByIndex(value, i));
            }
        } else {
            for (int i = 0; i < count; ++i) {
                charValue[i] = getCharFromArrayByIndex(value, i);
            }
        }
    }
    return new String(charValue, offset, count);
}
Also used : AlgorithmVersion(com.ibm.j9ddr.vm29.j9.AlgorithmVersion) NoSuchElementException(java.util.NoSuchElementException)

Example 7 with J9IndexableObjectPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer 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)

Example 8 with J9IndexableObjectPointer

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

the class DTFJJavaObject method arraycopy.

public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
    fetchDeferredData();
    if (!objectIsArray) {
        throw new IllegalArgumentException("Object is not an array");
    }
    J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
    try {
        validateArrayCopyParameters(array, srcStart, dst, dstStart, length);
        // CMVC 171150 : use helper object to correctly get the class name
        String className = J9IndexableObjectHelper.getClassName(array);
        if ((null == className) || (className.length() < 2)) {
            J9DDRCorruptData cd = new J9DDRCorruptData(DTFJContext.getProcess(), "The class name for this object could not be determined", object.getAddress());
            throw new CorruptDataException(cd);
        }
        if (className.charAt(1) == 'L' || className.charAt(1) == '[') {
            // JExtract/DTFJ can cope with dst of either Object[] or JavaObject[] - but we need to detect other things
            if (!dst.getClass().equals(Object[].class) && !(dst instanceof JavaObject[])) {
                throw new IllegalArgumentException("Type of dst object (" + dst.getClass().getName() + ") incompatible with Object array. Should be JavaObject[] or Object[]");
            }
            J9ObjectPointer[] intermediateArray = new J9ObjectPointer[length];
            Object[] castedDst = (Object[]) dst;
            if (dstStart + (long) length > castedDst.length) {
                throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + (dstStart + (long) length) + ", was " + castedDst.length);
            }
            J9IndexableObjectHelper.getData(array, intermediateArray, srcStart, length, 0);
            for (int i = 0; i < length; i++) {
                if (intermediateArray[i].isNull()) {
                    castedDst[dstStart + i] = null;
                } else {
                    castedDst[dstStart + i] = new DTFJJavaObject(intermediateArray[i]);
                }
            }
        } else {
            // For primitives we can pass through the client object. The type verification will be done in J9IndexableObjectPointer
            J9IndexableObjectHelper.getData(array, dst, srcStart, length, dstStart);
        }
    } catch (Throwable t) {
        throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
    }
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) J9IndexableObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object) CorruptJavaObject(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)

Example 9 with J9IndexableObjectPointer

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

the class J9ObjectStructureFormatter method printSubArrayType.

void printSubArrayType(PrintStream out, int tabLevel, J9ClassPointer localClazz, U8Pointer dataStart, int begin, int end, J9IndexableObjectPointer array) throws CorruptDataException {
    U32 arraySize = J9IndexableObjectHelper.size(array);
    if (arraySize.anyBitsIn(0x80000000)) {
        arraySize = new U32(Integer.MAX_VALUE);
    }
    int finish = Math.min(arraySize.intValue(), end);
    if (begin < finish) {
        String className = J9IndexableObjectHelper.getClassName(array);
        char signature = className.charAt(1);
        switch(signature) {
            case 'B':
            case 'Z':
                for (int index = begin; index < finish; index++) {
                    padding(out, tabLevel);
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, 1);
                    out.println(String.format("[%d] = %3d, 0x%02x", index, U8Pointer.cast(slot).at(0).longValue(), U8Pointer.cast(slot).at(0).longValue()));
                }
                break;
            case 'C':
                for (int index = begin; index < finish; index++) {
                    padding(out, tabLevel);
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, 2);
                    long value = U16Pointer.cast(slot).at(0).longValue();
                    out.println(String.format("[%d] = %5d, 0x%2$04x, '%c'", index, value, (char) value));
                }
                break;
            case 'S':
                for (int index = begin; index < finish; index++) {
                    padding(out, tabLevel);
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, 2);
                    out.println(String.format("[%d] = %6d, 0x%04x", index, I16Pointer.cast(slot).at(0).longValue(), U16Pointer.cast(slot).at(0).longValue()));
                }
                break;
            case 'I':
            case 'F':
                for (int index = begin; index < finish; index++) {
                    padding(out, tabLevel);
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, 4);
                    out.println(String.format("[%d] = %10d, 0x%08x, %8.8fF", index, I32Pointer.cast(slot).at(0).longValue(), U32Pointer.cast(slot).at(0).longValue(), FloatPointer.cast(slot).floatAt(0)));
                }
                break;
            case 'J':
            case 'D':
                for (int index = begin; index < finish; index++) {
                    padding(out, tabLevel);
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, 8);
                    out.println(String.format("[%d] = %2d, 0x%016x, %8.8fF", index, I64Pointer.cast(slot).at(0).longValue(), I64Pointer.cast(slot).at(0).longValue(), DoublePointer.cast(slot).doubleAt(0)));
                }
                break;
            case 'L':
            case '[':
                for (int index = begin; index < finish; index++) {
                    VoidPointer slot = J9IndexableObjectHelper.getElementEA(array, index, (int) ObjectReferencePointer.SIZEOF);
                    if (slot.notNull()) {
                        long compressedPtrValue;
                        if (J9BuildFlags.gc_compressedPointers) {
                            compressedPtrValue = I32Pointer.cast(slot).at(0).longValue();
                        } else {
                            compressedPtrValue = DataType.getProcess().getPointerAt(slot.getAddress());
                        }
                        padding(out, tabLevel);
                        out.println(String.format("[%d] = !fj9object 0x%x = !j9object 0x%x", index, compressedPtrValue, ObjectReferencePointer.cast(slot).at(0).longValue()));
                    } else {
                        padding(out, tabLevel);
                        out.println(String.format("[%d] = null", slot));
                    }
                }
                break;
        }
    }
    /* check if it just printed a range; if so, give cmd to see all data */
    arraySize = J9IndexableObjectHelper.size(array);
    if (begin > 0 || arraySize.longValue() > finish) {
        out.println(String.format("To print entire range: !j9indexableobject %s %d %d\n", array.getHexAddress(), 0, arraySize.longValue()));
    }
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) U32(com.ibm.j9ddr.vm29.types.U32)

Example 10 with J9IndexableObjectPointer

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

the class J9ObjectStructureFormatter method formatArrayObject.

private void formatArrayObject(PrintStream out, J9ClassPointer localClazz, U8Pointer dataStart, J9IndexableObjectPointer localObject, int begin, int end) throws CorruptDataException {
    String className = J9IndexableObjectHelper.getClassName(localObject);
    out.print(String.format("!J9IndexableObject %s {", localObject.getHexAddress()));
    out.println();
    /* print individual fields */
    out.println(String.format("    struct J9Class* clazz = !j9arrayclass 0x%X   // %s", localClazz.getAddress(), className));
    out.println(String.format("    Object flags = %s;", J9IndexableObjectHelper.flags(localObject).getHexValue()));
    U32 size = J9IndexableObjectHelper.size(localObject);
    if (!J9BuildFlags.thr_lockNursery) {
        out.println(String.format("    j9objectmonitor_t monitor = %s;", J9IndexableObjectHelper.monitor(localObject).getHexValue()));
    }
    if (size.anyBitsIn(0x80000000)) {
        out.println(String.format("    U_32 size = %s; // Size exceeds Integer.MAX_VALUE!", size.getHexValue()));
    } else {
        out.println(String.format("    U_32 size = %s;", size.getHexValue()));
    }
    printSubArrayType(out, 1, localClazz, dataStart, begin, end, localObject);
    out.println("}");
}
Also used : U32(com.ibm.j9ddr.vm29.types.U32)

Aggregations

UDATA (com.ibm.j9ddr.vm29.types.UDATA)9 U32 (com.ibm.j9ddr.vm29.types.U32)4 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)3 J9ArrayClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ArrayClassPointer)3 J9IndexableObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9IndexableObjectPointer)2 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)2 NoSuchElementException (java.util.NoSuchElementException)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 CorruptDataException (com.ibm.j9ddr.CorruptDataException)1 InvalidDataTypeException (com.ibm.j9ddr.InvalidDataTypeException)1 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 AlgorithmVersion (com.ibm.j9ddr.vm29.j9.AlgorithmVersion)1 GCScavengerForwardedHeader (com.ibm.j9ddr.vm29.j9.gc.GCScavengerForwardedHeader)1 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)1 ObjectReferencePointer (com.ibm.j9ddr.vm29.pointer.ObjectReferencePointer)1 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)1 J9ROMArrayClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMArrayClassPointer)1 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)1 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)1