Skip to content

Trigger contended object monitor enter event for virtual threads - #21585

Merged
babsingh merged 1 commit into
eclipse-openj9:masterfrom
hangshao0:master
Apr 8, 2025
Merged

Trigger contended object monitor enter event for virtual threads#21585
babsingh merged 1 commit into
eclipse-openj9:masterfrom
hangshao0:master

Conversation

@hangshao0

Copy link
Copy Markdown
Contributor

issue #21545

@hangshao0

Copy link
Copy Markdown
Contributor Author

Change for J9HOOK_VM_MONITOR_CONTENDED_ENTERED will be added in a separate PR.

@hangshao0
hangshao0 requested review from babsingh and fengxue-IS April 7, 2025 15:30
@hangshao0 hangshao0 changed the title Trigger contened object monitor enter envent for virtual threads Trigger contended object monitor enter envent for virtual threads Apr 7, 2025
@hangshao0 hangshao0 changed the title Trigger contended object monitor enter envent for virtual threads Trigger contended object monitor enter event for virtual threads Apr 7, 2025

@fengxue-IS fengxue-IS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code logic looks good, but missing support for other JVMTI functions which can be used by the user callback.

If this is sufficient to fix the test, I'm happy with moving the remaining support work into a different PR.

Comment thread runtime/vm/BytecodeInterpreter.hpp
Comment thread runtime/vm/BytecodeInterpreter.hpp Outdated
@hangshao0
hangshao0 force-pushed the master branch 3 times, most recently from 3e35164 to 3669be8 Compare April 7, 2025 17:39

@fengxue-IS fengxue-IS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@babsingh

babsingh commented Apr 7, 2025

Copy link
Copy Markdown
Contributor

jenkins test sanity amac jdk24

@babsingh

babsingh commented Apr 7, 2025

Copy link
Copy Markdown
Contributor

jenkins compile zlinux jdk21

@hangshao0

hangshao0 commented Apr 7, 2025

Copy link
Copy Markdown
Contributor Author

@fengxue-IS Adding VM_VMAccess::setPublicFlags(_currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED) is causing assertion failure at thrinfo.c:240:

Assert_VMUtil_true(targetThread->blockingEnterObject != NULL);

#23 0x00007ffff6f931f9 in getVMThreadStateHelper (targetThread=0x254c00, pLockObject=0x0, pRawLock=0x0, pLockOwner=0x0, pCount=0x0, includeRawMonitors=0)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/util/thrinfo.c:240
#24 0x00007ffff6f6b9c0 in getThreadStateHelper (vmThread=0x254c00, threadObject=0x7fffb23e0, currentThread=0x254c00)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHelpers.cpp:742
#25 getVirtualThreadState (currentThread=0x254c00, thread=0x2586a8) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHelpers.cpp:876
#26 0x00007ffff6f835ff in jvmtiGetThreadState (env=<optimized out>, thread=0x2586a8, thread_state_ptr=0x7fffcae1312c)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiThread.cpp:95
--Type <RET> for more, q to quit, c to continue without paging--
#27 0x00007ffff426ac0c in _jvmtiEnv::GetThreadState (thread_state_ptr=0x7fffcae1312c, thread=0x2586a8, this=0x7ffff00c5818) at support/modules_include/java.base/jvmti.h:1197
#28 print_thread_info (jvmti=jvmti@entry=0x7ffff00c5818, jni=jni@entry=0x254c00, thread_obj=thread_obj@entry=0x2586a8) at test/lib/jdk/test/lib/jvmti/jvmti_common.hpp:258
#29 0x00007ffff426ad98 in MonitorContendedEnter (jvmti=0x7ffff00c5818, jni=0x254c00, thr=0x2586a8, obj=0x258670)
    at test/hotspot/jtreg/serviceability/jvmti/events/MonitorContendedEnter/mcontenter01/libmcontenter01.cpp:53
