8062490: Out of memory problems, as untouched array datas didn't go directly to SparseArrayDatas, but dragged very large int arrays around.
authorlagergren
Mon, 03 Nov 2014 14:59:34 +0100
changeset 27364 2c2e0dfec388
parent 27363 9722f0db287b
child 27365 6dd6e324d1c7
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
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Mon Nov 03 13:58:52 2014 +0100
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Mon Nov 03 14:59:34 2014 +0100
@@ -98,6 +98,10 @@
         @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;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java	Mon Nov 03 13:58:52 2014 +0100
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java	Mon Nov 03 14:59:34 2014 +0100
@@ -38,6 +38,11 @@
 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;