|
71 | 71 | import com.oracle.svm.core.monitor.MonitorSupport; |
72 | 72 | import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; |
73 | 73 | import com.oracle.svm.core.thread.JavaThreads; |
74 | | -import com.oracle.svm.core.thread.VirtualThreads; |
75 | 74 | import com.oracle.svm.core.util.VMError; |
76 | 75 |
|
77 | 76 | import jdk.vm.ci.meta.MetaAccessProvider; |
@@ -100,29 +99,18 @@ private int hashCodeSubst() { |
100 | 99 | } |
101 | 100 |
|
102 | 101 | @Substitute |
103 | | - @TargetElement(name = "wait", onlyWith = JDK17OrEarlier.class) |
| 102 | + @TargetElement(name = "wait") |
104 | 103 | 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 | + */ |
105 | 111 | MonitorSupport.singleton().wait(this, timeoutMillis); |
106 | 112 | } |
107 | 113 |
|
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 | | - |
126 | 114 | @Delete |
127 | 115 | @TargetElement(onlyWith = JDK19OrLater.class) |
128 | 116 | private native void wait0(long timeoutMillis); |
|
0 commit comments