On Mon, 20 Oct 2025 19:19:05 GMT, Patricio Chilano Mateo <[email protected]> wrote:
>> src/hotspot/share/runtime/objectMonitor.cpp line 315: >> >>> 313: } >>> 314: >>> 315: // Keep object protected during ObjectLocker preemption. >> >> I don't understand why this is necessary. > > Once the thread initializing the class finishes the initialization and calls > `InstanceKlass::fence_and_clear_init_lock()`, the init_lock oop can be GC’ed, > unless there is some other `Handle` protecting it (`ObjectMonitor::_object` > is only a `WeakHandle`). But we could still have preempted virtual threads > using the ObjectMonitor, so we need to protect the oop. In practice, I don’t > see paths in `ObjectMonitor::resume_operation` where we try to get the oop > out of the monitor, but I’m not sure if we want to break the invariant where > the object needs to be alive while using its ObjectMonitor. I see - platforms threads have a Handle to the oop whilst they wait, but vthreads have left that code, so we need the OM to maintain the strong reference. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/27802#discussion_r2450563031
