Skip to content

Commit c982de9

Browse files
committed
Fix typo
Signed-off-by: Jack Lu <[email protected]>
1 parent 738cb02 commit c982de9

File tree

9 files changed

+88
-43
lines changed

9 files changed

+88
-43
lines changed

runtime/j9vm/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ target_link_libraries(jvm_common
5656
${OMR_PLATFORM_THREAD_LIBRARY}
5757
)
5858

59+
if(NOT JAVA_SPEC_VERSION LESS 24)
60+
target_link_libraries(jvm_common
61+
INTERFACE
62+
j9thr
63+
)
64+
endif()
65+
5966
target_include_directories(jvm_common
6067
INTERFACE
6168
${CMAKE_CURRENT_BINARY_DIR}

runtime/j9vm/javanextvmi.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include "VMHelpers.hpp"
3636
#include "ContinuationHelpers.hpp"
3737
#endif /* JAVA_SPEC_VERSION >= 19 */
38+
#if JAVA_SPEC_VERSION >= 24
39+
#include "j9protos.h"
40+
#endif /* JAVA_SPEC_VERSION >= 24 */
3841

3942
extern "C" {
4043

@@ -731,8 +734,11 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
731734
{
732735
J9VMThread *currentThread = (J9VMThread *)env;
733736
J9JavaVM *vm = currentThread->javaVM;
737+
J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions;
734738
j9object_t unblockedList = NULL;
739+
jobject result = NULL;
735740

741+
vmFuncs->internalEnterVMFromJNI(currentThread);
736742
while (NULL == unblockedList) {
737743
if (NULL != vm->blockedVirtualThreads) {
738744
omrthread_monitor_enter(vm->blockedVirtualThreadsMutex);
@@ -747,17 +753,18 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
747753
unblocked = true;
748754
} else {
749755
j9object_t continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, listHead);
750-
j9object_t syncObject = J9VMJDKINTERALVMCONTINUATION_BLOCKER(currentThread, continuationObj);
756+
j9object_t syncObject = J9VMJDKINTERNALVMCONTINUATION_BLOCKER(currentThread, continuationObj);
751757
J9ObjectMonitor* syncObjectMonitor = NULL;
752-
if (!LN_HAS_LOCKWORD(currentThread, syncObj)) {
753-
syncObjectMonitor = monitorTablePeek(currentThread->javaVM, syncObject);
758+
j9objectmonitor_t lock = 0;
759+
if (!LN_HAS_LOCKWORD(currentThread, syncObject)) {
760+
syncObjectMonitor = vmFuncs->monitorTablePeek(vm, syncObject);
754761
if (syncObjectMonitor != NULL){
755-
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
762+
lock = J9_LOAD_LOCKWORD_VM(vm, syncObjectMonitor->alternateLockword);
756763
}
757764
} else {
758765
lock = J9OBJECT_MONITOR(currentThread, syncObject);
759766
}
760-
J9ThreadAbstractMonitor *monitor = getInflatedObjectMonitor(vm, object, lock);
767+
J9ThreadAbstractMonitor *monitor = getInflatedObjectMonitor(vm, syncObject, lock);
761768
if (0 == monitor->count) {
762769
unblocked = true;
763770
if (syncObjectMonitor->virtualThreadWaitCount >= 1) {
@@ -771,8 +778,8 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
771778
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, unblockedList);
772779
unblockedList = listHead;
773780
} else {
774-
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, vm->blockedVirtualThreadsMutex);
775-
vm->blockedVirtualThreadsMutex = listHead;
781+
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, vm->blockedVirtualThreads);
782+
vm->blockedVirtualThreads = listHead;
776783
}
777784
listHead = next;
778785
}
@@ -781,12 +788,14 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
781788
goto restart;
782789
} else {
783790
omrthread_monitor_exit(vm->blockedVirtualThreadsMutex);
791+
result = vmFuncs->j9jni_createLocalRef(env, unblockedList);
784792
break;
785793
}
786794
}
787795
}
796+
vmFuncs->internalExitVMToJNI(currentThread);
788797

