changeset 399:9396e42bae4f

8017082: Long array literals were slightly broken Reviewed-by: sundar, attila
author lagergren
date Tue, 02 Jul 2013 14:50:39 +0200
parents a7b82e333c31
children 69ec02d12a31
files src/jdk/nashorn/internal/codegen/CodeGenerator.java src/jdk/nashorn/internal/codegen/types/Type.java src/jdk/nashorn/internal/ir/LiteralNode.java test/script/basic/JDK-8017082.js
diffstat 4 files changed, 64 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 13:50:19 2013 +0200
+++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 14:50:39 2013 +0200
@@ -1110,7 +1110,7 @@
      * @return the method generator that was used
      */
     private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) {
-        assert arrayType == Type.INT_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;
+        assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY;
 
         final Node[]          nodes    = arrayLiteralNode.getValue();
         final Object          presets  = arrayLiteralNode.getPresets();
--- a/src/jdk/nashorn/internal/codegen/types/Type.java	Tue Jul 02 13:50:19 2013 +0200
+++ b/src/jdk/nashorn/internal/codegen/types/Type.java	Tue Jul 02 14:50:39 2013 +0200
@@ -36,6 +36,7 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.IALOAD;
 import static jdk.internal.org.objectweb.asm.Opcodes.IASTORE;
 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;
+import static jdk.internal.org.objectweb.asm.Opcodes.LALOAD;
 import static jdk.internal.org.objectweb.asm.Opcodes.LASTORE;
 import static jdk.internal.org.objectweb.asm.Opcodes.NEWARRAY;
 import static jdk.internal.org.objectweb.asm.Opcodes.POP;
@@ -43,6 +44,7 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.SWAP;
 import static jdk.internal.org.objectweb.asm.Opcodes.T_DOUBLE;
 import static jdk.internal.org.objectweb.asm.Opcodes.T_INT;
+import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
 
 import java.lang.invoke.MethodHandle;
 import java.util.Collections;
@@ -729,19 +731,19 @@
 
         @Override
         public Type aload(final MethodVisitor method) {
-            method.visitInsn(IALOAD);
-            return INT;
+            method.visitInsn(LALOAD);
+            return LONG;
         }
 
         @Override
         public Type newarray(final MethodVisitor method) {
-            method.visitIntInsn(NEWARRAY, T_INT);
+            method.visitIntInsn(NEWARRAY, T_LONG);
             return this;
         }
 
         @Override
         public Type getElementType() {
-            return INT;
+            return LONG;
         }
     };
 
--- a/src/jdk/nashorn/internal/ir/LiteralNode.java	Tue Jul 02 13:50:19 2013 +0200
+++ b/src/jdk/nashorn/internal/ir/LiteralNode.java	Tue Jul 02 14:50:39 2013 +0200
@@ -621,8 +621,10 @@
             elementType = Type.INT;
             analyzeElements();
 
-            if (elementType == Type.INT) {
+            if (elementType.isInteger()) {
                 presetIntArray();
+            } else if (elementType.isLong()) {
+                presetLongArray();
             } else if (elementType.isNumeric()) {
                 presetNumberArray();
             } else {
@@ -649,6 +651,25 @@
             postsets = Arrays.copyOf(computed, nComputed);
         }
 
+        private void presetLongArray() {
+            final long[] array = new long[value.length];
+            final int[] computed = new int[value.length];
+            int nComputed = 0;
+
+            for (int i = 0; i < value.length; i++) {
+                final Object element = objectAsConstant(value[i]);
+
+                if (element instanceof Number) {
+                    array[i] = ((Number)element).longValue();
+                } else {
+                    computed[nComputed++] = i;
+                }
+            }
+
+            presets = array;
+            postsets = Arrays.copyOf(computed, nComputed);
+        }
+
         private void presetNumberArray() {
             final double[] array = new double[value.length];
             final int[] computed = new int[value.length];
@@ -746,6 +767,8 @@
         public Type getType() {
             if (elementType.isInteger()) {
                 return Type.INT_ARRAY;
+            } else if (elementType.isLong()) {
+                return Type.LONG_ARRAY;
             } else if (elementType.isNumeric()) {
                 return Type.NUMBER_ARRAY;
             } else {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8017082.js	Tue Jul 02 14:50:39 2013 +0200
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Long array literals were broken
+ *
+ * @test
+ * @run
+ */
+function f() {
+    var z=  c>>e>>>0;
+    var x = [z];
+}