8062490: Out of memory problems, as untouched array datas didn't go directly to SparseArrayDatas, but dragged very large int arrays around

Reviewed-by: attila, sundar
This commit is contained in:
Marcus Lagergren 2014-11-03 14:59:34 +01:00
parent 75d37c8e9c
commit d82a461e44
2 changed files with 9 additions and 0 deletions

View File

@ -98,6 +98,10 @@ public abstract class ArrayData {
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex > 0L) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) {
return new SparseArrayData(this, safeIndex + 1);
}
//known to fit in int
return toRealArrayData((int)safeIndex).ensure(safeIndex);
}
return this;

View File

@ -38,6 +38,11 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
class SparseArrayData extends ArrayData {
static final long MAX_DENSE_LENGTH = 16 * 512 * 1024;
static {
// we must break into sparse arrays before we require long indexes
assert MAX_DENSE_LENGTH <= Integer.MAX_VALUE;
}
/** Underlying array. */
private ArrayData underlying;