789-
return unblockedList;
798+
return result;
790799
}
791800
#endif /* JAVA_SPEC_VERSION >= 24 */
792801

runtime/oti/j9nonbuilder.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,7 @@ typedef struct J9ObjectMonitor {
17171717
U_32 hash;
17181718
#if JAVA_SPEC_VERSION >= 24
17191719
U_32 virtualThreadWaitCount;
1720+
j9object_t vthread;
17201721
j9object_t waitingVirtualThreads;
17211722
#endif /* JAVA_SPEC_VERSION >= 24 */
17221723
} J9ObjectMonitor;
@@ -5321,6 +5322,9 @@ typedef struct J9InternalVMFunctions {
53215322
struct J9Class * (*initializeSnapshotClassObject)(struct J9JavaVM *javaVM, struct J9ClassLoader *classLoader, struct J9Class *clazz);
53225323
BOOLEAN (*loadWarmClassFromSnapshot)(struct J9VMThread *vmThread, struct J9ClassLoader *classLoader, struct J9Class *clazz);
53235324
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
5325+
#if JAVA_SPEC_VERSION >= 24
5326+
J9ObjectMonitor * (*monitorTablePeek)(struct J9JavaVM *vm, j9object_t object);
5327+
#endif /* JAVA_SPEC_VERSION >= 24 */
53245328
} J9InternalVMFunctions;
53255329

53265330
/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */
@@ -6388,7 +6392,7 @@ typedef struct J9JavaVM {
63886392
#define J9_OBJECT_MONITOR_CRIU_SINGLE_THREAD_MODE_THROW 2
63896393
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
63906394
#if JAVA_SPEC_VERSION >= 24
6391-
#define J9_OBJECT_MONTIOR_YIELD_VIRTUAL 3
6395+
#define J9_OBJECT_MONITOR_YIELD_VIRTUAL 3
63926396
#endif /* JAVA_SPEC_VERSION >= 24 */
63936397
#define J9_OBJECT_MONITOR_BLOCKING 4
63946398

runtime/oti/vm_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,16 @@ monitorTableAt(J9VMThread* vmStruct, j9object_t object);
24192419
void
24202420
cacheObjectMonitorForLookup(J9JavaVM* vm, J9VMThread* vmStruct, J9ObjectMonitor* objectMonitor);
24212421

2422+
/* ---------------- thrinfo.c ---------------- */
2423+
2424+
/**
2425+
* @brief Search vm->monitorTable for the inflated monitor corresponding to an object.
2426+
* @param vm
2427+
* @param object
2428+
* @return J9ObjectMonitor *
2429+
*/
2430+
J9ObjectMonitor *
2431+
monitorTablePeek(J9JavaVM *vm, j9object_t object);
24222432

24232433
/* ---------------- PackageIDHashTable.c ---------------- */
24242434

runtime/vm/BytecodeInterpreter.hpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ class INTERPRETER_CLASS
11881188
&& (0 == _currentThread->callOutCount)
11891189
) {
11901190
/* Try to yield virtual thread if it will be blocked */
1191-
rc = VM_ContinuationHelpers::preparePinnedVirtualThreadForUnmount(_currentThread, obj);
1191+
rc = preparePinnedVirtualThreadForUnmount(_currentThread, obj, false);
11921192
} else
11931193
#endif /* JAVA_SPEC_VERSION >= 24 */
11941194
{
@@ -1718,6 +1718,7 @@ class INTERPRETER_CLASS
17181718
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
17191719
#if JAVA_SPEC_VERSION >= 24
17201720
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
1721+
{
17211722
rc = EXECUTE_BYTECODE;
17221723
buildInternalNativeStackFrame(REGISTER_ARGS);
17231724
updateVMStruct(REGISTER_ARGS);
@@ -1740,6 +1741,7 @@ class INTERPRETER_CLASS
17401741
*/
17411742
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
17421743
break;
1744+
}
17431745
#endif /* JAVA_SPEC_VERSION >= 24 */
17441746
case J9_OBJECT_MONITOR_OOM:
17451747
rc = THROW_MONITOR_ALLOC_FAIL;
@@ -1820,6 +1822,7 @@ class INTERPRETER_CLASS
18201822
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
18211823
#if JAVA_SPEC_VERSION >= 24
18221824
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
1825+
{
18231826
rc = EXECUTE_BYTECODE;
18241827
buildInternalNativeStackFrame(REGISTER_ARGS);
18251828
updateVMStruct(REGISTER_ARGS);
@@ -1842,6 +1845,7 @@ class INTERPRETER_CLASS
18421845
*/
18431846
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
18441847
break;
1848+
}
18451849
#endif /* JAVA_SPEC_VERSION >= 24 */
18461850
case J9_OBJECT_MONITOR_OOM:
18471851
/* Monitor was not entered - hide the frame to prevent exception throw from processing it.
@@ -1974,6 +1978,7 @@ class INTERPRETER_CLASS
19741978
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
19751979
#if JAVA_SPEC_VERSION >= 24
19761980
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
1981+
{
19771982
rc = EXECUTE_BYTECODE;
19781983
buildInternalNativeStackFrame(REGISTER_ARGS);
19791984
updateVMStruct(REGISTER_ARGS);
@@ -1996,6 +2001,7 @@ class INTERPRETER_CLASS
19962001
*/
19972002
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
19982003
break;
2004+
}
19992005
#endif /* JAVA_SPEC_VERSION >= 24 */
20002006
case J9_OBJECT_MONITOR_OOM:
20012007
rc = THROW_MONITOR_ALLOC_FAIL;
@@ -2369,6 +2375,7 @@ class INTERPRETER_CLASS
23692375
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
23702376
#if JAVA_SPEC_VERSION >= 24
23712377
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
2378+
{
23722379
rc = EXECUTE_BYTECODE;
23732380
buildInternalNativeStackFrame(REGISTER_ARGS);
23742381
updateVMStruct(REGISTER_ARGS);
@@ -2391,6 +2398,7 @@ class INTERPRETER_CLASS
23912398
*/
23922399
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
23932400
break;
2401+
}
23942402
#endif /* JAVA_SPEC_VERSION >= 24 */
23952403
case J9_OBJECT_MONITOR_OOM:
23962404
rc = THROW_MONITOR_ALLOC_FAIL;
@@ -2984,7 +2992,7 @@ class INTERPRETER_CLASS
29842992
if ((NULL != objectMonitor) && (NULL != objectMonitor->waitingVirtualThreads)) {
29852993
omrthread_monitor_enter(_vm->blockedVirtualThreadsMutex);
29862994
j9object_t head = objectMonitor->waitingVirtualThreads;
2987-
if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
2995+
if (omrthread_monitor_notify == notifyFunction) {
29882996
objectMonitor->waitingVirtualThreads = J9VMJAVALANGVIRTUALTHREAD_NEXT(_currentThread, head);
29892997
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(_currentThread, head, _vm->blockedVirtualThreads);
29902998
_vm->blockedVirtualThreads = head;
@@ -3001,7 +3009,7 @@ class INTERPRETER_CLASS
30013009
omrthread_monitor_notify(_vm->blockedVirtualThreadsMutex);
30023010
omrthread_monitor_exit(_vm->blockedVirtualThreadsMutex);
30033011

3004-
if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
3012+
if (omrthread_monitor_notify == notifyFunction) {
30053013
returnVoidFromINL(REGISTER_ARGS, 1);
30063014
goto done;
30073015
}
@@ -5204,8 +5212,8 @@ class INTERPRETER_CLASS
52045212
newState = JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING;
52055213
}
52065214
/* Try to yield virtual thread if it will be blocked */
5207-
rc = VM_ContinuationHelpers::preparePinnedVirtualThreadForUnmount(_currentThread, obj, true);
5208-
if (rc != J9_OBJECT_MONITOR_OOM) {
5215+
UDATA result = preparePinnedVirtualThreadForUnmount(_currentThread, object, true);
5216+
if (result != J9_OBJECT_MONITOR_OOM) {
52095217
rc = EXECUTE_BYTECODE;
52105218
/* Handle virutal thread Object.wait call. */
52115219
buildInternalNativeStackFrame(REGISTER_ARGS);
@@ -5713,9 +5721,6 @@ class INTERPRETER_CLASS
57135721
VM_BytecodeAction rc = EXECUTE_BYTECODE;
57145722

57155723
j9object_t continuationObject = *(j9object_t*)_sp;
5716-
#if JAVA_SPEC_VERSION >= 24
5717-
bool handleReturnCases = false;
5718-
#endif /* JAVA_SPEC_VERSION >= 24 */
57195724

57205725
buildInternalNativeStackFrame(REGISTER_ARGS);
57215726
updateVMStruct(REGISTER_ARGS);
@@ -5724,11 +5729,6 @@ class INTERPRETER_CLASS
57245729
_sendMethod = J9VMJDKINTERNALVMCONTINUATION_ENTER_METHOD(_currentThread->javaVM);
57255730
rc = GOTO_RUN_METHOD;
57265731
}
5727-
#if JAVA_SPEC_VERSION >= 24
5728-
else {
5729-
handleReturnCases = true;
5730-
}
5731-
#endif /* JAVA_SPEC_VERSION >= 24 */
57325732

57335733
VMStructHasBeenUpdated(REGISTER_ARGS);
57345734

@@ -8882,6 +8882,7 @@ class INTERPRETER_CLASS
88828882
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
88838883
#if JAVA_SPEC_VERSION >= 24
88848884
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
8885+
{
88858886
rc = EXECUTE_BYTECODE;
88868887
buildInternalNativeStackFrame(REGISTER_ARGS);
88878888
updateVMStruct(REGISTER_ARGS);
@@ -8904,6 +8905,7 @@ class INTERPRETER_CLASS
89048905
*/
89058906
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
89068907
break;
8908+
}
89078909
#endif /* JAVA_SPEC_VERSION >= 24 */
89088910
case J9_OBJECT_MONITOR_OOM:
89098911
rc = THROW_MONITOR_ALLOC_FAIL;

runtime/vm/ContinuationHelpers.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535

3636
extern "C" {
3737

38+
#if JAVA_SPEC_VERSION >= 24
39+
void preparePinnedVirtualThreadForMount(J9VMThread *currentThread, j9object_t contObj);
40+
#endif /* JAVA_SPEC_VERSION >= 24 */
41+
3842
BOOLEAN
3943
createContinuation(J9VMThread *currentThread, j9object_t continuationObject)
4044
{
@@ -641,17 +645,17 @@ releaseVThreadInspector(J9VMThread *currentThread, jobject thread)
641645

642646
#if JAVA_SPEC_VERSION >= 24
643647
void
644-
detachMonitorInfo(J9VMThread currentThread, J9ObjectMonitor *objectMonitor)
648+
detachMonitorInfo(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor)
645649
{
646-
J9ThreadAbstractMonitor *monitor = objectMonitor->monitor;
647-
monitor->owner = 1;
650+
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor*)objectMonitor->monitor;
651+
monitor->owner = (J9Thread*)1;
648652
objectMonitor->vthread = currentThread->threadObject;
649653
}
650654

651655
void
652656
updateMonitorInfo(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor)
653657
{
654-
J9ThreadAbstractMonitor *monitor = objectMonitor->monitor;
658+
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor*)objectMonitor->monitor;
655659
monitor->owner = currentThread->osThread;
656660
objectMonitor->vthread = NULL;
657661
}
@@ -660,41 +664,43 @@ void
660664
preparePinnedVirtualThreadForMount(J9VMThread *currentThread, j9object_t contObj)
661665
{
662666
if (0 < currentThread->ownedMonitorCount) {
663-
J9MonitorEnterRecord monitorRecords = currentThread->monitorEnterRecords;
664-
while (monitorRecords) {
667+
J9MonitorEnterRecord *monitorRecords = currentThread->monitorEnterRecords;
668+
while (NULL != monitorRecords) {
665669
j9object_t object = monitorRecords->object;
666670
j9objectmonitor_t lock = 0;
667671
J9ObjectMonitor *objectMonitor = NULL;
668672

669673
if (!LN_HAS_LOCKWORD(currentThread, object)) {
670674
objectMonitor = monitorTablePeek(currentThread->javaVM, object);
671675
} else {
672-
lwEA = J9OBJECT_MONITOR_EA(currentThread, object);
673-
lock = J9_LOAD_LOCKWORD(currentThread, lwEA);
676+
lock = J9OBJECT_MONITOR(currentThread, object);
674677
objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
675678
}
676679
updateMonitorInfo(currentThread, objectMonitor);
677680
}
678681
}
679-
J9VMJDKINTERALVMCONTINUATION_SET_BLOCKER(currentThread, contObj, NULL);
682+
J9VMJDKINTERNALVMCONTINUATION_SET_BLOCKER(currentThread, contObj, NULL);
680683
}
681684

682685
UDATA
683686
preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncObj, BOOLEAN isObjectWait)
684687
{
685-
UDATA result = J9_OBJECT_MONTIOR_YIELD_VIRTUAL;
688+
UDATA result = J9_OBJECT_MONITOR_YIELD_VIRTUAL;
689+
J9ObjectMonitor *syncObjectMonitor = NULL;
690+
j9objectmonitor_t lock = 0;
691+
j9object_t continuationObj = NULL;
692+
686693
if (0 < currentThread->ownedMonitorCount) {
687694
/* Inflate all owned monitors */
688-
J9MonitorEnterRecord monitorRecords = currentThread->monitorEnterRecords;
689-
while (monitorRecords) {
695+
J9MonitorEnterRecord *monitorRecords = currentThread->monitorEnterRecords;
696+
while (NULL != monitorRecords) {
690697
j9object_t object = monitorRecords->object;
691-
j9objectmonitor_t lock = 0;
692698
J9ObjectMonitor *objectMonitor = NULL;
693699

694700
if (!LN_HAS_LOCKWORD(currentThread, object)) {
695701
objectMonitor = monitorTablePeek(currentThread->javaVM, object);
696702
if (objectMonitor != NULL){
697-
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
703+
lock = J9_LOAD_LOCKWORD(currentThread, objectMonitor->alternateLockword);
698704
} else {
699705
lock = 0;
700706
}
@@ -705,7 +711,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
705711
if (!J9_LOCK_IS_INFLATED(lock)) {
706712
objectMonitor = objectMonitorInflate(currentThread, object, lock);
707713
if (NULL == objectMonitor) {
708-
result == J9_OBJECT_MONITOR_OOM;
714+
result = J9_OBJECT_MONITOR_OOM;
709715
goto done;
710716
}
711717
}
@@ -714,11 +720,10 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
714720
}
715721
}
716722

717-
J9ObjectMonitor *syncObjectMonitor = NULL;
718723
if (!LN_HAS_LOCKWORD(currentThread, syncObj)) {
719724
syncObjectMonitor = monitorTablePeek(currentThread->javaVM, syncObj);
720725
if (syncObjectMonitor != NULL){
721-
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
726+
lock = J9_LOAD_LOCKWORD(currentThread, syncObjectMonitor->alternateLockword);
722727
} else {
723728
lock = 0;
724729
}
@@ -729,14 +734,14 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
729734
if (!J9_LOCK_IS_INFLATED(lock)) {
730735
syncObjectMonitor = objectMonitorInflate(currentThread, syncObj, lock);
731736
if (NULL == syncObjectMonitor) {
732-
result == J9_OBJECT_MONITOR_OOM;
737+
result = J9_OBJECT_MONITOR_OOM;
733738
goto done;
734739
}
735740
}
736741

737742
syncObjectMonitor->virtualThreadWaitCount += 1;
738-
j9object_t continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, currentThread->threadObject);
739-
J9VMJDKINTERALVMCONTINUATION_SET_BLOCKER(currentThread, continuationObj, syncObj);
743+
continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, currentThread->threadObject);
744+
J9VMJDKINTERNALVMCONTINUATION_SET_BLOCKER(currentThread, continuationObj, syncObj);
740745

741746
if (isObjectWait) {
742747
/* Add thread object to monitor's waiting list. */

0 commit comments

Comments
 (0)