234 endWait();
235 status.print();
236 }
237
238
239 public static void main(String[] args) throws Exception {
240 runnable();
241 blockedOnMonitorEnter();
242 waiting(false);
243 waiting(true);
244 sleeping();
245 parked();
246 inNative();
247
248 int errCount = getErrorCount();
249 if (errCount > 0) {
250 throw new RuntimeException("Test failed, " + errCount + " errors");
251 }
252 }
253
254 private static Thread createPinnedVThread(Runnable runnable) {
255 final Object syncObj = new Object();
256 return Thread.ofVirtual().unstarted(() -> {
257 synchronized (syncObj) {
258 runnable.run();
259 }
260 });
261 }
262
263 // Native implementation of suspendWaiting.
264 // Returns false if the method is not able to reach the desired state in several tries.
265 private static native boolean trySuspendInWaitingState(Thread vthread);
266
267 // Suspends virtual thread and ensures it's suspended in "waiting" state
268 // (to handle possible spurious wakeups).
269 // throws an exception if the method is not able to reach the desired state in several tries.
270 private static void suspendWaiting(Thread vthread) {
271 boolean result = trySuspendInWaitingState(vthread);
272 if (!result) {
273 throw new RuntimeException("Failed to suspend thread in WAITING state");
274 }
275 }
276
277 // Tests thread states (vthread and the carrier thread).
278 // expectedStrong specifies value which must be present in vthreat state;
279 // expectedWeak is a combination of bits which may be set in vthreat state
280 // (at least one of the bit must set, but not all).
|
234 endWait();
235 status.print();
236 }
237
238
239 public static void main(String[] args) throws Exception {
240 runnable();
241 blockedOnMonitorEnter();
242 waiting(false);
243 waiting(true);
244 sleeping();
245 parked();
246 inNative();
247
248 int errCount = getErrorCount();
249 if (errCount > 0) {
250 throw new RuntimeException("Test failed, " + errCount + " errors");
251 }
252 }
253
254 private static native void runFromNative(Runnable runnable);
255
256 private static Thread createPinnedVThread(Runnable runnable) {
257 return Thread.ofVirtual().unstarted(() -> runFromNative(runnable));
258 }
259
260 private static void runUpcall(Runnable runnable) {
261 runnable.run();
262 }
263
264 // Native implementation of suspendWaiting.
265 // Returns false if the method is not able to reach the desired state in several tries.
266 private static native boolean trySuspendInWaitingState(Thread vthread);
267
268 // Suspends virtual thread and ensures it's suspended in "waiting" state
269 // (to handle possible spurious wakeups).
270 // throws an exception if the method is not able to reach the desired state in several tries.
271 private static void suspendWaiting(Thread vthread) {
272 boolean result = trySuspendInWaitingState(vthread);
273 if (!result) {
274 throw new RuntimeException("Failed to suspend thread in WAITING state");
275 }
276 }
277
278 // Tests thread states (vthread and the carrier thread).
279 // expectedStrong specifies value which must be present in vthreat state;
280 // expectedWeak is a combination of bits which may be set in vthreat state
281 // (at least one of the bit must set, but not all).
|