On Mon, 20 May 2024 04:25:49 GMT, David Holmes <dhol...@openjdk.org> wrote:

> Okay but how does this `dbgRawMonitor` lock prevent the GC from clearing a 
> jobject?

The JNI ref. It's actually a global ref (I said local ref earlier). As long as 
any setters of DebugRawMonitor::ownerThread (setting the thread or clearing it) 
grab dbgRawMonitor first, and the current thread accessing ownerThread does the 
same, then you know that whatever ownerThread points to is either NULL, the 
current thread, or some other thread that is still alive and is actually 
holding the monitor that the DebugRawMonitor is encapsulating. As long as the 
current thread continues to hold dbgRawMonitor, no other thread will be able to 
change ownerThread. This means that if some other thread currently owns the 
monitor that the DebugRawMonitor is encapsulating, then it will first block on 
dbgRawMonitor before trying to release it and clear ownerThread.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19044#issuecomment-2119650743

Reply via email to