aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlagergren <none@none>2014-11-03 14:59:34 +0100
committerlagergren <none@none>2014-11-03 14:59:34 +0100
commitc6df9349f77eaef0e74369680c06bc33e219eb3b (patch)
treea4242ef59df614ddbd56b073b66ff72f60e74769
parenta68d5e254221f6afa50d5bd09813a2eca99f5ca1 (diff)
downloadnashorn-c6df9349f77eaef0e74369680c06bc33e219eb3b.tar.gz
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
-rw-r--r--src/jdk/nashorn/internal/runtime/arrays/ArrayData.java4
-rw-r--r--src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java5
2 files changed, 9 insertions, 0 deletions
diff --git a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
index dc41c4d9..dd27612b 100644
--- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
+++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java
@@ -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;
diff --git a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java
index ef473451..61fb420f 100644
--- a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java
+++ b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java
@@ -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;