Skip to content

Commit

Permalink
fix Blocked state overwriting oldState in blocking enter
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Lu <[email protected]>
  • Loading branch information
fengxue-IS committed Jan 30, 2025
1 parent 1ff5a46 commit 6528e33
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions runtime/vm/ObjectMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6528e33

Please sign in to comment.