mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8230744: Several classes throw OutOfMemoryError without message
Reviewed-by: psandoz, martin, bchristi, rriggs, smarks
This commit is contained in:
parent
2085fd32ff
commit
03642a01af
9 changed files with 27 additions and 53 deletions
|
@ -53,6 +53,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
|
||||
/**
|
||||
* An unbounded {@linkplain BlockingQueue blocking queue} that uses
|
||||
|
@ -136,14 +137,6 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
|
|||
*/
|
||||
private static final int DEFAULT_INITIAL_CAPACITY = 11;
|
||||
|
||||
/**
|
||||
* The maximum size of array to allocate.
|
||||
* Some VMs reserve some header words in an array.
|
||||
* Attempts to allocate larger arrays may result in
|
||||
* OutOfMemoryError: Requested array size exceeds VM limit
|
||||
*/
|
||||
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
|
||||
|
||||
/**
|
||||
* Priority queue represented as a balanced binary heap: the two
|
||||
* children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The
|
||||
|
@ -298,16 +291,9 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
|
|||
if (allocationSpinLock == 0 &&
|
||||
ALLOCATIONSPINLOCK.compareAndSet(this, 0, 1)) {
|
||||
try {
|
||||
int newCap = oldCap + ((oldCap < 64) ?
|
||||
(oldCap + 2) : // grow faster if small
|
||||
(oldCap >> 1));
|
||||
if (newCap - MAX_ARRAY_SIZE > 0) { // possible overflow
|
||||
int minCap = oldCap + 1;
|
||||
if (minCap < 0 || minCap > MAX_ARRAY_SIZE)
|
||||
throw new OutOfMemoryError();
|
||||
newCap = MAX_ARRAY_SIZE;
|
||||
}
|
||||
if (newCap > oldCap && queue == array)
|
||||
int growth = oldCap < 64 ? oldCap + 2 : oldCap >> 1;
|
||||
int newCap = ArraysSupport.newLength(oldCap, 1, growth);
|
||||
if (queue == array)
|
||||
newArray = new Object[newCap];
|
||||
} finally {
|
||||
allocationSpinLock = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue