# HG changeset patch # User lagergren # Date 1372770098 -7200 # Node ID 433fc717df0e192e08edd95e08b57870e73bda29 # Parent c2138d47b2c6e1ccdf1ac03c47767114e7d443d7# Parent 93017277615e7381ea073f38e0b1e2913cea854f Merge diff -r 93017277615e -r 433fc717df0e nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java --- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Jul 02 18:00:15 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Jul 02 15:01:38 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(); diff -r 93017277615e -r 433fc717df0e nashorn/src/jdk/nashorn/internal/codegen/types/Type.java --- a/nashorn/src/jdk/nashorn/internal/codegen/types/Type.java Tue Jul 02 18:00:15 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/codegen/types/Type.java Tue Jul 02 15:01:38 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; } }; diff -r 93017277615e -r 433fc717df0e nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java --- a/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Tue Jul 02 18:00:15 2013 +0530 +++ b/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Tue Jul 02 15:01:38 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 { diff -r 93017277615e -r 433fc717df0e nashorn/test/script/basic/JDK-8017082.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8017082.js Tue Jul 02 15:01:38 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]; +}