Search in sources :

Example 16 with Pointer

use of com.ibm.j9ddr.vm29.pointer.Pointer 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 17 with Pointer

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

the class CheckEngine method findRegionForPointer.

private GCHeapRegionDescriptor findRegionForPointer(AbstractPointer pointer, GCHeapRegionDescriptor region) {
    GCHeapRegionDescriptor regionDesc = null;
    if (region != null && region.isAddressInRegion(pointer)) {
        return region;
    }
    regionDesc = regionForAddress(pointer);
    if (null != regionDesc) {
        return regionDesc;
    }
    // TODO kmt : this is tragically slow
    try {
        GCHeapRegionIterator iterator = GCHeapRegionIterator.from();
        while (iterator.hasNext()) {
            regionDesc = GCHeapRegionDescriptor.fromHeapRegionDescriptor(iterator.next());
            if (isPointerInRegion(pointer, regionDesc)) {
                return regionDesc;
            }
        }
    } catch (CorruptDataException e) {
    }
    return null;
}
Also used : GCHeapRegionDescriptor(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor) GCHeapRegionIterator(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 18 with Pointer

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

the class DTFJJavaRuntime method validHeapAddress.

/*
	 * Quickly check if an object address is within a memory range that we
	 * know is part of the heap.
	 * (Heap sections are usually contiguous so we can merge them down to
	 * just a few ranges. This is important in balanced mode where there
	 * may be thousands. See See PR 103197)
	 */
private boolean validHeapAddress(ImagePointer address) {
    if (mergedHeapSections == null) {
        mergeSections();
    }
    U64 addr = new U64(address.getAddress());
    for (ImageSection i : mergedHeapSections) {
        U64 baseAddress = new U64(i.getBaseAddress().getAddress());
        if (baseAddress.gt(addr)) {
            // found the pointer in a heap.
            return false;
        }
        U64 endAddress = new U64(i.getBaseAddress().getAddress() + i.getSize());
        if (endAddress.gt(addr)) {
            return true;
        }
    }
    return false;
}
Also used : U64(com.ibm.j9ddr.vm29.types.U64) ImageSection(com.ibm.dtfj.image.ImageSection) J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)

Example 19 with Pointer

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

the class JITLook method hash_jit_artifact_search.

public static J9JITExceptionTablePointer hash_jit_artifact_search(J9JITHashTablePointer table, UDATA searchValue) throws CorruptDataException {
    PointerPointer bucket;
    J9JITExceptionTablePointer entry;
    if (searchValue.gte(table.start()) && searchValue.lt(table.end())) {
        /* The search value is in this hash table */
        bucket = DETERMINE_BUCKET(searchValue, table.start(), table.buckets());
        if (bucket.at(0).notNull()) {
            /* The bucket for this search value is not empty */
            if (bucket.at(0).allBitsIn(1)) {
                // LOW_BIT_SET
                /* The bucket consists of a single low-tagged J9JITExceptionTable pointer */
                entry = J9JITExceptionTablePointer.cast(bucket.at(0));
            } else {
                /* The bucket consists of an array of J9JITExceptionTable pointers,
					 * the last of which is low-tagged */
                /* Search all but the last entry in the array */
                bucket = PointerPointer.cast(bucket.at(0));
                for (; ; bucket = bucket.add(1)) {
                    entry = J9JITExceptionTablePointer.cast(bucket.at(0));
                    if (entry.allBitsIn(1)) {
                        break;
                    }
                    if (searchValue.gte(entry.startPC()) && searchValue.lt(entry.endWarmPC()))
                        return entry;
                    if ((entry.startColdPC().longValue() != 0) && searchValue.gte(entry.startColdPC()) && searchValue.lt(entry.endPC()))
                        return entry;
                }
            }
            /* Search the last (or only) entry in the bucket, which is low-tagged */
            entry = J9JITExceptionTablePointer.cast(UDATA.cast(entry).bitAnd(new UDATA(1).bitNot()));
            if (searchValue.gte(entry.startPC()) && searchValue.lt(entry.endWarmPC()))
                return entry;
            if ((entry.startColdPC().longValue() != 0) && searchValue.gte(entry.startColdPC()) && searchValue.lt(entry.endPC()))
                return entry;
        }
    }
    return J9JITExceptionTablePointer.NULL;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9JITExceptionTablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9JITExceptionTablePointer)

Example 20 with Pointer

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

the class J9JavaVMHelper method getMethodFromPC.

/*
	 * Returns a program space pointer to the matching J9Method for the
	 * specified PC.
	 */
public static J9MethodPointer getMethodFromPC(J9JavaVMPointer vmPtr, U8Pointer pc) throws CorruptDataException {
    GCClassLoaderIterator it = GCClassLoaderIterator.from();
    while (it.hasNext()) {
        J9ClassLoaderPointer loader = it.next();
        Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
        while (classIt.hasNext()) {
            J9ClassPointer clazz = classIt.next();
            J9MethodPointer result = J9ClassHelper.getMethodFromPCAndClass(clazz, pc);
            if (!result.isNull()) {
                return result;
            }
        }
    }
    return J9MethodPointer.NULL;
}
Also used : J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer)

Aggregations

CorruptDataException (com.ibm.j9ddr.CorruptDataException)14 UDATA (com.ibm.j9ddr.vm29.types.UDATA)14 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)6 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)5 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)4 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)4 GCHeapRegionDescriptor (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor)3 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)3 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)2 StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)2 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 J9DDRImageSection (com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)2 GCClassLoaderIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)2 GCHeapRegionIterator (com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator)2 GCScavengerForwardedHeader (com.ibm.j9ddr.vm29.j9.gc.GCScavengerForwardedHeader)2 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)2 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)2 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)2