Repository navigation
Implement ThreadMXBean thread info, deadlock detection and locked monitor and synchronizer dumps - #65
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…itor and synchronizer dumps
6b2650b to
c1c98f7
Compare
There was a problem hiding this comment.
This PR implements ThreadMXBean thread info, deadlock detection, and locked monitor/synchronizer dumps. It adds per-thread blocked/waited counts, snapshot logic to capture thread state (blocker, owner, frames), synchronized block analysis via exception tables to report locked monitors per frame, a heap walk from roots to find owned synchronizers, and a cycle detector for monitor and synchronizer deadlocks. Carrier threads report waiting on their mounted virtual thread. Contention monitoring stays off so times are -1. Tests pass and match HotSpot output.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
Implements the
ThreadMXBeannatives that describe threads, sogetThreadInfo,dumpAllThreadsand deadlock detection work as on HotSpot.getThreadInfo1anddumpThreads0buildThreadInfofrom the VM's thread records as HotSpot'sThreadSnapshotdoes: state asThread.getState()reports it, the lock a thread is blocked on or waiting for and its owner, the park blocker of a parked thread, and the stack trace tomaxDepth. A carrier thread reports waiting on its mounted virtual thread.findMonitorDeadlockedThreads0andfindDeadlockedThreads0portfind_deadlocks_at_safepoint: cycles over blocked monitors, and with synchronizers the park blocker'sexclusiveOwnerThread.lockedMonitors, each frame's locked monitors come from its synchronized blocks, found in the method's exception table, and the locals that hold the lock objects. Synchronized methods useFrame.lock. A monitor no frame accounts for is listed at depth -1.lockedSynchronizers, the owned ownable synchronizers come from a walk of the class statics and thread stacks, as HotSpot inspects the heap.VMManagementImplreports object monitor and synchronizer usage as supported.The monitor and lock fast paths are unchanged: no new stores on
monitorenter,monitorexitorsetExclusiveOwnerThread. The only new per-thread state is written when a thread blocks, waits or sleeps, and the snapshot restores the waiting monitor.ReentrantLock, read lock and write lock loops (3M uncontended lock and unlock, master against this branch, 10 alternating pairs, minimum time in ms): reentrant 778 against 791, read 1776 against 1770, write 1335 against 1315. The spread between runs is far larger than these differences.Tests:
test/java/ThreadInfos.javamatches HotSpot. It covers a monitor deadlock, aReentrantLockdeadlock, blocked, waiting, timed waiting, sleeping and parked threads, the caller's own locks in one frame and in a synchronized method, depth limits anddumpAllThreads. SevenThreadMXBeantests and the fourCarrierThreadInfotests joinpassing.txtwith their durations intimes.tsv. All 45java/lang/managementandCarrierThreadInfotests inpassing.txtpass. The suite has 189 passing, 0 failing and 3 skipped, andpnpm typecheckpasses. A scratch program with recursive locks, a lock held acrosswaitand a lock held in a hot loop also matches HotSpot.docs/support.mdno longer saysgetThreadInfoanddumpThreadsare missing.Noticed, not fixed:
ThreadMXBean/SynchronizationStatisticsneeds contention monitoring, which stays off.dumpAllThreads(true, true)slow. HotSpot pays the same kind of cost.