Search in sources :

Example 6 with J9ThreadPointer

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

the class MonitorsCommand method threadCommand.

/**
 * Dumps all monitors that are active for the specified J9Thread/J9VMThread/java.lang.Thread
 * @param args
 * @param out
 * @throws DDRInteractiveCommandException
 */
private void threadCommand(String[] args, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length < 2) {
        out.println("This command takes one address argument: \"!monitors thread <address>\"");
        return;
    }
    try {
        long address = CommandUtils.parsePointer(args[1], J9BuildFlags.env_data64);
        VoidPointer ptr = VoidPointer.cast(address);
        J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
        J9VMThreadPointer mainThread = vm.mainThread();
        J9ThreadLibraryPointer lib = mainThread.osThread().library();
        J9PoolPointer pool = lib.thread_pool();
        Pool<J9ThreadPointer> threadPool = Pool.fromJ9Pool(pool, J9ThreadPointer.class);
        SlotIterator<J9ThreadPointer> poolIterator = threadPool.iterator();
        J9ThreadPointer osThreadPtr = null;
        while (poolIterator.hasNext()) {
            osThreadPtr = poolIterator.next();
            // Is there an associated J9VMThread?
            J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(osThreadPtr);
            J9ObjectPointer jlThread = null;
            if (vmThread.notNull()) {
                jlThread = vmThread.threadObject();
                if ((null != jlThread) && jlThread.equals(ptr)) {
                    out.println("Found java/lang/Thread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                } else if (vmThread.equals(ptr)) {
                    out.println("Found j9vmthread @ " + ptr.getHexAddress());
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                    return;
                }
            }
            if (osThreadPtr.equals(ptr)) {
                out.println("Found j9thread @ " + ptr.getHexAddress());
                if (vmThread.notNull()) {
                    printMonitorsForJ9VMThread(out, vm, vmThread);
                }
                printMonitorsForJ9Thread(out, vm, osThreadPtr);
                return;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9ThreadLibraryPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)

Example 7 with J9ThreadPointer

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

the class MonitorsCommand method printMonitorsForJ9Thread.

private void printMonitorsForJ9Thread(PrintStream out, J9JavaVMPointer vm, J9ThreadPointer osThreadPtr) throws CorruptDataException {
    FilterOptions defaultFilter = FilterOptions.defaultOption();
    MonitorIterator iterator = new MonitorIterator(vm);
    while (iterator.hasNext()) {
        Object current = iterator.next();
        if (current instanceof J9ThreadMonitorPointer) {
            // System Monitor
            SystemMonitor monitor = SystemMonitor.fromJ9ThreadMonitor((J9ThreadMonitorPointer) current);
            List<J9ThreadPointer> threadList = null;
            // Step 2: Print any monitors that the thread is the owner of:
            J9ThreadPointer ownerPtr = monitor.getOwner();
            if (ownerPtr.notNull() && ownerPtr.equals(osThreadPtr)) {
                out.print("Owns System Monitor:\n\t");
                writeSystemMonitor(defaultFilter, monitor, out);
            }
            // Step 3: Print any monitors that the thread is blocking on:
            threadList = monitor.getBlockedThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Blocking on System Monitor (Enter Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
            // Step 4: Print any monitors that the thread is waiting on:
            threadList = monitor.getWaitingThreads();
            for (J9ThreadPointer thread : threadList) {
                if (osThreadPtr.equals(thread)) {
                    out.print("Waiting on System Monitor (Notify Waiter):\n\t");
                    writeSystemMonitor(defaultFilter, monitor, out);
                }
            }
        }
    }
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) MonitorIterator(com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator) SystemMonitor(com.ibm.j9ddr.vm29.j9.SystemMonitor) J9ThreadMonitorPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)

Example 8 with J9ThreadPointer

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

the class MonitorsCommand method threadsListHelper.

/**
 * Helper to create lists of thread strings.
 *
 * @param thread
 * @return
 * @throws CorruptDataException
 */
private List<String> threadsListHelper(List<J9ThreadPointer> list) throws CorruptDataException {
    LinkedList<String> threadList = new LinkedList<String>();
    for (J9ThreadPointer thread : list) {
        J9VMThreadPointer vmThread = J9ThreadHelper.getVMThread(thread);
        if (vmThread.notNull()) {
            threadList.add(String.format("%s\t%s", vmThread.formatShortInteractive(), J9VMThreadHelper.getName(vmThread)));
        } else {
            threadList.add(String.format("%s\t%s", thread.formatShortInteractive(), "[osthread]"));
        }
        thread = thread.next();
    }
    return threadList;
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) LinkedList(java.util.LinkedList)

Example 9 with J9ThreadPointer

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

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

the class ObjectMonitor_V1 method initializeOwnerAndCount.

private void initializeOwnerAndCount() throws CorruptDataException {
    if (isInflated) {
        J9ThreadPointer osOwner = monitor.owner();
        if (osOwner.notNull()) {
            owner = J9ThreadHelper.getVMThread(osOwner);
            count = monitor.count().longValue();
            if (count == 0) {
                owner = J9VMThreadPointer.NULL;
            }
        } else {
            owner = J9VMThreadPointer.NULL;
        }
    } else {
        owner = J9VMThreadPointer.cast(lockword.untag(OBJECT_HEADER_LOCK_BITS_MASK));
        if (owner.notNull()) {
            UDATA base = UDATA.cast(lockword).bitAnd(OBJECT_HEADER_LOCK_BITS_MASK).rightShift((int) OBJECT_HEADER_LOCK_RECURSION_OFFSET);
            if (J9BuildFlags.thr_lockReservation) {
                if (!lockword.allBitsIn(OBJECT_HEADER_LOCK_RESERVED)) {
                    base = base.add(1);
                }
                count = base.longValue();
            } else {
                count = base.add(1).longValue();
            }
            if (count == 0) {
                /* this can happen if the lock is reserved but unowned */
                owner = J9VMThreadPointer.NULL;
            }
        }
    }
    ownerAndCountInitialized = true;
}
Also used : J9ThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA)

Aggregations

J9ThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadPointer)13 J9VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer)9 CorruptDataException (com.ibm.j9ddr.CorruptDataException)4 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)4 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)4 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)4 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)3 J9ThreadLibraryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadLibraryPointer)3 J9ThreadMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadMonitorPointer)3 SystemMonitor (com.ibm.j9ddr.vm29.j9.SystemMonitor)2 MonitorIterator (com.ibm.j9ddr.vm29.j9.walkers.MonitorIterator)2 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)2 OMR_VMThreadPointer (com.ibm.j9ddr.vm29.pointer.generated.OMR_VMThreadPointer)2 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 JavaThread (com.ibm.dtfj.java.JavaThread)1 ObjectMonitor (com.ibm.j9ddr.vm29.j9.ObjectMonitor)1 J9ContendedLoadTableEntryPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ContendedLoadTableEntryPointer)1 J9HashTablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer)1 J9ThreadAbstractMonitorPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ThreadAbstractMonitorPointer)1 HashMap (java.util.HashMap)1