< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI04/bi04t002/newclass02/java.base/java/lang/Object.java

Print this page
@@ -21,11 +21,10 @@
   * questions.
   */
  
  package java.lang;
  
- import jdk.internal.misc.Blocker;
  import nsk.jvmti.scenarios.bcinstr.BI04.bi04t002a;
  
  /**
   * Class <code>Object</code> is the root of the class hierarchy.
   * Every class has <code>Object</code> as a superclass. All objects,

@@ -366,25 +365,28 @@
       *             this exception is thrown.
       * @see        java.lang.Object#notify()
       * @see        java.lang.Object#notifyAll()
       */
      public final void wait(long timeoutMillis) throws InterruptedException {
-         if (!Thread.currentThread().isVirtual()) {
-             wait0(timeoutMillis);
-             return;
+         if (timeoutMillis < 0) {
+             throw new IllegalArgumentException("timeout value is negative");
          }
  
-         // virtual thread waiting
-         boolean attempted = Blocker.begin();
-         try {
+         if (Thread.currentThread() instanceof VirtualThread vthread) {
+             try {
+                 wait0(timeoutMillis);
+             } catch (InterruptedException e) {
+                 // virtual thread's interrupt status needs to be cleared
+                 vthread.getAndClearInterrupt();
+                 throw e;
+             } finally {
+                 if (timeoutMillis > 0) {
+                     vthread.cancelWaitTimeout();
+                 }
+             }
+         } else {
              wait0(timeoutMillis);
-         } catch (InterruptedException e) {
-             // virtual thread's interrupt status needs to be cleared
-             Thread.currentThread().getAndClearInterrupt();
-             throw e;
-         } finally {
-             Blocker.end(attempted);
          }
      }
  
      /**
       * Causes current thread to wait until another thread invokes the

@@ -459,15 +461,15 @@
          if (nanos < 0 || nanos > 999999) {
              throw new IllegalArgumentException(
                                  "nanosecond timeout value out of range");
          }
  
-             if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
-                 timeout++;
-             }
+         if (nanos > 0 && timeout < Long.MAX_VALUE) {
+             timeout++;
+         }
  
-             wait(timeout);
+         wait(timeout);
      }
  
      // final modifier so method not in vtable
      private final native void wait0(long timeoutMillis) throws InterruptedException;
  
< prev index next >