Search in sources :

Example 86 with UDATA

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

the class CheckEngine method checkClassStatics.

private int checkClassStatics(J9ClassPointer clazz) {
    int result = J9MODRON_GCCHK_RC_OK;
    try {
        boolean validationRequired = true;
        if (J9ClassHelper.isSwappedOut(clazz)) {
            /* if class has been hot swapped (J9AccClassHotSwappedOut bit is set) in Fast HCR,
				 * the ramStatics of the existing class may be reused.  The J9ClassReusedStatics
				 * bit in J9Class->extendedClassFlags will be set if that's the case.
				 * In Extended HCR mode ramStatics might be not NULL and must be valid
				 * NOTE: If class is hot swapped and the value in ramStatics is NULL it is valid 
				 * to have the correspondent ROM Class value in objectStaticCount field greater then 0
				 */
            if (J9ClassHelper.isArrayClass(clazz)) {
                /* j9arrayclass should not be hot swapped */
                result = J9MODRON_GCCHK_RC_CLASS_HOT_SWAPPED_FOR_ARRAY;
                CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                _reporter.report(error);
                return result;
            }
            if (J9ClassHelper.areExtensionsEnabled()) {
                /* This is Extended HSR mode so hot swapped class might have NULL in ramStatics field */
                if (clazz.ramStatics().isNull()) {
                    validationRequired = false;
                }
            }
            try {
                /* This case can also occur when running -Xint with extensions enabled */
                if (J9ClassHelper.extendedClassFlags(clazz).allBitsIn(J9JavaClassFlags.J9ClassReusedStatics)) {
                    validationRequired = false;
                }
            } catch (NoSuchFieldError e) {
            /* Flag must be missing from the core. */
            }
        }
        if (validationRequired) {
            // J9ClassLoaderPointer classLoader = clazz.classLoader();
            J9ROMClassPointer romClazz = clazz.romClass();
            UDATA numberOfReferences = new UDATA(0);
            PointerPointer sectionStart = PointerPointer.NULL;
            PointerPointer sectionEnd = PointerPointer.NULL;
            /*
				 * Note: we have no special recognition for J9ArrayClass here
				 * J9ArrayClass does not have a ramStatics field but something else at this place
				 * so direct check (NULL != clazz->ramStatics) would not be correct,
				 * however romClazz->objectStaticCount must be 0 for this case
				 */
            if (!romClazz.objectStaticCount().eq(0)) {
                sectionStart = PointerPointer.cast(clazz.ramStatics());
                sectionEnd = sectionStart.add(romClazz.objectStaticCount());
            }
            /* Iterate all fields of ROM Class looking to statics fields pointed to java objects */
            Iterator<J9ObjectFieldOffset> objectFieldOffsetIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(clazz, J9ClassHelper.superclass(clazz), new U32(J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9VM_FIELD_OFFSET_WALK_ONLY_OBJECT_SLOTS));
            while (objectFieldOffsetIterator.hasNext()) {
                J9ObjectFieldOffset fieldOffset = objectFieldOffsetIterator.next();
                // J9ROMFieldShapePointer field = fieldOffset.getField();
                numberOfReferences = numberOfReferences.add(1);
                /* get address of next field */
                PointerPointer address = sectionStart.addOffset(fieldOffset.getOffsetOrAddress());
                /* an address must be in gc scan range */
                if (!(address.gte(sectionStart) && address.lt(sectionEnd))) {
                    result = J9MODRON_GCCHK_RC_CLASS_STATICS_REFERENCE_IS_NOT_IN_SCANNING_RANGE;
                    CheckError error = new CheckError(clazz, address, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                    _reporter.report(error);
                }
            /* check only if we have an object */
            // TODO kmt : can't easily implement this part of the check
            // J9Class* classToCast = vm->internalVMFunctions->internalFindClassUTF8(currentThread, toSearchString, toSearchLength, classLoader, J9_FINDCLASS_FLAG_EXISTING_ONLY);
            // if ((NULL == classToCast) || (0 == instanceOfOrCheckCast(J9GC_J9OBJECT_CLAZZ(*address), classToCast))) {
            // The issue is that we can't simply call "internalFindClassUTF8" in DDR.
            // We could guess at the behaviour of the ClassLoader, but that makes
            // distingushing a real problem from a weird ClassLoader delegation
            // model difficult.
            }
            if (!numberOfReferences.eq(romClazz.objectStaticCount())) {
                result = J9MODRON_GCCHK_RC_CLASS_STATICS_WRONG_NUMBER_OF_REFERENCES;
                CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                _reporter.report(error);
            }
        }
    } catch (CorruptDataException e) {
        // TODO : cde should be part of the error
        CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
        _reporter.report(error);
    }
    return result;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) U32(com.ibm.j9ddr.vm29.types.U32) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 87 with UDATA

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

the class CheckEngine method checkJ9Object.

/**
 * Verify the integrity of an object on the heap.
 * Checks various aspects of object integrity based on the checkFlags.
 *
 * @param objectPtr Pointer to the object
 * @param segment The segment containing the pointer
 * @param checkFlags Type/level of verification
 *
 * @return @ref GCCheckWalkStageErrorCodes
 * @throws CorruptDataException
 *
 * @see @ref checkFlags
 */
private int checkJ9Object(J9ObjectPointer object, GCHeapRegionDescriptor regionDesc, int checkFlags) throws CorruptDataException {
    if (object.isNull()) {
        return J9MODRON_GCCHK_RC_OK;
    }
    // if (0 == regionDesc->objectAlignment) {
    if (!regionDesc.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 (object.anyBitsIn(J9MODRON_GCCHK_J9OBJECT_ALIGNMENT_MASK)) {
        return J9MODRON_GCCHK_RC_UNALIGNED;
    }
    if ((checkFlags & J9MODRON_GCCHK_VERIFY_CLASS_SLOT) != 0) {
        /* Check that the class pointer points to the class heap, etc. */
        int ret = checkJ9ClassPointer(J9ObjectHelper.clazz(object), true);
        if (J9MODRON_GCCHK_RC_OK != ret) {
            return ret;
        }
    }
    if ((checkFlags & J9MODRON_GCCHK_VERIFY_RANGE) != 0) {
        UDATA regionEnd = UDATA.cast(regionDesc.getLowAddress()).add(regionDesc.getSize());
        long delta = regionEnd.sub(UDATA.cast(object)).longValue();
        /* Basic check that there is enough room for the object header */
        if (delta < J9Object.SIZEOF) {
            return J9MODRON_GCCHK_RC_INVALID_RANGE;
        }
        /* TODO: find out what the indexable header size should really be */
        if (ObjectModel.isIndexable(object) && (delta < J9IndexableObjectContiguous.SIZEOF)) {
            return J9MODRON_GCCHK_RC_INVALID_RANGE;
        }
        if (delta < ObjectModel.getSizeInBytesWithHeader(object).longValue()) {
            return J9MODRON_GCCHK_RC_INVALID_RANGE;
        }
        if (J9BuildFlags.gc_arraylets && !J9BuildFlags.gc_hybridArraylets) {
        // TODO kmt : more code here
        }
        if ((checkFlags & J9MODRON_GCCHK_VERIFY_FLAGS) != 0) {
            // TODO : fix this test
            if (!checkIndexableFlag(object)) {
                return J9MODRON_GCCHK_RC_INVALID_FLAGS;
            }
            if (GCExtensions.isStandardGC()) {
                UDATA regionFlags = regionDesc.getTypeFlags();
                if (regionFlags.allBitsIn(MEMORY_TYPE_OLD)) {
                    /* All objects in an old segment must have old bit set */
                    if (!ObjectModel.isOld(object)) {
                        return J9MODRON_GCCHK_RC_OLD_SEGMENT_INVALID_FLAGS;
                    }
                } else {
                    if (regionFlags.allBitsIn(MEMORY_TYPE_NEW)) {
                        /* Object in a new segment can't have old bit or remembered bit set */
                        if (ObjectModel.isOld(object)) {
                            return J9MODRON_GCCHK_RC_NEW_SEGMENT_INVALID_FLAGS;
                        }
                    }
                }
            }
        }
    }
    return J9MODRON_GCCHK_RC_OK;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Example 88 with UDATA

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

the class CheckEngine method checkSlotObjectHeap.

public int checkSlotObjectHeap(J9ObjectPointer object, ObjectReferencePointer objectIndirect, GCHeapRegionDescriptor regionDesc, J9ObjectPointer objectIndirectBase) {
    if (object.isNull()) {
        return J9MODRON_SLOT_ITERATOR_OK;
    }
    int result = checkObjectIndirect(object);
    /* might the heap include dark matter? If so, ignore most errors */
    if ((_cycle.getMiscFlags() & J9MODRON_GCCHK_MISC_DARKMATTER) != 0) {
        /* only report a subset of errors -- the rest are expected to be found in dark matter */
        switch(result) {
            case J9MODRON_GCCHK_RC_OK:
            case J9MODRON_GCCHK_RC_UNALIGNED:
            case J9MODRON_GCCHK_RC_STACK_OBJECT:
                break;
            /* These errors are unlikely, but not impossible to find in dark matter. 
			 * Leave them enabled because they can help find real corruption
			 */
            case J9MODRON_GCCHK_RC_NOT_FOUND:
                /* can happen due to contraction */
                break;
            /* other errors in possible dark matter are expected, so ignore them and don't 
			 * investigate this pointer any further 
			 */
            default:
                return J9MODRON_GCCHK_RC_OK;
        }
    }
    boolean isIndexable = false;
    boolean scavengerEnabled = false;
    try {
        isIndexable = ObjectModel.isIndexable(objectIndirectBase);
        scavengerEnabled = GCExtensions.scavengerEnabled();
    } catch (CorruptDataException e) {
        // TODO : cde should be part of the error
        CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
        _reporter.report(error);
        return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
    }
    if (J9MODRON_GCCHK_RC_OK != result) {
        String elementName = isIndexable ? "IObject " : "Object ";
        CheckError error = new CheckError(objectIndirectBase, objectIndirect, _cycle, _currentCheck, elementName, result, _cycle.nextErrorCount());
        _reporter.report(error);
        return J9MODRON_SLOT_ITERATOR_OK;
    }
    if (J9BuildFlags.gc_generational) {
        if (scavengerEnabled) {
            GCHeapRegionDescriptor objectRegion = findRegionForPointer(object, regionDesc);
            if (objectRegion == null) {
                /* should be impossible, since checkObjectIndirect() already verified that the object exists */
                return J9MODRON_GCCHK_RC_NOT_FOUND;
            }
            if (object.notNull()) {
                UDATA regionType;
                UDATA objectRegionType;
                boolean isRemembered;
                boolean isOld;
                try {
                    regionType = regionDesc.getTypeFlags();
                    objectRegionType = objectRegion.getTypeFlags();
                    isRemembered = ObjectModel.isRemembered(objectIndirectBase);
                    isOld = ObjectModel.isOld(object);
                } catch (CorruptDataException e) {
                    // TODO : cde should be part of the error
                    CheckError error = new CheckError(objectIndirectBase, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
                    _reporter.report(error);
                    return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
                }
                /* Old objects that point to new objects should have remembered bit ON */
                if (regionType.allBitsIn(MEMORY_TYPE_OLD) && objectRegionType.allBitsIn(MEMORY_TYPE_NEW) && !isRemembered) {
                    String elementName = isIndexable ? "IObject " : "Object ";
                    CheckError error = new CheckError(objectIndirectBase, objectIndirect, _cycle, _currentCheck, elementName, J9MODRON_GCCHK_RC_NEW_POINTER_NOT_REMEMBERED, _cycle.nextErrorCount());
                    _reporter.report(error);
                    return J9MODRON_SLOT_ITERATOR_OK;
                }
                /* Old objects that point to objects with old bit OFF should have remembered bit ON */
                if (regionType.allBitsIn(MEMORY_TYPE_OLD) && !isOld && !isRemembered) {
                    String elementName = isIndexable ? "IObject " : "Object ";
                    CheckError error = new CheckError(objectIndirectBase, objectIndirect, _cycle, _currentCheck, elementName, J9MODRON_GCCHK_RC_REMEMBERED_SET_OLD_OBJECT, _cycle.nextErrorCount());
                    _reporter.report(error);
                    return J9MODRON_SLOT_ITERATOR_OK;
                }
            }
        }
    }
    return J9MODRON_SLOT_ITERATOR_OK;
}
Also used : GCHeapRegionDescriptor(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor) UDATA(com.ibm.j9ddr.vm29.types.UDATA) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 89 with UDATA

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

the class CheckObjectHeap method check.

@Override
public void check() {
    // Use iterators directly
    try {
        GCHeapRegionIterator regions = GCHeapRegionIterator.from();
        boolean midScavenge = _engine.isMidscavengeFlagSet();
        boolean isVLHGC = GCExtensions.isVLHGC();
        while (regions.hasNext()) {
            GCHeapRegionDescriptor region = GCHeapRegionDescriptor.fromHeapRegionDescriptor(regions.next());
            boolean isRegionTypeNew = region.getTypeFlags().allBitsIn(MEMORY_TYPE_NEW);
            GCObjectHeapIterator heapIterator = region.objectIterator(true, true);
            while (heapIterator.hasNext()) {
                J9ObjectPointer object = heapIterator.peek();
                if (midScavenge && (isVLHGC || isRegionTypeNew)) {
                    GCScavengerForwardedHeader scavengerForwardedHeader = GCScavengerForwardedHeader.fromJ9Object(object);
                    if (scavengerForwardedHeader.isForwardedPointer()) {
                        // forwarded pointer is discovered
                        // report it
                        _engine.reportForwardedObject(object, scavengerForwardedHeader.getForwardedObject());
                        // and skip it by advancing of iterator to the next object
                        UDATA objectSize = scavengerForwardedHeader.getObjectSize();
                        heapIterator.advance(objectSize);
                        _engine.pushPreviousObject(object);
                        continue;
                    }
                }
                int result = _engine.checkObjectHeap(object, region);
                if (result != J9MODRON_SLOT_ITERATOR_OK) {
                    break;
                }
                heapIterator.next();
                _engine.pushPreviousObject(object);
            }
        }
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCHeapRegionDescriptor(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionDescriptor) UDATA(com.ibm.j9ddr.vm29.types.UDATA) GCHeapRegionIterator(com.ibm.j9ddr.vm29.j9.gc.GCHeapRegionIterator) GCObjectHeapIterator(com.ibm.j9ddr.vm29.j9.gc.GCObjectHeapIterator) GCScavengerForwardedHeader(com.ibm.j9ddr.vm29.j9.gc.GCScavengerForwardedHeader) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 90 with UDATA

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

the class DeadlockUtils method getThreadStateDescription.

/**
 * Helper to obtain a textual description for a given thread state.
 * @param node
 * @return
 * @throws CorruptDataException
 */
private static String getThreadStateDescription(NativeDeadlockGraphNode node) throws CorruptDataException {
    String retVal = "unknown state for:";
    if (node instanceof JavaDeadlockGraphNode) {
        JavaDeadlockGraphNode javaNode = (JavaDeadlockGraphNode) node;
        ThreadInfo thrInfo = J9VMThreadPointerUtil.getJ9State(javaNode.javaThread);
        UDATA state = new UDATA(thrInfo.getState());
        if (state.allBitsIn(J9VMTHREAD_STATE_WAITING) || state.allBitsIn(J9VMTHREAD_STATE_WAITING_TIMED)) {
            retVal = "waiting for:";
        } else if (state.allBitsIn(J9VMTHREAD_STATE_BLOCKED)) {
            retVal = "blocking on:";
        }
    } else {
        // Native thread
        UDATA flags = node.nativeThread.flags();
        if (flags.allBitsIn(J9THREAD_FLAG_BLOCKED)) {
            retVal = "blocking on:";
        } else if (flags.allBitsIn(J9THREAD_FLAG_WAITING)) {
            retVal = "waiting for";
        }
    }
    return retVal;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) ThreadInfo(com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo)

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