#30 0x00007ffff6f7077c in jvmtiHookMonitorContendedEnter (hook=<optimized out>, eventNum=<optimized out>, eventData=<optimized out>, userData=0x7ffff00c5818)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHook.c:2110
#31 0x00007ffff7a139de in J9HookDispatch (hookInterface=0x7ffff0011db0, taggedEventNum=<optimized out>, eventData=0x7fffcae135c0)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/util/hookable/hookable.cpp:237
#32 0x00007ffff7aed516 in VM_BytecodeInterpreterCompressed::yieldPinnedContinuation (returnState=<optimized out>, newThreadState=<optimized out>, _pc=<optimized out>, _sp=<optimized out>,
    this=<optimized out>) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:1554
#33 VM_BytecodeInterpreterCompressed::monitorenter (_pc=<optimized out>, _sp=<optimized out>, this=<optimized out>)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:8974
#34 VM_BytecodeInterpreterCompressed::run (this=0x7fffcae13840, vmThread=0x7ffff7471198) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:12012
#35 0x00007ffff7acfcde in bytecodeLoopCompressed (currentThread=<optimized out>) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.inc:112
#36 0x00007ffff7b9caf2 in c_cInterpreter () at /root/CCM/JDK24/openj9-openjdk-jdk24/build/linux-x86_64-server-release/vm/runtime/vm/xcinterp.s:157
#37 0x00007ffff7a36c12 in runJavaThread (currentThread=0x254c00) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/callin.cpp:682
#38 0x00007ffff7ab6098 in javaProtectedThreadProc (portLibrary=portLibrary@entry=0x7ffff7cc2420 <j9portLibrary>, entryarg=entryarg@entry=0x254c00)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/vmthread.cpp:2153
#39 0x00007ffff78c3451 in omrsig_protect (portLibrary=0x7ffff7cc2420 <j9portLibrary>, fn=0x7ffff7ab6000 <javaProtectedThreadProc(J9PortLibrary*, void*)>, fn_arg=0x254c00,
    handler=0x7ffff7a59f80 <structuredSignalHandler>, handler_arg=0x254c00, flags=506, result=0x7fffcae13d28) at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/port/unix/omrsignal.c:425
#40 0x00007ffff7ab232d in javaThreadProc (entryarg=0x7ffff000f9d0) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/vmthread.cpp:414
#41 0x00007ffff7a03c07 in thread_wrapper (arg=0x7ffff0dd9440) at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/thread/common/omrthread.c:1724

I see it is set to NULL at the end of preparePinnedVirtualThreadForUnmount().

J9VMTHREAD_SET_BLOCKINGENTEROBJECT(currentThread, currentThread, NULL);

@fengxue-IS

Copy link
Copy Markdown
Contributor

@fengxue-IS Adding VM_VMAccess::setPublicFlags(_currentThread, J9_PUBLIC_FLAGS_THREAD_BLOCKED) is causing assertion failure at thrinfo.c:240:

Assert_VMUtil_true(targetThread->blockingEnterObject != NULL);

#23 0x00007ffff6f931f9 in getVMThreadStateHelper (targetThread=0x254c00, pLockObject=0x0, pRawLock=0x0, pLockOwner=0x0, pCount=0x0, includeRawMonitors=0)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/util/thrinfo.c:240
#24 0x00007ffff6f6b9c0 in getThreadStateHelper (vmThread=0x254c00, threadObject=0x7fffb23e0, currentThread=0x254c00)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHelpers.cpp:742
#25 getVirtualThreadState (currentThread=0x254c00, thread=0x2586a8) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHelpers.cpp:876
#26 0x00007ffff6f835ff in jvmtiGetThreadState (env=<optimized out>, thread=0x2586a8, thread_state_ptr=0x7fffcae1312c)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiThread.cpp:95
--Type <RET> for more, q to quit, c to continue without paging--
#27 0x00007ffff426ac0c in _jvmtiEnv::GetThreadState (thread_state_ptr=0x7fffcae1312c, thread=0x2586a8, this=0x7ffff00c5818) at support/modules_include/java.base/jvmti.h:1197
#28 print_thread_info (jvmti=jvmti@entry=0x7ffff00c5818, jni=jni@entry=0x254c00, thread_obj=thread_obj@entry=0x2586a8) at test/lib/jdk/test/lib/jvmti/jvmti_common.hpp:258
#29 0x00007ffff426ad98 in MonitorContendedEnter (jvmti=0x7ffff00c5818, jni=0x254c00, thr=0x2586a8, obj=0x258670)
    at test/hotspot/jtreg/serviceability/jvmti/events/MonitorContendedEnter/mcontenter01/libmcontenter01.cpp:53
