From 6528e3346af5a296f3a30619624539870d7251f9 Mon Sep 17 00:00:00 2001 From: Jack Lu Date: Thu, 30 Jan 2025 11:08:37 -0500 Subject: [PATCH] fix Blocked state overwriting oldState in blocking enter Signed-off-by: Jack Lu --- runtime/vm/ObjectMonitor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/vm/ObjectMonitor.cpp b/runtime/vm/ObjectMonitor.cpp index 9b61083e7b8..afc64ec3840 100644 --- a/runtime/vm/ObjectMonitor.cpp +++ b/runtime/vm/ObjectMonitor.cpp @@ -164,7 +164,6 @@ objectMonitorEnterBlocking(J9VMThread *currentThread) /* Table entry was created by the nonblocking case, so this peek cannot fail */ Assert_VM_notNull(objectMonitor); object = NULL; // for safety, since object may be moved by the GC at various points after this - U_64 oldState = 0; /* Ensure object monitor isn't deflated while we block */ omrthread_monitor_t monitor = objectMonitor->monitor; VM_AtomicSupport::add(&monitor->pinCount, 1); @@ -174,6 +173,8 @@ objectMonitorEnterBlocking(J9VMThread *currentThread) IDATA waitTime = 1; if (J9_EVENT_IS_HOOKED(vm->hookInterface, J9HOOK_VM_MONITOR_CONTENDED_ENTER)) { bool frameBuilt = saveBlockingEnterObject(currentThread); + /* Set j.l.Thread status to BLOCKED. */ + VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_BLOCKED); VM_VMAccess::setPublicFlags(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED); ALWAYS_TRIGGER_J9HOOK_VM_MONITOR_CONTENDED_ENTER(vm->hookInterface, currentThread, monitor); restoreBlockingEnterObject(currentThread, frameBuilt); @@ -187,7 +188,7 @@ objectMonitorEnterBlocking(J9VMThread *currentThread) } restart: /* Set j.l.Thread status to BLOCKED. */ - oldState = VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_BLOCKED); + VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_BLOCKED); internalReleaseVMAccessSetStatus(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED); releasedAccess: omrthread_monitor_enter_using_threadId(monitor, osThread); @@ -288,8 +289,8 @@ objectMonitorEnterBlocking(J9VMThread *currentThread) } done: clearEventFlag(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED); - /* Set j.l.Thread status to oldState. */ - VM_VMHelpers::setThreadState(currentThread, oldState); + /* Set j.l.Thread status to RUNNING state. */ + VM_VMHelpers::setThreadState(currentThread, J9VMTHREAD_STATE_RUNNING); /* Clear the SUPPRESS_CONTENDED_EXITS bit in the monitor saying that CONTENDED EXIT can be sent again */ ((J9ThreadMonitor*)monitor)->flags &= ~(UDATA)J9THREAD_MONITOR_SUPPRESS_CONTENDED_EXIT;