Search in sources :

Example 76 with J9ClassPointer

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

the class CheckEngine method checkJ9ClassPointer.

public int checkJ9ClassPointer(J9ClassPointer clazz, boolean allowUndead) throws CorruptDataException {
    // Java-ism. Need to check this first before doing compares etc.
    if (clazz == null || clazz.isNull()) {
        return J9MODRON_GCCHK_RC_NULL_CLASS_POINTER;
    }
    // Short circuit if we've recently checked this class.
    int cacheIndex = (int) (clazz.longValue() % CLASS_CACHE_SIZE);
    if (allowUndead && clazz.eq(_checkedClassCacheAllowUndead[cacheIndex])) {
        return J9MODRON_GCCHK_RC_OK;
    } else if (clazz.eq(_checkedClassCache[cacheIndex])) {
        return J9MODRON_GCCHK_RC_OK;
    }
    if (UDATA.cast(clazz).anyBitsIn(J9MODRON_GCCHK_J9CLASS_ALIGNMENT_MASK)) {
        return J9MODRON_GCCHK_RC_CLASS_POINTER_UNALIGNED;
    }
    J9MemorySegmentPointer segment = findSegmentForClass(clazz);
    if (segment == null) {
        return J9MODRON_GCCHK_RC_CLASS_NOT_FOUND;
    }
    if (!allowUndead) {
        if ((segment.type().longValue() & MEMORY_TYPE_UNDEAD_CLASS) != 0) {
            return J9MODRON_GCCHK_RC_CLASS_IS_UNDEAD;
        }
    }
    /* Check to ensure J9Class header has the correct eyecatcher. */
    int result = checkJ9ClassHeader(clazz);
    if (J9MODRON_GCCHK_RC_OK != result) {
        return result;
    }
    /* Check to ensure J9Class is not unloaded */
    result = checkJ9ClassIsNotUnloaded(clazz);
    if (J9MODRON_GCCHK_RC_OK != result) {
        return result;
    }
    if ((_cycle.getCheckFlags() & J9MODRON_GCCHK_VERIFY_RANGE) != 0) {
        IDATA delta = segment.heapAlloc().sub(U8Pointer.cast(clazz));
        /* Basic check that there is enough room for the class header */
        if (delta.lt(J9Class.SIZEOF)) {
            return J9MODRON_GCCHK_RC_CLASS_INVALID_RANGE;
        }
    }
    /* class checked out. Record it in the cache so we don't need to check it again. */
    if (allowUndead) {
        _checkedClassCacheAllowUndead[cacheIndex] = clazz;
    } else {
        _checkedClassCache[cacheIndex] = clazz;
    }
    return J9MODRON_GCCHK_RC_OK;
}
Also used : IDATA(com.ibm.j9ddr.vm29.types.IDATA) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer)

Example 77 with J9ClassPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer 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 78 with J9ClassPointer

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

the class CheckEngine method checkObjectHeap.

