--- old/src/hotspot/share/services/threadService.cpp 2019-12-11 14:56:22.000000000 -0500 +++ new/src/hotspot/share/services/threadService.cpp 2019-12-11 14:56:21.000000000 -0500 @@ -208,6 +208,10 @@ assert(thread != NULL, "should be non-NULL"); debug_only(Thread::check_for_dangling_thread_pointer(thread);) + // This function can be called on a target JavaThread that is not + // the caller and we are not at a safepoint. This ObjectMonitorHandle + // keeps the ObjectMonitor from being async deflated so the object + // reference we fetch remains non-NULL. ObjectMonitorHandle omh; ObjectMonitor *wait_obj = thread->current_waiting_monitor(&omh); @@ -217,7 +221,6 @@ obj = (oop) wait_obj->object(); assert(obj != NULL, "Object.wait() should have an object"); } else { - ObjectMonitorHandle omh; ObjectMonitor *enter_obj = thread->current_pending_monitor(&omh); if (enter_obj != NULL) { // thread is trying to enter() an ObjectMonitor. @@ -364,6 +367,8 @@ // This code was modified from the original Threads::find_deadlocks code. int globalDfn = 0, thisDfn; + // This code is called at a safepoint so this ObjectMonitorHandle + // is not strictly necessary. ObjectMonitorHandle omh; ObjectMonitor* waitingToLockMonitor = NULL; JvmtiRawMonitor* waitingToLockRawMonitor = NULL; @@ -985,6 +990,8 @@ int len = _threads->length(); for (int i = 0; i < len; i++) { currentThread = _threads->at(i); + // This code is called at a safepoint so this ObjectMonitorHandle + // is not strictly necessary. ObjectMonitorHandle omh; ObjectMonitor* waitingToLockMonitor = currentThread->current_pending_monitor(&omh); waitingToLockRawMonitor = currentThread->current_pending_raw_monitor();