Search in sources :

Example 1 with ThreadInfo

use of com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo 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 2 with ThreadInfo

use of com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo 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 3 with ThreadInfo

use of com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo 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)

Example 4 with ThreadInfo

use of com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo in project openj9 by eclipse.

the class DTFJJavaSystemMonitor method scanThreads.

private Iterator<DTFJJavaThread> scanThreads(long threadState) throws com.ibm.j9ddr.CorruptDataException {
    List<ThreadInfo> threadInfoCache = DTFJContext.getThreadInfoCache();
    ArrayList<DTFJJavaThread> threads = new ArrayList<DTFJJavaThread>();
    for (int i = 0; i < threadInfoCache.size(); i++) {
        try {
            ThreadInfo info = threadInfoCache.get(i);
            if ((info.getState() & threadState) != 0) {
                // thread is in the correct state
                if ((info.getRawLock() != null) && info.getRawLock().eq(monitor)) {
                    DTFJJavaThread dtfjThread = new DTFJJavaThread(info.getThread());
                    // raw monitor
                    threads.add(dtfjThread);
                }
            }
        } catch (Throwable t) {
            // log error and try to carry on
            J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
        }
    }
    return threads.iterator();
}
Also used : ThreadInfo(com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo) ArrayList(java.util.ArrayList)

Aggregations

ThreadInfo (com.ibm.j9ddr.vm29.j9.J9VMThreadPointerUtil.ThreadInfo)3 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 ArrayList (java.util.ArrayList)2 J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)1 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)1