Skip to content

Commit 946e97f

Browse files
authored
Merge pull request eclipse-openj9#21361 from fengxue-IS/jep491-interrupt
Fix Object.wait logic for vthread
2 parents dd7725a + d79ddbf commit 946e97f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

runtime/oti/vmconstantpool.xml

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
270270
<fieldref class="java/lang/VirtualThread" name="next" signature="Ljava/lang/VirtualThread;" versions="24-"/>
271271
<fieldref class="java/lang/VirtualThread" name="notified" signature="Z" versions="24-"/>
272272
<fieldref class="java/lang/VirtualThread" name="onWaitingList" signature="Z" versions="24-"/>
273+
<fieldref class="java/lang/VirtualThread" name="timeout" signature="J" versions="24-"/>
273274

274275
<fieldref class="java/lang/Throwable" name="cause" signature="Ljava/lang/Throwable;"/>
275276
<fieldref class="java/lang/Throwable" name="detailMessage" signature="Ljava/lang/String;"/>

runtime/vm/BytecodeInterpreter.hpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -5228,6 +5228,10 @@ class INTERPRETER_CLASS
52285228
restoreInternalNativeStackFrame(REGISTER_ARGS);
52295229
/* Handle the virtual thread Object.wait call. */
52305230
J9VMJAVALANGVIRTUALTHREAD_SET_NOTIFIED(_currentThread, _currentThread->threadObject, JNI_FALSE);
5231+
/* VirtualThread.timeout is a private field used by both VM and JCL to temporarily hold
5232+
* the value of expected wait/park time before a wake up task is scheduled using the value.
5233+
*/
5234+
J9VMJAVALANGVIRTUALTHREAD_SET_TIMEOUT(_currentThread, _currentThread->threadObject, millis + (nanos / 1000000));
52315235
rc = yieldPinnedContinuation(REGISTER_ARGS, newState, J9VM_CONTINUATION_RETURN_FROM_OBJECT_WAIT);
52325236
} else {
52335237
rc = THROW_MONITOR_ALLOC_FAIL;
@@ -5777,7 +5781,18 @@ class INTERPRETER_CLASS
57775781
omrthread_monitor_t monitor = getMonitorForWait(_currentThread, waitObject);
57785782
monitor->count = _currentThread->currentContinuation->waitingMonitorEnterCount;
57795783
_currentThread->currentContinuation->waitingMonitorEnterCount = 0;
5780-
returnVoidFromINL(REGISTER_ARGS, 4);
5784+
_currentThread->ownedMonitorCount -= 1;
5785+
if (J9VMJAVALANGTHREAD_DEADINTERRUPT(_currentThread, _currentThread->threadObject)) {
5786+
/* Build a native frame on vthread stack before throwing exception. */
5787+
buildInternalNativeStackFrame(REGISTER_ARGS);
5788+
updateVMStruct(REGISTER_ARGS);
5789+
prepareForExceptionThrow(_currentThread);
5790+
setCurrentException(_currentThread, J9VMCONSTANTPOOL_JAVALANGINTERRUPTEDEXCEPTION, NULL);
5791+
VMStructHasBeenUpdated(REGISTER_ARGS);
5792+
rc = GOTO_THROW_CURRENT_EXCEPTION;
5793+
} else {
5794+
returnVoidFromINL(REGISTER_ARGS, 4);
5795+
}
57815796
}
57825797
break;
57835798
}

0 commit comments

Comments
 (0)