Search in sources :

Example 26 with J9VMThreadPointer

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

the class CheckVMThreads method check.

@Override
public void check() {
    try {
        GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
        while (vmThreadListIterator.hasNext()) {
            J9VMThreadPointer walkThread = vmThreadListIterator.next();
            GCVMThreadIterator vmthreadIterator = GCVMThreadIterator.fromJ9VMThread(walkThread);
            while (vmthreadIterator.hasNext()) {
                PointerPointer slot = PointerPointer.cast(vmthreadIterator.nextAddress());
                if (_engine.checkSlotVMThread(slot, VoidPointer.cast(walkThread), CheckError.check_type_other, vmthreadIterator.getState()) != J9MODRON_SLOT_ITERATOR_OK) {
                    continue;
                }
            }
        }
    } catch (CorruptDataException e) {
    // TODO: handle exception
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) GCVMThreadIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadIterator)

Example 27 with J9VMThreadPointer

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

the class DTFJContext method getThreadInfoCache.

public static List<ThreadInfo> getThreadInfoCache() throws CorruptDataException {
    if (threadInfoCache == null) {
        List<ThreadInfo> localThreadInfoCache = new ArrayList<ThreadInfo>();
        J9VMThreadPointer vmThread = DTFJContext.getVm().mainThread();
        J9VMThreadPointer firstThread = vmThread;
        do {
            ThreadInfo info = getJ9State(vmThread);
            localThreadInfoCache.add(info);
            vmThread = vmThread.linkNext();
        } while (!vmThread.eq(firstThread));
        threadInfoCache = localThreadInfoCache;
    }
    return threadInfoCache;
}
Also used : ThreadInfo(com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo) ArrayList(java.util.ArrayList) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)

Example 28 with J9VMThreadPointer

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

the class J9VMThreadPointerUtil method getJ9State.

// Taken from thrinfo.c getVMThreadStateHelper
// Note that DDR has access to a wrapper for getting information about object monitors
// this should be used as the single point of access for obtaining this information rather
// than local copies of the functionality e.g. monitorPeekTable.
public static ThreadInfo getJ9State(J9VMThreadPointer targetThread) throws CorruptDataException {
    final ThreadInfo thrinfo = new ThreadInfo();
    if (targetThread.isNull()) {
        thrinfo.state = new UDATA(J9VMTHREAD_STATE_UNKNOWN).longValue();
        return thrinfo;
    }
    thrinfo.thread = targetThread;
    long vmstate = J9VMTHREAD_STATE_RUNNING;
    UDATA publicFlags = targetThread.publicFlags();
    J9ThreadPointer j9self = targetThread.osThread();
    /* j9self may be NULL if this function is used by RAS on a corrupt VM */
    ThreadState j9state = new ThreadState(j9self);
    if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_BLOCKED | J9_PUBLIC_FLAGS_THREAD_WAITING)) {
        /* Assert_VMUtil_true(targetThread->blockingEnterObject != NULL); */
        thrinfo.lockObject = targetThread.blockingEnterObject();
        // use the DDR object monitor wrapper
        ObjectMonitor monitor = ObjectMonitor.fromJ9Object(thrinfo.lockObject);
        // isInflated
        if (monitor.isInflated()) {
            if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_BLOCKED)) {
                if (monitor.getOwner().notNull() && !monitor.getOwner().equals(j9self)) {
                    /* 
						 * The omrthread may be accessing other raw monitors, but
						 * the vmthread is blocked while the object monitor is
						 * owned by a competing thread.
						 */
                    vmstate = J9VMTHREAD_STATE_BLOCKED;
                    thrinfo.rawLock = J9ThreadMonitorPointer.cast(monitor.getInflatedMonitor());
                }
            } else {
                if (j9self.isNull()) {
                    if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_TIMED)) {
                        vmstate = J9VMTHREAD_STATE_WAITING_TIMED;
                    } else {
                        vmstate = J9VMTHREAD_STATE_WAITING;
                    }
                    thrinfo.rawLock = J9ThreadMonitorPointer.cast(monitor.getInflatedMonitor());
                } else if (monitor.getInflatedMonitor().equals(j9state.blocker)) {
                    vmstate = getInflatedMonitorState(j9self, j9state, thrinfo);
                }
            /* 
					 * If the omrthread is using a different monitor, it must be for vm access.
					 * So the vmthread is either not waiting yet or already awakened.
					 */
            }
        } else {
            if (monitor.getOwner().notNull() && (!monitor.getOwner().equals(targetThread))) {
                /* count = J9_FLATLOCK_COUNT(lockWord); */
                /* rawLock = (omrthread_monitor_t)monitorTablePeekMonitor(targetThread->javaVM, lockObject); */
                vmstate = J9VMTHREAD_STATE_BLOCKED;
            }
        }
    /* 
			 * targetThread may be blocked attempting to reacquire VM access, after 
			 * succeeding to acquire the object monitor. In this case, the returned 
			 * vmstate depends on includeRawMonitors.
			 * includeRawMonitors == FALSE: the vmstate is RUNNING.
			 * includeRawMonitors == TRUE: the vmstate depends on the state of
			 * the omrthread. e.g. The omrthread may be blocked on publicFlagsMutex.
			 */
    } else if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_PARKED)) {
        /* if the osthread is not parked, then the thread is runnable */
        if (j9self.isNull() || (j9state.flags.anyBitsIn(J9THREAD_FLAG_PARKED))) {
            thrinfo.lockObject = targetThread.blockingEnterObject();
            if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_TIMED)) {
                vmstate = J9VMTHREAD_STATE_PARKED_TIMED;
            } else {
                vmstate = J9VMTHREAD_STATE_PARKED;
            }
        }
    } else if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_THREAD_SLEEPING)) {
        /* if the osthread is not sleeping, then the thread is runnable */
        if (j9self.isNull() || (j9state.flags.anyBitsIn(J9THREAD_FLAG_SLEEPING))) {
            vmstate = J9VMTHREAD_STATE_SLEEPING;
        }
    } else {
        /* no vmthread flags apply, so go through the omrthread flags */
        if (j9self.isNull()) {
            vmstate = J9VMTHREAD_STATE_UNKNOWN;
        } else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_PARKED)) {
            if (j9state.flags.anyBitsIn(J9THREAD_FLAG_TIMER_SET)) {
                vmstate = J9VMTHREAD_STATE_PARKED_TIMED;
            } else {
                vmstate = J9VMTHREAD_STATE_PARKED;
            }
        } else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_SLEEPING)) {
            vmstate = J9VMTHREAD_STATE_SLEEPING;
        } else if (j9state.flags.anyBitsIn(J9THREAD_FLAG_DEAD)) {
            vmstate = J9VMTHREAD_STATE_DEAD;
        }
    }
    if (J9VMTHREAD_STATE_RUNNING == vmstate) {
        /* check if the omrthread is blocked/waiting on a raw monitor */
        thrinfo.lockObject = null;
        vmstate = getInflatedMonitorState(j9self, j9state, thrinfo);
    }
    if (thrinfo.rawLock != null) {
        if (thrinfo.rawLock.flags().allBitsIn(J9THREAD_MONITOR_OBJECT)) {
            thrinfo.lockObject = J9ObjectPointer.cast(thrinfo.rawLock.userData());
        }
    }
    /* j9state was zeroed if j9self is NULL */
    if (j9state.flags.anyBitsIn(J9THREAD_FLAG_INTERRUPTED)) {
        vmstate |= J9VMTHREAD_STATE_INTERRUPTED;
    }
    if (j9state.flags.anyBitsIn(J9THREAD_FLAG_SUSPENDED)) {
        vmstate |= J9VMTHREAD_STATE_SUSPENDED;
    }
    if (publicFlags.anyBitsIn(J9_PUBLIC_FLAGS_HALT_THREAD_JAVA_SUSPEND)) {
        vmstate |= J9VMTHREAD_STATE_SUSPENDED;
    }
    thrinfo.state = new UDATA(vmstate).longValue();
    return thrinfo;
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Example 29 with J9VMThreadPointer

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

