Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Lu <[email protected]>
  • Loading branch information
fengxue-IS committed Feb 4, 2025
1 parent 738cb02 commit c982de9
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 43 deletions.
7 changes: 7 additions & 0 deletions runtime/j9vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ target_link_libraries(jvm_common
${OMR_PLATFORM_THREAD_LIBRARY}
)

if(NOT JAVA_SPEC_VERSION LESS 24)
target_link_libraries(jvm_common
INTERFACE
j9thr
)
endif()

target_include_directories(jvm_common
INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
Expand Down
25 changes: 17 additions & 8 deletions runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "VMHelpers.hpp"
#include "ContinuationHelpers.hpp"
#endif /* JAVA_SPEC_VERSION >= 19 */
#if JAVA_SPEC_VERSION >= 24
#include "j9protos.h"
#endif /* JAVA_SPEC_VERSION >= 24 */

extern "C" {

Expand Down Expand Up @@ -731,8 +734,11 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
{
J9VMThread *currentThread = (J9VMThread *)env;
J9JavaVM *vm = currentThread->javaVM;
J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions;
j9object_t unblockedList = NULL;
jobject result = NULL;

vmFuncs->internalEnterVMFromJNI(currentThread);
while (NULL == unblockedList) {
if (NULL != vm->blockedVirtualThreads) {
omrthread_monitor_enter(vm->blockedVirtualThreadsMutex);
Expand All @@ -747,17 +753,18 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
unblocked = true;
} else {
j9object_t continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, listHead);
j9object_t syncObject = J9VMJDKINTERALVMCONTINUATION_BLOCKER(currentThread, continuationObj);
j9object_t syncObject = J9VMJDKINTERNALVMCONTINUATION_BLOCKER(currentThread, continuationObj);
J9ObjectMonitor* syncObjectMonitor = NULL;
if (!LN_HAS_LOCKWORD(currentThread, syncObj)) {
syncObjectMonitor = monitorTablePeek(currentThread->javaVM, syncObject);
j9objectmonitor_t lock = 0;
if (!LN_HAS_LOCKWORD(currentThread, syncObject)) {
syncObjectMonitor = vmFuncs->monitorTablePeek(vm, syncObject);
if (syncObjectMonitor != NULL){
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
lock = J9_LOAD_LOCKWORD_VM(vm, syncObjectMonitor->alternateLockword);
}
} else {
lock = J9OBJECT_MONITOR(currentThread, syncObject);
}
J9ThreadAbstractMonitor *monitor = getInflatedObjectMonitor(vm, object, lock);
J9ThreadAbstractMonitor *monitor = getInflatedObjectMonitor(vm, syncObject, lock);
if (0 == monitor->count) {
unblocked = true;
if (syncObjectMonitor->virtualThreadWaitCount >= 1) {
Expand All @@ -771,8 +778,8 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, unblockedList);
unblockedList = listHead;
} else {
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, vm->blockedVirtualThreadsMutex);
vm->blockedVirtualThreadsMutex = listHead;
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(currentThread, listHead, vm->blockedVirtualThreads);
vm->blockedVirtualThreads = listHead;
}
listHead = next;
}
Expand All @@ -781,12 +788,14 @@ JVM_TakeVirtualThreadListToUnblock(JNIEnv* env, jclass ignored)
goto restart;
} else {
omrthread_monitor_exit(vm->blockedVirtualThreadsMutex);
result = vmFuncs->j9jni_createLocalRef(env, unblockedList);
break;
}
}
}
vmFuncs->internalExitVMToJNI(currentThread);

return unblockedList;
return result;
}
#endif /* JAVA_SPEC_VERSION >= 24 */

Expand Down
6 changes: 5 additions & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ typedef struct J9ObjectMonitor {
U_32 hash;
#if JAVA_SPEC_VERSION >= 24
U_32 virtualThreadWaitCount;
j9object_t vthread;
j9object_t waitingVirtualThreads;
#endif /* JAVA_SPEC_VERSION >= 24 */
} J9ObjectMonitor;
Expand Down Expand Up @@ -5321,6 +5322,9 @@ typedef struct J9InternalVMFunctions {
struct J9Class * (*initializeSnapshotClassObject)(struct J9JavaVM *javaVM, struct J9ClassLoader *classLoader, struct J9Class *clazz);
BOOLEAN (*loadWarmClassFromSnapshot)(struct J9VMThread *vmThread, struct J9ClassLoader *classLoader, struct J9Class *clazz);
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
#if JAVA_SPEC_VERSION >= 24
J9ObjectMonitor * (*monitorTablePeek)(struct J9JavaVM *vm, j9object_t object);
#endif /* JAVA_SPEC_VERSION >= 24 */
} J9InternalVMFunctions;

/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */
Expand Down Expand Up @@ -6388,7 +6392,7 @@ typedef struct J9JavaVM {
#define J9_OBJECT_MONITOR_CRIU_SINGLE_THREAD_MODE_THROW 2
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
#define J9_OBJECT_MONTIOR_YIELD_VIRTUAL 3
#define J9_OBJECT_MONITOR_YIELD_VIRTUAL 3
#endif /* JAVA_SPEC_VERSION >= 24 */
#define J9_OBJECT_MONITOR_BLOCKING 4

Expand Down
10 changes: 10 additions & 0 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,16 @@ monitorTableAt(J9VMThread* vmStruct, j9object_t object);
void
cacheObjectMonitorForLookup(J9JavaVM* vm, J9VMThread* vmStruct, J9ObjectMonitor* objectMonitor);

/* ---------------- thrinfo.c ---------------- */

/**
* @brief Search vm->monitorTable for the inflated monitor corresponding to an object.
* @param vm
* @param object
* @return J9ObjectMonitor *
*/
J9ObjectMonitor *
monitorTablePeek(J9JavaVM *vm, j9object_t object);

/* ---------------- PackageIDHashTable.c ---------------- */

Expand Down
28 changes: 15 additions & 13 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ class INTERPRETER_CLASS
&& (0 == _currentThread->callOutCount)
) {
/* Try to yield virtual thread if it will be blocked */
rc = VM_ContinuationHelpers::preparePinnedVirtualThreadForUnmount(_currentThread, obj);
rc = preparePinnedVirtualThreadForUnmount(_currentThread, obj, false);
} else
#endif /* JAVA_SPEC_VERSION >= 24 */
{
Expand Down Expand Up @@ -1718,6 +1718,7 @@ class INTERPRETER_CLASS
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
{
rc = EXECUTE_BYTECODE;
buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -1740,6 +1741,7 @@ class INTERPRETER_CLASS
*/
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
break;
}
#endif /* JAVA_SPEC_VERSION >= 24 */
case J9_OBJECT_MONITOR_OOM:
rc = THROW_MONITOR_ALLOC_FAIL;
Expand Down Expand Up @@ -1820,6 +1822,7 @@ class INTERPRETER_CLASS
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
{
rc = EXECUTE_BYTECODE;
buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -1842,6 +1845,7 @@ class INTERPRETER_CLASS
*/
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
break;
}
#endif /* JAVA_SPEC_VERSION >= 24 */
case J9_OBJECT_MONITOR_OOM:
/* Monitor was not entered - hide the frame to prevent exception throw from processing it.
Expand Down Expand Up @@ -1974,6 +1978,7 @@ class INTERPRETER_CLASS
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
{
rc = EXECUTE_BYTECODE;
buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -1996,6 +2001,7 @@ class INTERPRETER_CLASS
*/
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
break;
}
#endif /* JAVA_SPEC_VERSION >= 24 */
case J9_OBJECT_MONITOR_OOM:
rc = THROW_MONITOR_ALLOC_FAIL;
Expand Down Expand Up @@ -2369,6 +2375,7 @@ class INTERPRETER_CLASS
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
{
rc = EXECUTE_BYTECODE;
buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -2391,6 +2398,7 @@ class INTERPRETER_CLASS
*/
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
break;
}
#endif /* JAVA_SPEC_VERSION >= 24 */
case J9_OBJECT_MONITOR_OOM:
rc = THROW_MONITOR_ALLOC_FAIL;
Expand Down Expand Up @@ -2984,7 +2992,7 @@ class INTERPRETER_CLASS
if ((NULL != objectMonitor) && (NULL != objectMonitor->waitingVirtualThreads)) {
omrthread_monitor_enter(_vm->blockedVirtualThreadsMutex);
j9object_t head = objectMonitor->waitingVirtualThreads;
if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
if (omrthread_monitor_notify == notifyFunction) {
objectMonitor->waitingVirtualThreads = J9VMJAVALANGVIRTUALTHREAD_NEXT(_currentThread, head);
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(_currentThread, head, _vm->blockedVirtualThreads);
_vm->blockedVirtualThreads = head;
Expand All @@ -3001,7 +3009,7 @@ class INTERPRETER_CLASS
omrthread_monitor_notify(_vm->blockedVirtualThreadsMutex);
omrthread_monitor_exit(_vm->blockedVirtualThreadsMutex);

if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
if (omrthread_monitor_notify == notifyFunction) {
returnVoidFromINL(REGISTER_ARGS, 1);
goto done;
}
Expand Down Expand Up @@ -5204,8 +5212,8 @@ class INTERPRETER_CLASS
newState = JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING;
}
/* Try to yield virtual thread if it will be blocked */
rc = VM_ContinuationHelpers::preparePinnedVirtualThreadForUnmount(_currentThread, obj, true);
if (rc != J9_OBJECT_MONITOR_OOM) {
UDATA result = preparePinnedVirtualThreadForUnmount(_currentThread, object, true);
if (result != J9_OBJECT_MONITOR_OOM) {
rc = EXECUTE_BYTECODE;
/* Handle virutal thread Object.wait call. */
buildInternalNativeStackFrame(REGISTER_ARGS);
Expand Down Expand Up @@ -5713,9 +5721,6 @@ class INTERPRETER_CLASS
VM_BytecodeAction rc = EXECUTE_BYTECODE;

j9object_t continuationObject = *(j9object_t*)_sp;
#if JAVA_SPEC_VERSION >= 24
bool handleReturnCases = false;
#endif /* JAVA_SPEC_VERSION >= 24 */

buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -5724,11 +5729,6 @@ class INTERPRETER_CLASS
_sendMethod = J9VMJDKINTERNALVMCONTINUATION_ENTER_METHOD(_currentThread->javaVM);
rc = GOTO_RUN_METHOD;
}
#if JAVA_SPEC_VERSION >= 24
else {
handleReturnCases = true;
}
#endif /* JAVA_SPEC_VERSION >= 24 */

VMStructHasBeenUpdated(REGISTER_ARGS);

Expand Down Expand Up @@ -8882,6 +8882,7 @@ class INTERPRETER_CLASS
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
#if JAVA_SPEC_VERSION >= 24
case J9_OBJECT_MONITOR_YIELD_VIRTUAL:
{
rc = EXECUTE_BYTECODE;
buildInternalNativeStackFrame(REGISTER_ARGS);
updateVMStruct(REGISTER_ARGS);
Expand All @@ -8904,6 +8905,7 @@ class INTERPRETER_CLASS
*/
returnSingleFromINL(REGISTER_ARGS, JNI_FALSE, 1);
break;
}
#endif /* JAVA_SPEC_VERSION >= 24 */
case J9_OBJECT_MONITOR_OOM:
rc = THROW_MONITOR_ALLOC_FAIL;
Expand Down
45 changes: 25 additions & 20 deletions runtime/vm/ContinuationHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

extern "C" {

#if JAVA_SPEC_VERSION >= 24
void preparePinnedVirtualThreadForMount(J9VMThread *currentThread, j9object_t contObj);
#endif /* JAVA_SPEC_VERSION >= 24 */

BOOLEAN
createContinuation(J9VMThread *currentThread, j9object_t continuationObject)
{
Expand Down Expand Up @@ -641,17 +645,17 @@ releaseVThreadInspector(J9VMThread *currentThread, jobject thread)

#if JAVA_SPEC_VERSION >= 24
void
detachMonitorInfo(J9VMThread currentThread, J9ObjectMonitor *objectMonitor)
detachMonitorInfo(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor)
{
J9ThreadAbstractMonitor *monitor = objectMonitor->monitor;
monitor->owner = 1;
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor*)objectMonitor->monitor;
monitor->owner = (J9Thread*)1;
objectMonitor->vthread = currentThread->threadObject;
}

void
updateMonitorInfo(J9VMThread *currentThread, J9ObjectMonitor *objectMonitor)
{
J9ThreadAbstractMonitor *monitor = objectMonitor->monitor;
J9ThreadAbstractMonitor *monitor = (J9ThreadAbstractMonitor*)objectMonitor->monitor;
monitor->owner = currentThread->osThread;
objectMonitor->vthread = NULL;
}
Expand All @@ -660,41 +664,43 @@ void
preparePinnedVirtualThreadForMount(J9VMThread *currentThread, j9object_t contObj)
{
if (0 < currentThread->ownedMonitorCount) {
J9MonitorEnterRecord monitorRecords = currentThread->monitorEnterRecords;
while (monitorRecords) {
J9MonitorEnterRecord *monitorRecords = currentThread->monitorEnterRecords;
while (NULL != monitorRecords) {
j9object_t object = monitorRecords->object;
j9objectmonitor_t lock = 0;
J9ObjectMonitor *objectMonitor = NULL;

if (!LN_HAS_LOCKWORD(currentThread, object)) {
objectMonitor = monitorTablePeek(currentThread->javaVM, object);
} else {
lwEA = J9OBJECT_MONITOR_EA(currentThread, object);
lock = J9_LOAD_LOCKWORD(currentThread, lwEA);
lock = J9OBJECT_MONITOR(currentThread, object);
objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
}
updateMonitorInfo(currentThread, objectMonitor);
}
}
J9VMJDKINTERALVMCONTINUATION_SET_BLOCKER(currentThread, contObj, NULL);
J9VMJDKINTERNALVMCONTINUATION_SET_BLOCKER(currentThread, contObj, NULL);
}

UDATA
preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncObj, BOOLEAN isObjectWait)
{
UDATA result = J9_OBJECT_MONTIOR_YIELD_VIRTUAL;
UDATA result = J9_OBJECT_MONITOR_YIELD_VIRTUAL;
J9ObjectMonitor *syncObjectMonitor = NULL;
j9objectmonitor_t lock = 0;
j9object_t continuationObj = NULL;

if (0 < currentThread->ownedMonitorCount) {
/* Inflate all owned monitors */
J9MonitorEnterRecord monitorRecords = currentThread->monitorEnterRecords;
while (monitorRecords) {
J9MonitorEnterRecord *monitorRecords = currentThread->monitorEnterRecords;
while (NULL != monitorRecords) {
j9object_t object = monitorRecords->object;
j9objectmonitor_t lock = 0;
J9ObjectMonitor *objectMonitor = NULL;

if (!LN_HAS_LOCKWORD(currentThread, object)) {
objectMonitor = monitorTablePeek(currentThread->javaVM, object);
if (objectMonitor != NULL){
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
lock = J9_LOAD_LOCKWORD(currentThread, objectMonitor->alternateLockword);
} else {
lock = 0;
}
Expand All @@ -705,7 +711,7 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
if (!J9_LOCK_IS_INFLATED(lock)) {
objectMonitor = objectMonitorInflate(currentThread, object, lock);
if (NULL == objectMonitor) {
result == J9_OBJECT_MONITOR_OOM;
result = J9_OBJECT_MONITOR_OOM;
goto done;
}
}
Expand All @@ -714,11 +720,10 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
}
}

J9ObjectMonitor *syncObjectMonitor = NULL;
if (!LN_HAS_LOCKWORD(currentThread, syncObj)) {
syncObjectMonitor = monitorTablePeek(currentThread->javaVM, syncObj);
if (syncObjectMonitor != NULL){
lock = J9_LOAD_LOCKWORD_VM(vm, &objectMonitor->alternateLockword);
lock = J9_LOAD_LOCKWORD(currentThread, syncObjectMonitor->alternateLockword);
} else {
lock = 0;
}
Expand All @@ -729,14 +734,14 @@ preparePinnedVirtualThreadForUnmount(J9VMThread *currentThread, j9object_t syncO
if (!J9_LOCK_IS_INFLATED(lock)) {
syncObjectMonitor = objectMonitorInflate(currentThread, syncObj, lock);
if (NULL == syncObjectMonitor) {
result == J9_OBJECT_MONITOR_OOM;
result = J9_OBJECT_MONITOR_OOM;
goto done;
}
}

syncObjectMonitor->virtualThreadWaitCount += 1;
j9object_t continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, currentThread->threadObject);
J9VMJDKINTERALVMCONTINUATION_SET_BLOCKER(currentThread, continuationObj, syncObj);
continuationObj = J9VMJAVALANGVIRTUALTHREAD_CONT(currentThread, currentThread->threadObject);
J9VMJDKINTERNALVMCONTINUATION_SET_BLOCKER(currentThread, continuationObj, syncObj);

if (isObjectWait) {
/* Add thread object to monitor's waiting list. */
Expand Down
Loading

0 comments on commit c982de9

Please sign in to comment.