#30 0x00007ffff6f7077c in jvmtiHookMonitorContendedEnter (hook=<optimized out>, eventNum=<optimized out>, eventData=<optimized out>, userData=0x7ffff00c5818)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/jvmti/jvmtiHook.c:2110
#31 0x00007ffff7a139de in J9HookDispatch (hookInterface=0x7ffff0011db0, taggedEventNum=<optimized out>, eventData=0x7fffcae135c0)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/util/hookable/hookable.cpp:237
#32 0x00007ffff7aed516 in VM_BytecodeInterpreterCompressed::yieldPinnedContinuation (returnState=<optimized out>, newThreadState=<optimized out>, _pc=<optimized out>, _sp=<optimized out>,
    this=<optimized out>) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:1554
#33 VM_BytecodeInterpreterCompressed::monitorenter (_pc=<optimized out>, _sp=<optimized out>, this=<optimized out>)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:8974
#34 VM_BytecodeInterpreterCompressed::run (this=0x7fffcae13840, vmThread=0x7ffff7471198) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.hpp:12012
#35 0x00007ffff7acfcde in bytecodeLoopCompressed (currentThread=<optimized out>) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/BytecodeInterpreter.inc:112
#36 0x00007ffff7b9caf2 in c_cInterpreter () at /root/CCM/JDK24/openj9-openjdk-jdk24/build/linux-x86_64-server-release/vm/runtime/vm/xcinterp.s:157
#37 0x00007ffff7a36c12 in runJavaThread (currentThread=0x254c00) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/callin.cpp:682
#38 0x00007ffff7ab6098 in javaProtectedThreadProc (portLibrary=portLibrary@entry=0x7ffff7cc2420 <j9portLibrary>, entryarg=entryarg@entry=0x254c00)
    at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/vmthread.cpp:2153
#39 0x00007ffff78c3451 in omrsig_protect (portLibrary=0x7ffff7cc2420 <j9portLibrary>, fn=0x7ffff7ab6000 <javaProtectedThreadProc(J9PortLibrary*, void*)>, fn_arg=0x254c00,
    handler=0x7ffff7a59f80 <structuredSignalHandler>, handler_arg=0x254c00, flags=506, result=0x7fffcae13d28) at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/port/unix/omrsignal.c:425
#40 0x00007ffff7ab232d in javaThreadProc (entryarg=0x7ffff000f9d0) at /root/CCM/JDK24/openj9-openjdk-jdk24/openj9/runtime/vm/vmthread.cpp:414
#41 0x00007ffff7a03c07 in thread_wrapper (arg=0x7ffff0dd9440) at /root/CCM/JDK24/openj9-openjdk-jdk24/omr/thread/common/omrthread.c:1724

I see it is set to NULL at the end of preparePinnedVirtualThreadForUnmount().

J9VMTHREAD_SET_BLOCKINGENTEROBJECT(currentThread, currentThread, NULL);

Yes, which is why I mentioned the 2 jvmti function at the same time. Once the preparePinnedVirtualThreadForUnmount is finished, the blocking state is transferred from the J9VMThread to Continuation object, the blocking object is stored in Continuation.blocker instead since we need to disassociate the virtual thread with its carrier.
For this PR, I suggest just reverting to the original changeset if that is sufficient to fix the test and patch both the state flag and blocker object together with the JVMTI function support.

@hangshao0

Copy link
Copy Markdown
Contributor Author

Reverted to the original change. The test mcontenter01 passed with the change.

@babsingh

babsingh commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

jenkins test sanity amac jdk24

@babsingh

babsingh commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

jenkins compile zlinux jdk21

@babsingh

babsingh commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

@hangshao0 There are failures in the sanity.openjdk PR build. Could you do an initial triage to see if it's related to your changes? If it's not, please create a new issue to track it. Once that's done, I'll go ahead and merge this PR.

@hangshao0

Copy link
Copy Markdown
Contributor Author

The test failures are known issues: #21446 and #21352.

@hangshao0

Copy link
Copy Markdown
Contributor Author

PR for 0.52: #21595

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants