< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java

Print this page
*** 33,11 ***
   * http://creativecommons.org/publicdomain/zero/1.0/
   */
  
  package java.util.concurrent.locks;
  
! import jdk.internal.misc.VirtualThreads;
  import jdk.internal.misc.Unsafe;
  
  /**
   * Basic thread blocking primitives for creating locks and other
   * synchronization classes.
--- 33,13 ---
   * http://creativecommons.org/publicdomain/zero/1.0/
   */
  
  package java.util.concurrent.locks;
  
! import java.util.concurrent.TimeUnit;
+ import jdk.internal.access.JavaLangAccess;
+ import jdk.internal.access.SharedSecrets;
  import jdk.internal.misc.Unsafe;
  
  /**
   * Basic thread blocking primitives for creating locks and other
   * synchronization classes.

*** 174,11 ***
       *        this operation has no effect
       */
      public static void unpark(Thread thread) {
          if (thread != null) {
              if (thread.isVirtual()) {
!                 VirtualThreads.unpark(thread);
              } else {
                  U.unpark(thread);
              }
          }
      }
--- 176,11 ---
       *        this operation has no effect
       */
      public static void unpark(Thread thread) {
          if (thread != null) {
              if (thread.isVirtual()) {
!                 JLA.unparkVirtualThread(thread);
              } else {
                  U.unpark(thread);
              }
          }
      }

*** 214,11 ***
      public static void park(Object blocker) {
          Thread t = Thread.currentThread();
          setBlocker(t, blocker);
          try {
              if (t.isVirtual()) {
!                 VirtualThreads.park();
              } else {
                  U.park(false, 0L);
              }
          } finally {
              setBlocker(t, null);
--- 216,11 ---
      public static void park(Object blocker) {
          Thread t = Thread.currentThread();
          setBlocker(t, blocker);
          try {
              if (t.isVirtual()) {
!                 JLA.parkVirtualThread();
              } else {
                  U.park(false, 0L);
              }
          } finally {
              setBlocker(t, null);

*** 262,11 ***
          if (nanos > 0) {
              Thread t = Thread.currentThread();
              setBlocker(t, blocker);
              try {
                  if (t.isVirtual()) {
!                     VirtualThreads.park(nanos);
                  } else {
                      U.park(false, nanos);
                  }
              } finally {
                  setBlocker(t, null);
--- 264,11 ---
          if (nanos > 0) {
              Thread t = Thread.currentThread();
              setBlocker(t, blocker);
              try {
                  if (t.isVirtual()) {
!                     JLA.parkVirtualThread(nanos);
                  } else {
                      U.park(false, nanos);
                  }
              } finally {
                  setBlocker(t, null);

*** 309,15 ***
       */
      public static void parkUntil(Object blocker, long deadline) {
          Thread t = Thread.currentThread();
          setBlocker(t, blocker);
          try {
!             if (t.isVirtual()) {
-                 VirtualThreads.parkUntil(deadline);
-             } else {
-                 U.park(true, deadline);
-             }
          } finally {
              setBlocker(t, null);
          }
      }
  
--- 311,11 ---
       */
      public static void parkUntil(Object blocker, long deadline) {
          Thread t = Thread.currentThread();
          setBlocker(t, blocker);
          try {
!             parkUntil(deadline);
          } finally {
              setBlocker(t, null);
          }
      }
  

*** 364,11 ***
       * the thread to park in the first place. Callers may also determine,
       * for example, the interrupt status of the thread upon return.
       */
      public static void park() {
          if (Thread.currentThread().isVirtual()) {
!             VirtualThreads.park();
          } else {
              U.park(false, 0L);
          }
      }
  
--- 362,11 ---
       * the thread to park in the first place. Callers may also determine,
       * for example, the interrupt status of the thread upon return.
       */
      public static void park() {
          if (Thread.currentThread().isVirtual()) {
!             JLA.parkVirtualThread();
          } else {
              U.park(false, 0L);
          }
      }
  

*** 403,11 ***
       * @param nanos the maximum number of nanoseconds to wait
       */
      public static void parkNanos(long nanos) {
          if (nanos > 0) {
              if (Thread.currentThread().isVirtual()) {
!                 VirtualThreads.park(nanos);
              } else {
                  U.park(false, nanos);
              }
          }
      }
--- 401,11 ---
       * @param nanos the maximum number of nanoseconds to wait
       */
      public static void parkNanos(long nanos) {
          if (nanos > 0) {
              if (Thread.currentThread().isVirtual()) {
!                 JLA.parkVirtualThread(nanos);
              } else {
                  U.park(false, nanos);
              }
          }
      }

*** 442,11 ***
       * @param deadline the absolute time, in milliseconds from the Epoch,
       *        to wait until
       */
      public static void parkUntil(long deadline) {
          if (Thread.currentThread().isVirtual()) {
!             VirtualThreads.parkUntil(deadline);
          } else {
              U.park(true, deadline);
          }
      }
  
--- 440,12 ---
       * @param deadline the absolute time, in milliseconds from the Epoch,
       *        to wait until
       */
      public static void parkUntil(long deadline) {
          if (Thread.currentThread().isVirtual()) {
!             long millis = deadline - System.currentTimeMillis();
+             JLA.parkVirtualThread(TimeUnit.MILLISECONDS.toNanos(millis));
          } else {
              U.park(true, deadline);
          }
      }
  

*** 460,6 ***
--- 459,7 ---
      // Hotspot implementation via intrinsics API
      private static final Unsafe U = Unsafe.getUnsafe();
      private static final long PARKBLOCKER
          = U.objectFieldOffset(Thread.class, "parkBlocker");
  
+     private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
  }
< prev index next >