the class RootScanner method scanThreads.

protected void scanThreads() throws CorruptDataException {
    setReachability(Reachability.STRONG);
    GCVMThreadListIterator vmThreadListIterator = GCVMThreadListIterator.from();
    while (vmThreadListIterator.hasNext()) {
        J9VMThreadPointer walkThread = vmThreadListIterator.next();
        /* "Inline" the behaviour of GC_VMThreadIterator to distinguish between the types of roots */
        GCVMThreadSlotIterator threadSlotIterator = GCVMThreadSlotIterator.fromJ9VMThread(walkThread);
        GCVMThreadSlotIterator threadSlotAddressIterator = GCVMThreadSlotIterator.fromJ9VMThread(walkThread);
        while (threadSlotIterator.hasNext()) {
            doVMThreadSlot(threadSlotIterator.next(), threadSlotAddressIterator.nextAddress());
        }
        GCVMThreadJNISlotIterator jniSlotIterator = GCVMThreadJNISlotIterator.fromJ9VMThread(walkThread);
        GCVMThreadJNISlotIterator jniSlotAddressIterator = GCVMThreadJNISlotIterator.fromJ9VMThread(walkThread);
        while (jniSlotIterator.hasNext()) {
            doVMThreadJNISlot(jniSlotIterator.next(), jniSlotAddressIterator.nextAddress());
        }
        if (J9BuildFlags.interp_hotCodeReplacement) {
            GCVMThreadMonitorRecordSlotIterator monitorRecordSlotIterator = GCVMThreadMonitorRecordSlotIterator.fromJ9VMThread(walkThread);
            GCVMThreadMonitorRecordSlotIterator addressIterator = GCVMThreadMonitorRecordSlotIterator.fromJ9VMThread(walkThread);
            while (monitorRecordSlotIterator.hasNext()) {
                doVMThreadMonitorRecordSlot(monitorRecordSlotIterator.next(), addressIterator.nextAddress());
            }
        }
        if (_scanStackSlots) {
            GCVMThreadStackSlotIterator.scanSlots(walkThread, _stackWalkerCallbacks, _includeStackFrameClassReferences, _trackVisibleStackFrameDepth);
        }
    }
}
Also used : GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) GCVMThreadJNISlotIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadJNISlotIterator) GCVMThreadSlotIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadSlotIterator) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) GCVMThreadMonitorRecordSlotIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadMonitorRecordSlotIterator)

Example 30 with J9VMThreadPointer

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

the class WhatIsCommand method runWhatIs.

private void runWhatIs(String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length == 0) {
        badOrMissingSearchValue(out);
        return;
    }
    long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
    UDATA localSearchValue = new UDATA(address);
    if (localSearchValue.eq(0)) {
        badOrMissingSearchValue(out);
        return;
    }
    if (searchValue == null || !searchValue.eq(localSearchValue)) {
        searchValue = localSearchValue;
    } else {
        out.println("Skip count now " + (++skipCount) + ". Run !whatis 0 to reset it.");
    }
    resetFieldData();
    long startTime = System.currentTimeMillis();
    // Walk from the VM
    J9JavaVMPointer vm = null;
    try {
        vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException("Couldn't get VM", e);
    }
    boolean found = walkStructuresFrom(vm);
    // Walk from each VM thread
    if (!found) {
        try {
            J9VMThreadPointer mainThread = vm.mainThread();
            List<J9VMThreadPointer> threads = new LinkedList<J9VMThreadPointer>();
            if (mainThread.notNull()) {
                J9VMThreadPointer threadCursor = vm.mainThread();
                do {
                    threads.add(threadCursor);
                    threadCursor = threadCursor.linkNext();
                } while (!threadCursor.eq(mainThread) && !found);
                /* Walk the thread list backwards so we will find the match next to the closest thread (prevents walkStructures from doing anything useful with the linkNext list) */
                Collections.reverse(threads);
                for (J9VMThreadPointer thisThread : threads) {
                    found = walkStructuresFrom(thisThread);
                    if (found) {
                        break;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking thread list.");
            e.printStackTrace(out);
        }
    }
    // Walk from each class
    if (!found) {
        try {
            GCClassLoaderIterator it = GCClassLoaderIterator.from();
            OUTER: while (it.hasNext()) {
                J9ClassLoaderPointer loader = it.next();
                Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
                while (classIt.hasNext()) {
                    J9ClassPointer clazz = classIt.next();
                    found = walkStructuresFrom(clazz);
                    if (found) {
                        break OUTER;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking classes.");
            e.printStackTrace(out);
        }
    }
    long stopTime = System.currentTimeMillis();
    if (found) {
        out.println("Match found");
    } else {
        out.println("No match found");
        if (closestAboveStack != null) {
            out.print("Closest above was: ");
            closestAboveStack.dump(out);
            out.print(" at " + closestAbove.getHexValue());
            out.println();
        } else {
            out.println("No values found above search value");
        }
        if (closestBelowStack != null) {
            out.print("Closest below was: ");
            closestBelowStack.dump(out);
            out.print(" at " + closestBelow.getHexValue());
            out.println();
        } else {
            out.println("No values found below search value");
        }
        if (shortestHammingDistanceStack != null) {
            out.print("Value with shortest hamming distance (fewest single-bit changes required) was: ");
            shortestHammingDistanceStack.dump(out);
            out.print(" at " + shortestHammingDistance.getHexValue());
            out.print(". Hamming distance = " + hammingDistance);
            out.println();
        }
        /* Reset search value - so if someone reruns the same (unsuccessful) search again it won't set skipCount to 1 */
        searchValue = null;
    }
    out.println("Searched " + fieldCount + " fields to a depth of " + maxDepth + " in " + (stopTime - startTime) + " ms");
    resetFieldData();
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) LinkedList(java.util.LinkedList) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) Iterator(java.util.Iterator) ClassIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassIterator) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)

Aggregations

J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)39 CorruptDataException (com.ibm.j9ddr.CorruptDataException)28 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)16 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)15 GCVMThreadListIterator (com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator)13 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)9 WalkState (com.ibm.j9ddr.vm29.j9.stackwalker.WalkState)7 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)6 UDATA (com.ibm.j9ddr.vm29.types.UDATA)6 BaseStackWalkerCallbacks (com.ibm.j9ddr.vm29.j9.stackwalker.BaseStackWalkerCallbacks)5 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)5 StackWalkResult (com.ibm.j9ddr.vm29.j9.stackwalker.StackWalkResult)4 U8Pointer (com.ibm.j9ddr.vm29.pointer.U8Pointer)4 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)4 PointerPointer (com.ibm.j9ddr.vm29.pointer.PointerPointer)3 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)3 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)3 J9ThreadLibraryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)3 LinkedList (java.util.LinkedList)3 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)2