--- old/src/hotspot/share/services/threadService.cpp 2019-11-04 14:59:08.000000000 -0500 +++ new/src/hotspot/share/services/threadService.cpp 2019-11-04 14:59:08.000000000 -0500 @@ -208,7 +208,8 @@ assert(thread != NULL, "should be non-NULL"); debug_only(Thread::check_for_dangling_thread_pointer(thread);) - ObjectMonitor *wait_obj = thread->current_waiting_monitor(); + ObjectMonitorHandle omh; + ObjectMonitor *wait_obj = thread->current_waiting_monitor(&omh); oop obj = NULL; if (wait_obj != NULL) { @@ -216,7 +217,8 @@ obj = (oop) wait_obj->object(); assert(obj != NULL, "Object.wait() should have an object"); } else { - ObjectMonitor *enter_obj = thread->current_pending_monitor(); + ObjectMonitorHandle omh; + ObjectMonitor *enter_obj = thread->current_pending_monitor(&omh); if (enter_obj != NULL) { // thread is trying to enter() an ObjectMonitor. obj = (oop) enter_obj->object(); @@ -362,6 +364,7 @@ // This code was modified from the original Threads::find_deadlocks code. int globalDfn = 0, thisDfn; + ObjectMonitorHandle omh; ObjectMonitor* waitingToLockMonitor = NULL; JvmtiRawMonitor* waitingToLockRawMonitor = NULL; oop waitingToLockBlocker = NULL; @@ -391,10 +394,15 @@ cycle->reset(); + if (waitingToLockMonitor != NULL) { + // Done with the current waitingToLockMonitor value so release + // the ObjectMonitorHandle manually before we use it again: + omh.unset_om_ptr(); + } // When there is a deadlock, all the monitors involved in the dependency // cycle must be contended and heavyweight. So we only care about the // heavyweight monitor a thread is waiting to lock. - waitingToLockMonitor = jt->current_pending_monitor(); + waitingToLockMonitor = jt->current_pending_monitor(&omh); // JVM TI raw monitors can also be involved in deadlocks, and we can be // waiting to lock both a raw monitor and ObjectMonitor at the same time. // It isn't clear how to make deadlock detection work correctly if that @@ -485,7 +493,12 @@ break; } previousThread = currentThread; - waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(); + if (waitingToLockMonitor != NULL) { + // Done with the current waitingToLockMonitor value so release + // the ObjectMonitorHandle manually before we use it again: + omh.unset_om_ptr(); + } + waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor(&omh); if (concurrent_locks) { waitingToLockBlocker = currentThread->current_park_blocker(); } @@ -967,13 +980,13 @@ st->print("============================="); JavaThread* currentThread; - ObjectMonitor* waitingToLockMonitor; JvmtiRawMonitor* waitingToLockRawMonitor; oop waitingToLockBlocker; int len = _threads->length(); for (int i = 0; i < len; i++) { currentThread = _threads->at(i); - waitingToLockMonitor = currentThread->current_pending_monitor(); + ObjectMonitorHandle omh; + ObjectMonitor* waitingToLockMonitor = currentThread->current_pending_monitor(&omh); waitingToLockRawMonitor = currentThread->current_pending_raw_monitor(); waitingToLockBlocker = currentThread->current_park_blocker(); st->cr();