Skip to content

Commit 738cb02

Browse files
committed
add support for object.notify()
Signed-off-by: Jack Lu <[email protected]>
1 parent 3426d78 commit 738cb02

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

runtime/oti/j9nonbuilder.h

Lines changed: 1 addition & 0 deletions
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 waitingVirtualThreads;
17201721
#endif /* JAVA_SPEC_VERSION >= 24 */
17211722
} J9ObjectMonitor;
17221723

runtime/vm/BytecodeInterpreter.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,46 @@ class INTERPRETER_CLASS
29672967
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
29682968
{
29692969
if (VM_ObjectMonitor::getMonitorForNotify(_currentThread, receiver, &monitorPtr, true)) {
2970+
#if JAVA_SPEC_VERSION >= 24
2971+
j9objectmonitor_t lock;
2972+
j9objectmonitor_t *lockEA = NULL;
2973+
J9ObjectMonitor *objectMonitor = NULL;
2974+
if (!LN_HAS_LOCKWORD(_currentThread, receiver)) {
2975+
objectMonitor = monitorTableAt(_currentThread, receiver);
2976+
} else {
2977+
lockEA = J9OBJECT_MONITOR_EA(_currentThread, receiver);
2978+
lock = J9_LOAD_LOCKWORD(_currentThread, lockEA);
2979+
if (J9_LOCK_IS_INFLATED(lock)) {
2980+
objectMonitor = J9_INFLLOCK_OBJECT_MONITOR(lock);
2981+
}
2982+
}
2983+
2984+
if ((NULL != objectMonitor) && (NULL != objectMonitor->waitingVirtualThreads)) {
2985+
omrthread_monitor_enter(_vm->blockedVirtualThreadsMutex);
2986+
j9object_t head = objectMonitor->waitingVirtualThreads;
2987+
if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
2988+
objectMonitor->waitingVirtualThreads = J9VMJAVALANGVIRTUALTHREAD_NEXT(_currentThread, head);
2989+
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(_currentThread, head, _vm->blockedVirtualThreads);
2990+
_vm->blockedVirtualThreads = head;
2991+
} else {
2992+
j9object_t next = J9VMJAVALANGVIRTUALTHREAD_NEXT(_currentThread, head);
2993+
while (NULL != next) {
2994+
head = next;
2995+
next = J9VMJAVALANGVIRTUALTHREAD_NEXT(_currentThread, head);
2996+
}
2997+
J9VMJAVALANGVIRTUALTHREAD_SET_NEXT(_currentThread, head, _vm->blockedVirtualThreads);
2998+
_vm->blockedVirtualThreads = head;
2999+
objectMonitor->waitingVirtualThreads = NULL;
3000+
}
3001+
omrthread_monitor_notify(_vm->blockedVirtualThreadsMutex);
3002+
omrthread_monitor_exit(_vm->blockedVirtualThreadsMutex);
3003+
3004+
if (operation = J9_SINGLE_THREAD_MODE_OP_NOTIFY) {
3005+
returnVoidFromINL(REGISTER_ARGS, 1);
3006+
goto done;
3007+
}
3008+
}
3009+
#endif /* JAVA_SPEC_VERSION >= 24 */
29703010
if (0 != notifyFunction(monitorPtr)) {
29713011
buildInternalNativeStackFrame(REGISTER_ARGS);
29723012
rc = THROW_ILLEGAL_MONITOR_STATE;

0 commit comments

Comments
 (0)