Skip to content

Commit c257c8a

Browse files
committedMar 7, 2023
Set thread blocked flag before triggering JVMTI Monitor Contended Enter
Fixes #16685 Signed-off-by: Gengchen Tuo <gengchen.tuo@ibm.com>
1 parent 5a4ab53 commit c257c8a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎runtime/vm/ObjectMonitor.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "VMHelpers.hpp"
3333
#include "AtomicSupport.hpp"
3434
#include "ObjectMonitor.hpp"
35+
#include "VMAccess.hpp"
3536

3637
extern "C" {
3738

@@ -172,14 +173,20 @@ objectMonitorEnterBlocking(J9VMThread *currentThread)
172173
IDATA waitTime = 1;
173174
if (J9_EVENT_IS_HOOKED(vm->hookInterface, J9HOOK_VM_MONITOR_CONTENDED_ENTER)) {
174175
bool frameBuilt = saveBlockingEnterObject(currentThread);
176+
VM_VMAccess::setPublicFlags(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED);
175177
ALWAYS_TRIGGER_J9HOOK_VM_MONITOR_CONTENDED_ENTER(vm->hookInterface, currentThread, monitor);
176178
restoreBlockingEnterObject(currentThread, frameBuilt);
177179
}
178180
omrthread_t const osThread = currentThread->osThread;
179181
/* Update j.l.management info */
180182
currentThread->mgmtBlockedCount += 1;
183+
if (J9_ARE_ALL_BITS_SET(currentThread->publicFlags, J9_PUBLIC_FLAGS_THREAD_BLOCKED)) {
184+
internalReleaseVMAccess(currentThread);
185+
goto releasedAccess;
186+
}
181187
restart:
182188
internalReleaseVMAccessSetStatus(currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED);
189+
releasedAccess:
183190
omrthread_monitor_enter_using_threadId(monitor, osThread);
184191
#if defined(J9VM_THR_SMART_DEFLATION)
185192
/* Update the anti-deflation vote because we had to block */

0 commit comments

Comments
 (0)
Please sign in to comment.