ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/PriorityBlockingQueue.java (file contents):
Revision 1.142 by jsr166, Thu Oct 17 01:51:38 2019 UTC vs.
Revision 1.143 by jsr166, Thu Jun 11 17:04:16 2020 UTC

# Line 24 | Line 24 | import java.util.concurrent.locks.Reentr
24   import java.util.function.Consumer;
25   import java.util.function.Predicate;
26   // OPENJDK import jdk.internal.access.SharedSecrets;
27 + import jdk.internal.util.ArraysSupport;
28  
29   /**
30   * An unbounded {@linkplain BlockingQueue blocking queue} that uses
# Line 108 | Line 109 | public class PriorityBlockingQueue<E> ex
109      private static final int DEFAULT_INITIAL_CAPACITY = 11;
110  
111      /**
111     * The maximum size of array to allocate.
112     * Some VMs reserve some header words in an array.
113     * Attempts to allocate larger arrays may result in
114     * OutOfMemoryError: Requested array size exceeds VM limit
115     */
116    private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
117
118    /**
112       * Priority queue represented as a balanced binary heap: the two
113       * children of queue[n] are queue[2*n+1] and queue[2*(n+1)].  The
114       * priority queue is ordered by comparator, or by the elements'
# Line 269 | Line 262 | public class PriorityBlockingQueue<E> ex
262          if (allocationSpinLock == 0 &&
263              ALLOCATIONSPINLOCK.compareAndSet(this, 0, 1)) {
264              try {
265 <                int newCap = oldCap + ((oldCap < 64) ?
266 <                                       (oldCap + 2) : // grow faster if small
267 <                                       (oldCap >> 1));
275 <                if (newCap - MAX_ARRAY_SIZE > 0) {    // possible overflow
276 <                    int minCap = oldCap + 1;
277 <                    if (minCap < 0 || minCap > MAX_ARRAY_SIZE)
278 <                        throw new OutOfMemoryError();
279 <                    newCap = MAX_ARRAY_SIZE;
280 <                }
281 <                if (newCap > oldCap && queue == array)
265 >                int growth = oldCap < 64 ? oldCap + 2 : oldCap >> 1;
266 >                int newCap = ArraysSupport.newLength(oldCap, 1, growth);
267 >                if (queue == array)
268                      newArray = new Object[newCap];
269              } finally {
270                  allocationSpinLock = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines