Search in sources :

Example 1 with GCVMThreadListIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator in project openj9 by eclipse.

the class StackRoots method walkStacks.

private void walkStacks() throws CorruptDataException {
    GCVMThreadListIterator threadIterator = GCVMThreadListIterator.from();
    while (threadIterator.hasNext()) {
        J9VMThreadPointer next = threadIterator.next();
        WalkState walkState = new WalkState();
        walkState.walkThread = next;
        walkState.flags = J9_STACKWALK_SKIP_INLINES | J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_ITERATE_METHOD_CLASS_SLOTS;
        walkState.callBacks = new StackWalkerCallbacks();
        StackWalkResult result = StackWalkResult.STACK_CORRUPT;
        result = StackWalker.walkStackFrames(walkState);
        if (StackWalkResult.NONE != result) {
            throw new UnsupportedOperationException("Failed to walk stack");
        }
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) IStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.IStackWalkerCallbacks) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) StackWalkResult(com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)

Example 2 with GCVMThreadListIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator in project openj9 by eclipse.

the class RootScanner method scanMonitorLookupCaches.

protected void scanMonitorLookupCaches() throws CorruptDataException {
    setReachability(Reachability.WEAK);
    GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
    while (vmThreadListIterator.hasNext()) {
        J9VMThreadPointer walkThread = vmThreadListIterator.next();
        if (J9BuildFlags.thr_lockNursery) {
            ObjectMonitorReferencePointer objectMonitorLookupCache = walkThread.objectMonitorLookupCacheEA();
            for (long cacheIndex = 0; cacheIndex < J9VMThread.J9VMTHREAD_OBJECT_MONITOR_CACHE_SIZE; cacheIndex++) {
                ObjectMonitorReferencePointer slotAddress = objectMonitorLookupCache.add(cacheIndex);
                doMonitorLookupCacheSlot(slotAddress.at(0), slotAddress);
            }
        } else {
            /* Can't implement this because walkThread.cachedMonitor field does not exist as we've never had a vm29 spec yet with the condition: 
				 * (!J9BuildFlags.thr_lockNursery && !J9BuildFlags.opt_realTimeLockingSupport)
				 * 
				 * // This cast is ugly but is technically what the c-code is doing 
				 * ObjectMonitorReferencePointer cachedMonitorSlot = ObjectMonitorReferencePointer.cast(walkThread.cachedMonitorEA());
				 * doMonitorLookupCacheSlot(walkThread.cachedMonitor(), cachedMonitorSlot);
				 */
            throw new UnsupportedOperationException("Not implemented");
        }
    }
}
Also used : ObjectMonitorReferencePointer(com.ibm.j9ddr.vm29.pointer.ObjectMonitorReferencePointer) GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)

Example 3 with GCVMThreadListIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator in project openj9 by eclipse.

the class ObjectMonitor_V1 method getBlockedThreads.

private static List<J9VMThreadPointer> getBlockedThreads(J9ObjectPointer blockingObject) throws CorruptDataException {
    // Do a single walk and cache all the results.
    if (blockedThreadsCache == null) {
        blockedThreadsCache = new HashMap<J9ObjectPointer, List<J9VMThreadPointer>>();
        GCVMThreadListIterator iterator = GCVMThreadListIterator.from();
        while (iterator.hasNext()) {
            J9VMThreadPointer vmThread = iterator.next();
            if (vmThread.publicFlags().allBitsIn(J9Consts.J9_PUBLIC_FLAGS_THREAD_BLOCKED)) {
                J9ObjectPointer object = vmThread.blockingEnterObject();
                if (object.notNull()) {
                    List<J9VMThreadPointer> list = blockedThreadsCache.get(object);
                    if (list == null) {
                        list = new ArrayList<J9VMThreadPointer>();
                        blockedThreadsCache.put(object, list);
                    }
                    list.add(vmThread);
                }
            }
        }
    }
    return blockedThreadsCache.get(blockingObject);
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) ArrayList(java.util.ArrayList) List(java.util.List) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 4 with GCVMThreadListIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator 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 5 with GCVMThreadListIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator in project openj9 by eclipse.

the class CheckVMThreadStacks method check.

@Override
public void check() {
    try {
        GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
        while (vmThreadListIterator.hasNext()) {
            J9VMThreadPointer walkThread = vmThreadListIterator.next();
            // GC_VMThreadStackSlotIterator::scanSlots(toScanWalkThread, toScanWalkThread, (void *)&localData, checkStackSlotIterator, false, false);
            WalkState walkState = new WalkState();
            walkState.walkThread = walkThread;
            walkState.flags = J9_STACKWALK_ITERATE_O_SLOTS | J9_STACKWALK_DO_NOT_SNIFF_AND_WHACK | J9_STACKWALK_SKIP_INLINES;
            walkState.callBacks = new BaseStackWalkerCallbacks() {

                public void objectSlotWalkFunction(J9VMThreadPointer walkThread, WalkState walkState, PointerPointer objectSlot, VoidPointer stackAddress) {
                    _engine.checkSlotStack(objectSlot, walkThread, stackAddress);
                }
            };
            StackWalker.walkStackFrames(walkState);
        }
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) BaseStackWalkerCallbacks(com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) WalkState(com.ibm.j9ddr.vm29.j9.stackwalker.WalkState) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Aggregations

GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)13 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)13 CorruptDataException (com.ibm.j9ddr.CorruptDataException)7 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)4 WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)3 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 GCVMThreadIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadIterator)2 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)2 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 InvalidDataTypeException (com.ibm.j9ddr.InvalidDataTypeException)1 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 J9JavaStackIterator (com.ibm.j9ddr.vm29.j9.J9JavaStackIterator)1 GCScavengerForwardedHeader (com.ibm.j9ddr.vm29.j9.gc.GCScavengerForwardedHeader)1 GCVMThreadJNISlotIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadJNISlotIterator)1 GCVMThreadMonitorRecordSlotIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadMonitorRecordSlotIterator)1 GCVMThreadSlotIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadSlotIterator)1 IStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.IStackWalkerCallbacks)1