--- old/src/hotspot/share/runtime/thread.hpp 2020-02-25 17:42:16.000000000 -0500 +++ new/src/hotspot/share/runtime/thread.hpp 2020-02-25 17:42:16.000000000 -0500 @@ -624,11 +624,23 @@ void increment_vm_operation_completed_count() { _vm_operation_completed_count++; } // For tracking the heavyweight monitor the thread is pending on. - ObjectMonitor* current_pending_monitor() { - return _current_pending_monitor; + ObjectMonitor* current_pending_monitor(ObjectMonitorHandle* omh_p) { + if (omh_p->save_om_ptr_if_safe(_current_pending_monitor)) { + return omh_p->om_ptr(); // Return the safe ObjectMonitor*. + } + return NULL; } void set_current_pending_monitor(ObjectMonitor* monitor) { + ObjectMonitor* saved_cur = NULL; + if (monitor != NULL) { + monitor->inc_ref_count(); // Protect the ObjectMonitor* we're about to cache. + } else { + saved_cur = _current_pending_monitor; + } _current_pending_monitor = monitor; + if (saved_cur != NULL) { + saved_cur->dec_ref_count(); // Cleared the cached ObjectMonitor*. + } } void set_current_pending_monitor_is_from_java(bool from_java) { _current_pending_monitor_is_from_java = from_java; @@ -638,11 +650,23 @@ } // For tracking the ObjectMonitor on which this thread called Object.wait() - ObjectMonitor* current_waiting_monitor() { - return _current_waiting_monitor; + ObjectMonitor* current_waiting_monitor(ObjectMonitorHandle* omh_p) { + if (omh_p->save_om_ptr_if_safe(_current_waiting_monitor)) { + return omh_p->om_ptr(); // Return the safe ObjectMonitor*. + } + return NULL; } void set_current_waiting_monitor(ObjectMonitor* monitor) { + ObjectMonitor* saved_cur = NULL; + if (monitor != NULL) { + monitor->inc_ref_count(); // Protect the ObjectMonitor* we're about to cache. + } else { + saved_cur = _current_waiting_monitor; + } _current_waiting_monitor = monitor; + if (saved_cur != NULL) { + saved_cur->dec_ref_count(); // Cleared the cached ObjectMonitor*. + } } // For tracking the Jvmti raw monitor the thread is pending on.