diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp index 2ba7993b56ff7..b2d69ad582318 100644 --- a/src/hotspot/share/runtime/objectMonitor.cpp +++ b/src/hotspot/share/runtime/objectMonitor.cpp @@ -492,45 +492,45 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito freeze_result result; - { - assert(current->current_pending_monitor() == nullptr, "invariant"); - current->set_current_pending_monitor(this); - - DTRACE_MONITOR_PROBE(contended__enter, this, object(), current); - if (JvmtiExport::should_post_monitor_contended_enter()) { - JvmtiExport::post_monitor_contended_enter(current, this); - - // The current thread does not yet own the monitor and does not - // yet appear on any queues that would get it made the successor. - // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event - // handler cannot accidentally consume an unpark() meant for the - // ParkEvent associated with this ObjectMonitor. - } + assert(current->current_pending_monitor() == nullptr, "invariant"); + current->set_current_pending_monitor(this); - ContinuationEntry* ce = current->last_continuation(); - if (ce != nullptr && ce->is_virtual_thread()) { - result = Continuation::try_preempt(current, ce->cont_oop(current)); - if (result == freeze_ok) { - bool acquired = VThreadMonitorEnter(current); - if (acquired) { - // We actually acquired the monitor while trying to add the vthread to the - // _cxq so cancel preemption. We will still go through the preempt stub - // but instead of unmounting we will call thaw to continue execution. - current->set_preemption_cancelled(true); - if (JvmtiExport::should_post_monitor_contended_entered()) { - // We are going to call thaw again after this and finish the VMTS - // transition so no need to do it here. We will post the event there. - current->set_contended_entered_monitor(this); - } + DTRACE_MONITOR_PROBE(contended__enter, this, object(), current); + if (JvmtiExport::should_post_monitor_contended_enter()) { + JvmtiExport::post_monitor_contended_enter(current, this); + + // The current thread does not yet own the monitor and does not + // yet appear on any queues that would get it made the successor. + // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event + // handler cannot accidentally consume an unpark() meant for the + // ParkEvent associated with this ObjectMonitor. + } + + ContinuationEntry* ce = current->last_continuation(); + if (ce != nullptr && ce->is_virtual_thread()) { + result = Continuation::try_preempt(current, ce->cont_oop(current)); + if (result == freeze_ok) { + bool acquired = VThreadMonitorEnter(current); + if (acquired) { + // We actually acquired the monitor while trying to add the vthread to the + // _cxq so cancel preemption. We will still go through the preempt stub + // but instead of unmounting we will call thaw to continue execution. + current->set_preemption_cancelled(true); + if (JvmtiExport::should_post_monitor_contended_entered()) { + // We are going to call thaw again after this and finish the VMTS + // transition so no need to do it here. We will post the event there. + current->set_contended_entered_monitor(this); } - current->set_current_pending_monitor(nullptr); - DEBUG_ONLY(int state = java_lang_VirtualThread::state(current->vthread())); - assert((acquired && current->preemption_cancelled() && state == java_lang_VirtualThread::RUNNING) || - (!acquired && !current->preemption_cancelled() && state == java_lang_VirtualThread::BLOCKING), "invariant"); - return; } + current->set_current_pending_monitor(nullptr); + DEBUG_ONLY(int state = java_lang_VirtualThread::state(current->vthread())); + assert((acquired && current->preemption_cancelled() && state == java_lang_VirtualThread::RUNNING) || + (!acquired && !current->preemption_cancelled() && state == java_lang_VirtualThread::BLOCKING), "invariant"); + return; } + } + { // Change java thread status to indicate blocked on monitor enter. JavaThreadBlockedOnMonitorEnterState jtbmes(current, this);