@@ -5216,21 +5216,26 @@ class INTERPRETER_CLASS
5216
5216
updateVMStruct (REGISTER_ARGS);
5217
5217
#if JAVA_SPEC_VERSION >= 24
5218
5218
if (VM_ContinuationHelpers::isYieldableVirtualThread (_currentThread)) {
5219
- UDATA newState = JAVA_LANG_VIRTUALTHREAD_WAITING;
5220
- if ((millis > 0 ) || (nanos > 0 )) {
5221
- newState = JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING;
5222
- }
5223
- /* Try to yield the virtual thread if it will be blocked. */
5224
- UDATA result = preparePinnedVirtualThreadForUnmount (_currentThread, object, true );
5225
- VMStructHasBeenUpdated (REGISTER_ARGS);
5226
- if (J9_OBJECT_MONITOR_OOM != result) {
5227
- restoreInternalNativeStackFrame (REGISTER_ARGS);
5228
- /* Handle the virtual thread Object.wait call. */
5229
- J9VMJAVALANGVIRTUALTHREAD_SET_NOTIFIED (_currentThread, _currentThread->threadObject , JNI_FALSE);
5230
- rc = yieldPinnedContinuation (REGISTER_ARGS, newState, J9VM_CONTINUATION_RETURN_FROM_OBJECT_WAIT);
5219
+ if (getObjectMonitorOwner (_vm, object, NULL ) == _currentThread) {
5220
+ UDATA newState = JAVA_LANG_VIRTUALTHREAD_WAITING;
5221
+ if ((millis > 0 ) || (nanos > 0 )) {
5222
+ newState = JAVA_LANG_VIRTUALTHREAD_TIMED_WAITING;
5223
+ }
5224
+ /* Try to yield the virtual thread if it will be blocked. */
5225
+ UDATA result = preparePinnedVirtualThreadForUnmount (_currentThread, object, true );
5226
+ VMStructHasBeenUpdated (REGISTER_ARGS);
5227
+ if (J9_OBJECT_MONITOR_OOM != result) {
5228
+ restoreInternalNativeStackFrame (REGISTER_ARGS);
5229
+ /* Handle the virtual thread Object.wait call. */
5230
+ J9VMJAVALANGVIRTUALTHREAD_SET_NOTIFIED (_currentThread, _currentThread->threadObject , JNI_FALSE);
5231
+ rc = yieldPinnedContinuation (REGISTER_ARGS, newState, J9VM_CONTINUATION_RETURN_FROM_OBJECT_WAIT);
5232
+ } else {
5233
+ rc = THROW_MONITOR_ALLOC_FAIL;
5234
+ }
5231
5235
} else {
5232
- rc = THROW_MONITOR_ALLOC_FAIL ;
5236
+ rc = THROW_ILLEGAL_MONITOR_STATE ;
5233
5237
}
5238
+
5234
5239
return rc;
5235
5240
}
5236
5241
#endif /* JAVA_SPEC_VERSION >= 24 */
0 commit comments