提交 fe59d951 编写于 作者: L lagergren

8017082: Long array literals were slightly broken

Reviewed-by: sundar, attila
上级 e80ddc6e
......@@ -1110,7 +1110,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
* @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();
......
......@@ -36,6 +36,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.DUP_X2;
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.POP2;
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 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
@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;
}
};
......
......@@ -621,8 +621,10 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
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 @@ public abstract class LiteralNode<T> extends Node implements PropertyKey {
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 abstract class LiteralNode<T> extends Node implements PropertyKey {
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 {
......
/*
* 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];
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册