8230744: Several classes throw OutOfMemoryError without message

Reviewed-by: psandoz, martin, bchristi, rriggs, smarks
This commit is contained in:
Jim Laskey 2020-06-11 10:08:23 -03:00
parent 2085fd32ff
commit 03642a01af
9 changed files with 27 additions and 53 deletions

View file

@ -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;

View file

@ -1681,7 +1681,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
try {
newTempLen = Math.addExact(j + 2, Math.multiplyExact(3, pLen - i));
} catch (ArithmeticException ae) {
throw new OutOfMemoryError();
throw new OutOfMemoryError("Required pattern length too large");
}
int[] newtemp = new int[newTempLen];
System.arraycopy(temp, 0, newtemp, 0, j);