@@ -1731,7 +1731,7 @@ class INTERPRETER_CLASS
1731
1731
omrthread_monitor_exit (_vm->blockedVirtualThreadsMutex );
1732
1732
1733
1733
/* store the current Continuation state and swap to carrier thread stack */
1734
- yieldContinuation (_currentThread, FALSE );
1734
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_SYNC_METHOD );
1735
1735
1736
1736
VMStructHasBeenUpdated (REGISTER_ARGS);
1737
1737
restoreInternalNativeStackFrame (REGISTER_ARGS);
@@ -1833,7 +1833,7 @@ class INTERPRETER_CLASS
1833
1833
omrthread_monitor_exit (_vm->blockedVirtualThreadsMutex );
1834
1834
1835
1835
/* store the current Continuation state and swap to carrier thread stack */
1836
- yieldContinuation (_currentThread, FALSE );
1836
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_MONITOR_ENTER );
1837
1837
1838
1838
VMStructHasBeenUpdated (REGISTER_ARGS);
1839
1839
restoreInternalNativeStackFrame (REGISTER_ARGS);
@@ -1987,7 +1987,7 @@ class INTERPRETER_CLASS
1987
1987
omrthread_monitor_exit (_vm->blockedVirtualThreadsMutex );
1988
1988
1989
1989
/* store the current Continuation state and swap to carrier thread stack */
1990
- yieldContinuation (_currentThread, FALSE );
1990
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_MONITOR_ENTER );
1991
1991
1992
1992
VMStructHasBeenUpdated (REGISTER_ARGS);
1993
1993
restoreInternalNativeStackFrame (REGISTER_ARGS);
@@ -2382,7 +2382,7 @@ class INTERPRETER_CLASS
2382
2382
omrthread_monitor_exit (_vm->blockedVirtualThreadsMutex );
2383
2383
2384
2384
/* store the current Continuation state and swap to carrier thread stack */
2385
- yieldContinuation (_currentThread, FALSE );
2385
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_MONITOR_ENTER );
2386
2386
2387
2387
VMStructHasBeenUpdated (REGISTER_ARGS);
2388
2388
restoreInternalNativeStackFrame (REGISTER_ARGS);
@@ -5154,6 +5154,40 @@ class INTERPRETER_CLASS
5154
5154
j9object_t object = *(j9object_t *)(_sp + 3 );
5155
5155
buildInternalNativeStackFrame (REGISTER_ARGS);
5156
5156
updateVMStruct (REGISTER_ARGS);
5157
+ #if JAVA_SPEC_VERSION >= 24
5158
+ if (IS_JAVA_LANG_VIRTUALTHREAD (_currentThread, _currentThread->threadObject )
5159
+ && (0 == _currentThread->continuationPinCount )
5160
+ && (0 == _currentThread->callOutCount )
5161
+ ) {
5162
+ UDATA newState = JAVA_LANG_VIRTUALTHREAD_WAITING;
5163
+ if ((millis > 0 ) || (nanos > 0 )) {
5164
+ newState = JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING;
5165
+ }
5166
+ /* Try to yield virtual thread if it will be blocked */
5167
+ rc = VM_ContinuationHelpers::preparePinnedVirtualThreadForUnmount (_currentThread, obj, true );
5168
+ if (rc != J9_OBJECT_MONITOR_OOM) {
5169
+ rc = EXECUTE_BYTECODE;
5170
+ /* Handle virutal thread Object.wait call. */
5171
+ buildInternalNativeStackFrame (REGISTER_ARGS);
5172
+ updateVMStruct (REGISTER_ARGS);
5173
+
5174
+ J9VMJAVALANGVIRTUALTHREAD_SET_STATE (_currentThread, _currentThread->threadObject , newState);
5175
+
5176
+ /* store the current Continuation state and swap to carrier thread stack */
5177
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_OBJECT_WAIT);
5178
+
5179
+ VMStructHasBeenUpdated (REGISTER_ARGS);
5180
+ restoreInternalNativeStackFrame (REGISTER_ARGS);
5181
+ /* its going to return as if it were returning from continuation.enterImpl()
5182
+ * so we need to push the boolean return val
5183
+ */
5184
+ returnSingleFromINL (REGISTER_ARGS, JNI_FALSE, 1 );
5185
+ } else {
5186
+ rc = THROW_MONITOR_ALLOC_FAIL;
5187
+ }
5188
+ return rc;
5189
+ }
5190
+ #endif /* JAVA_SPEC_VERSION >= 24 */
5157
5191
IDATA waitResult = monitorWaitImpl (_currentThread, object, millis, nanos, TRUE );
5158
5192
VMStructHasBeenUpdated (REGISTER_ARGS);
5159
5193
if (0 == waitResult) {
@@ -5639,6 +5673,9 @@ class INTERPRETER_CLASS
5639
5673
VM_BytecodeAction rc = EXECUTE_BYTECODE;
5640
5674
5641
5675
j9object_t continuationObject = *(j9object_t *)_sp;
5676
+ #if JAVA_SPEC_VERSION >= 24
5677
+ bool handleReturnCases = false ;
5678
+ #endif /* JAVA_SPEC_VERSION >= 24 */
5642
5679
5643
5680
buildInternalNativeStackFrame (REGISTER_ARGS);
5644
5681
updateVMStruct (REGISTER_ARGS);
@@ -5647,6 +5684,11 @@ class INTERPRETER_CLASS
5647
5684
_sendMethod = J9VMJDKINTERNALVMCONTINUATION_ENTER_METHOD (_currentThread->javaVM );
5648
5685
rc = GOTO_RUN_METHOD;
5649
5686
}
5687
+ #if JAVA_SPEC_VERSION >= 24
5688
+ else {
5689
+ handleReturnCases = true ;
5690
+ }
5691
+ #endif /* JAVA_SPEC_VERSION >= 24 */
5650
5692
5651
5693
VMStructHasBeenUpdated (REGISTER_ARGS);
5652
5694
@@ -5655,6 +5697,22 @@ class INTERPRETER_CLASS
5655
5697
} else if (VM_VMHelpers::exceptionPending (_currentThread)) {
5656
5698
rc = GOTO_THROW_CURRENT_EXCEPTION;
5657
5699
}
5700
+ #if JAVA_SPEC_VERSION >= 24
5701
+ switch (_currentThread->currentContinuation ->returnState ) {
5702
+ case J9VM_CONTINUATION_RETURN_FROM_YIELD:
5703
+ case J9VM_CONTINUATION_RETURN_FROM_MONITOR_ENTER:
5704
+ break ;
5705
+ case J9VM_CONTINUATION_RETURN_FROM_OBJECT_WAIT:
5706
+ restoreInternalNativeStackFrame (REGISTER_ARGS);
5707
+ returnVoidFromINL (REGISTER_ARGS, 4 );
5708
+ break ;
5709
+ case J9VM_CONTINUATION_RETURN_FROM_SYNC_METHOD:
5710
+ UDATA *bp = ((UDATA*)(((J9SFMethodFrame*)_sp) + 1 )) - 1 ;
5711
+ restoreSpecialStackFrameLeavingArgs (REGISTER_ARGS, bp);
5712
+ rc = inlineSendTarget (REGISTER_ARGS, VM_MAYBE, VM_MAYBE, VM_MAYBE, VM_MAYBE);
5713
+ break ;
5714
+ }
5715
+ #endif /* JAVA_SPEC_VERSION >= 24 */
5658
5716
return rc;
5659
5717
}
5660
5718
@@ -5669,7 +5727,7 @@ class INTERPRETER_CLASS
5669
5727
updateVMStruct (REGISTER_ARGS);
5670
5728
5671
5729
/* store the current Continuation state and swap to carrier thread stack */
5672
- yieldContinuation (_currentThread, isFinished);
5730
+ yieldContinuation (_currentThread, isFinished, J9VM_CONTINUATION_RETURN_FROM_YIELD );
5673
5731
5674
5732
VMStructHasBeenUpdated (REGISTER_ARGS);
5675
5733
restoreInternalNativeStackFrame (REGISTER_ARGS);
@@ -8797,7 +8855,7 @@ class INTERPRETER_CLASS
8797
8855
omrthread_monitor_exit (_vm->blockedVirtualThreadsMutex );
8798
8856
8799
8857
/* store the current Continuation state and swap to carrier thread stack */
8800
- yieldContinuation (_currentThread, FALSE );
8858
+ yieldContinuation (_currentThread, FALSE , J9VM_CONTINUATION_RETURN_FROM_MONITOR_ENTER );
8801
8859
8802
8860
VMStructHasBeenUpdated (REGISTER_ARGS);
8803
8861
restoreInternalNativeStackFrame (REGISTER_ARGS);
0 commit comments