Skip to content

Commit d23de9f

Browse files
committed
In Object.wait, do not unnecessarily clear virtual thread interrupted status.
1 parent d05f810 commit d23de9f

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import com.oracle.svm.core.monitor.MonitorSupport;
7272
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
7373
import com.oracle.svm.core.thread.JavaThreads;
74-
import com.oracle.svm.core.thread.VirtualThreads;
7574
import com.oracle.svm.core.util.VMError;
7675

7776
import jdk.vm.ci.meta.MetaAccessProvider;
@@ -100,29 +99,18 @@ private int hashCodeSubst() {
10099
}
101100

102101
@Substitute
103-
@TargetElement(name = "wait", onlyWith = JDK17OrEarlier.class)
102+
@TargetElement(name = "wait")
104103
private void waitSubst(long timeoutMillis) throws InterruptedException {
104+
/*
105+
* JDK 19 and later: our monitor implementation does not pin virtual threads, so avoid
106+
* jdk.internal.misc.Blocker which expects and asserts that a virtual thread is pinned.
107+
* Also, we get interrupted on the virtual thread instead of the carrier thread, which
108+
* clears the carrier thread's interrupt status too, so we don't have to intercept an
109+
* InterruptedException from the carrier thread to clear the virtual thread interrupt.
110+
*/
105111
MonitorSupport.singleton().wait(this, timeoutMillis);
106112
}
107113

108-
/**
109-
* Our monitors do not pin virtual threads, so we must avoid {@code jdk.internal.misc.Blocker}
110-
* which expects and asserts that the virtual thread is pinned.
111-
*/
112-
@Substitute
113-
@TargetElement(name = "wait", onlyWith = JDK19OrLater.class)
114-
private void waitSubstJDK19(long timeoutMillis) throws InterruptedException {
115-
try {
116-
MonitorSupport.singleton().wait(this, timeoutMillis);
117-
} catch (InterruptedException e) {
118-
Thread thread = Thread.currentThread();
119-
if (VirtualThreads.isSupported() && VirtualThreads.singleton().isVirtual(thread)) {
120-
VirtualThreads.singleton().getAndClearInterrupt(thread);
121-
}
122-
throw e;
123-
}
124-
}
125-
126114
@Delete
127115
@TargetElement(onlyWith = JDK19OrLater.class)
128116
private native void wait0(long timeoutMillis);

0 commit comments

Comments
 (0)