changeset 1090:07755ae06bc9

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
author lagergren
date Mon, 03 Nov 2014 14:59:34 +0100
parents 4df3417e1a6e
children 569b6de2d343
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java	Mon Nov 03 13:58:52 2014 +0100
+++ b/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/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java	Mon Nov 03 13:58:52 2014 +0100
+++ b/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;