< prev index next >

src/java.base/share/classes/java/lang/ref/ReferenceQueue.java

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
--- 1,7 ---
  /*
!  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

*** 143,23 ***
          synchronized (lock) {
              return enqueue0(r);
          }
      }
  
-     private boolean tryDisablePreempt() {
-         if (Thread.currentThread().isVirtual() && ContinuationSupport.isSupported()) {
-             Continuation.pin();
-             return true;
-         } else {
-             return false;
-         }
-     }
- 
-     private void enablePreempt() {
-         Continuation.unpin();
-     }
- 
      /**
       * Polls this queue to see if a reference object is available.  If one is
       * available without further delay then it is removed from the queue and
       * returned.  Otherwise this method immediately returns {@code null}.
       *
--- 143,10 ---

*** 171,17 ***
          if (head == null)
              return null;
  
          // Prevent a virtual thread from being preempted as this could potentially
          // deadlock with a carrier that is polling the same reference queue.
!         boolean disabled = tryDisablePreempt();
          try {
              synchronized (lock) {
                  return poll0();
              }
          } finally {
!             if (disabled) enablePreempt();
          }
      }
  
      /**
       * Removes the next reference object in this queue, blocking until either
--- 158,17 ---
          if (head == null)
              return null;
  
          // Prevent a virtual thread from being preempted as this could potentially
          // deadlock with a carrier that is polling the same reference queue.
!         boolean pinned = Thread.currentThread().isVirtual() && ContinuationSupport.pinIfSupported();
          try {
              synchronized (lock) {
                  return poll0();
              }
          } finally {
!             if (pinned) Continuation.unpin();
          }
      }
  
      /**
       * Removes the next reference object in this queue, blocking until either
< prev index next >