public int checkObjectHeap(J9ObjectPointer object, GCHeapRegionDescriptor regionDesc) {
    int result = J9MODRON_SLOT_ITERATOR_OK;
    boolean isDead = false;
    boolean isIndexable = false;
    J9ClassPointer clazz = null;
    try {
        if (ObjectModel.isDeadObject(object)) {
            /* this is a hole */
            result = checkJ9LinkedFreeHeader(GCHeapLinkedFreeHeader.fromJ9Object(object), regionDesc, _cycle.getCheckFlags());
            if (J9MODRON_GCCHK_RC_OK != result) {
                CheckError error = new CheckError(object, _cycle, _currentCheck, "Object", result, _cycle.nextErrorCount());
                _reporter.report(error);
                /* There are some error cases would not prevent further iteration */
                if (!((J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_NOT_HOLE == result) || (J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_NOT_IN_REGION == result) || (J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_POINTED_INSIDE == result))) {
                    _reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
                    return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
                }
            }
            return J9MODRON_SLOT_ITERATOR_OK;
        }
    } 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;
    }
    try {
        // Prefetch this data to make CDE handling easy
        isIndexable = ObjectModel.isIndexable(object);
        clazz = J9ObjectHelper.clazz(object);
        result = checkJ9Object(object, regionDesc, _cycle.getCheckFlags());
    } catch (CorruptDataException cde) {
        // 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(object, _cycle, _currentCheck, elementName, result, _cycle.nextErrorCount());
        _reporter.report(error);
        /* There are some error cases would not prevent further iteration */
        if (!(J9MODRON_GCCHK_RC_CLASS_IS_UNLOADED == result)) {
            _reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
            return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
        } else {
            return J9MODRON_SLOT_ITERATOR_OK;
        }
    }
    try {
        /* check Ownable Synchronizer Object consistency */
        if (needVerifyOwnableSynchronizerConsistency()) {
            if (J9Object.OBJECT_HEADER_SHAPE_MIXED == ObjectModel.getClassShape(clazz).intValue() && !J9ClassHelper.classFlags(clazz).bitAnd(J9AccClassOwnableSynchronizer).eq(0)) {
                if (ObjectAccessBarrier.isObjectInOwnableSynchronizerList(object).isNull()) {
                    CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_OWNABLE_SYNCHRONIZER_OBJECT_IS_NOT_ATTACHED_TO_THE_LIST, _cycle.nextErrorCount());
                    _reporter.report(error);
                } else {
                    _ownableSynchronizerObjectCountOnHeap += 1;
                }
            }
        }
    } catch (CorruptDataException cde) {
        // 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) {
        GCObjectIterator fieldIterator;
        GCObjectIterator addressIterator;
        try {
            fieldIterator = GCObjectIterator.fromJ9Object(object, true);
            addressIterator = GCObjectIterator.fromJ9Object(object, true);
        } 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;
        }
        while (fieldIterator.hasNext()) {
            J9ObjectPointer field = fieldIterator.next();
            VoidPointer address = addressIterator.nextAddress();
            result = checkSlotObjectHeap(field, ObjectReferencePointer.cast(address), regionDesc, object);
            if (J9MODRON_SLOT_ITERATOR_OK != result) {
                break;
            }
        }
    }
    if (J9MODRON_GCCHK_RC_OK == result) {
        /* this heap object is OK. Record it in the cache in case we find a pointer to it soon */
        int cacheIndex = (int) (object.getAddress() % OBJECT_CACHE_SIZE);
        _checkedObjectCache[cacheIndex] = object;
    }
    return result;
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCObjectIterator(com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 79 with J9ClassPointer

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

the class CheckEngine method checkSlotOwnableSynchronizerList.

public int checkSlotOwnableSynchronizerList(J9ObjectPointer object, MM_OwnableSynchronizerObjectListPointer currentList) {
    if (needVerifyOwnableSynchronizerConsistency()) {
        _ownableSynchronizerObjectCountOnList += 1;
    }
    try {
        int result = checkObjectIndirect(object);
        if (J9MODRON_GCCHK_RC_OK != result) {
            CheckError error = new CheckError(currentList, object, _cycle, _currentCheck, result, _cycle.nextErrorCount());
            _reporter.report(error);
            _reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
            return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
        }
        J9ClassPointer instanceClass = J9ObjectHelper.clazz(object);
        if (J9ClassHelper.classFlags(instanceClass).bitAnd(J9AccClassOwnableSynchronizer).eq(0)) {
            CheckError error = new CheckError(currentList, object, _cycle, _currentCheck, J9MODRON_GCCHK_RC_INVALID_FLAGS, _cycle.nextErrorCount());
            _reporter.report(error);
        }
    } catch (CorruptDataException e) {
        CheckError error = new CheckError(currentList, object, _cycle, _currentCheck, J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
        _reporter.report(error);
        _reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
        return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
    }
    return J9MODRON_SLOT_ITERATOR_OK;
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 80 with J9ClassPointer

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

the class CheckVMClassSlots method print.

@Override
public void print() {
    try {
        GCVMClassSlotIterator classSlotIterator = GCVMClassSlotIterator.from();
        ScanFormatter formatter = new ScanFormatter(this, "VMClass Slot");
        while (classSlotIterator.hasNext()) {
            J9ClassPointer theClazz = classSlotIterator.next();
            if (theClazz.notNull()) {
                formatter.entry(theClazz);
            }
        }
        formatter.end("VMClass Slot");
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCVMClassSlotIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMClassSlotIterator) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

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