< prev index next >

src/java.base/share/classes/java/lang/Object.java

Print this page
*** 23,10 ***
--- 23,11 ---
   * questions.
   */
  
  package java.lang;
  
+ import jdk.internal.misc.Blocker;
  import jdk.internal.vm.annotation.IntrinsicCandidate;
  
  /**
   * Class {@code Object} is the root of the class hierarchy.
   * Every class has {@code Object} as a superclass. All objects,

*** 357,11 ***
       * @see    #notify()
       * @see    #notifyAll()
       * @see    #wait()
       * @see    #wait(long, int)
       */
!     public final native void wait(long timeoutMillis) throws InterruptedException;
  
      /**
       * Causes the current thread to wait until it is awakened, typically
       * by being <em>notified</em> or <em>interrupted</em>, or until a
       * certain amount of real time has elapsed.
--- 358,27 ---
       * @see    #notify()
       * @see    #notifyAll()
       * @see    #wait()
       * @see    #wait(long, int)
       */
!     public final void wait(long timeoutMillis) throws InterruptedException {
+         Thread thread = Thread.currentThread();
+         if (thread.isVirtual()) {
+             try {
+                 Blocker.managedBlock(() -> wait0(timeoutMillis));
+             } catch (Exception e) {
+                 if (e instanceof InterruptedException)
+                     thread.getAndClearInterrupt();
+                 throw e;
+             }
+         } else {
+             wait0(timeoutMillis);
+         }
+     }
+ 
+     // final modifier so method not in vtable
+     private final native void wait0(long timeoutMillis) throws InterruptedException;
  
      /**
       * Causes the current thread to wait until it is awakened, typically
       * by being <em>notified</em> or <em>interrupted</em>, or until a
       * certain amount of real time has elapsed.
< prev index next >