Thu, 23 May 2013 13:10:58 +0200
8012083: Array literal constant folding issue
Reviewed-by: attila, jlaskey
1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Thu May 23 12:01:35 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Thu May 23 13:10:58 2013 +0200 1.3 @@ -2295,7 +2295,7 @@ 1.4 @Override 1.5 public boolean enterADD(final UnaryNode unaryNode) { 1.6 load(unaryNode.rhs()); 1.7 - assert unaryNode.rhs().getType().isNumber(); 1.8 + assert unaryNode.rhs().getType().isNumber() : unaryNode.rhs().getType() + " "+ unaryNode.getSymbol(); 1.9 method.store(unaryNode.getSymbol()); 1.10 1.11 return false;
2.1 --- a/src/jdk/nashorn/internal/codegen/FinalizeTypes.java Thu May 23 12:01:35 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/codegen/FinalizeTypes.java Thu May 23 13:10:58 2013 +0200 2.3 @@ -800,7 +800,7 @@ 2.4 2.5 Node resultNode = node; 2.6 2.7 - if (node instanceof LiteralNode && !to.isObject()) { 2.8 + if (node instanceof LiteralNode && !(node instanceof ArrayLiteralNode) && !to.isObject()) { 2.9 final LiteralNode<?> newNode = new LiteralNodeConstantEvaluator((LiteralNode<?>)node, to).eval(); 2.10 if (newNode != null) { 2.11 resultNode = newNode;
3.1 --- a/src/jdk/nashorn/internal/codegen/FoldConstants.java Thu May 23 12:01:35 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/codegen/FoldConstants.java Thu May 23 13:10:58 2013 +0200 3.3 @@ -34,6 +34,7 @@ 3.4 import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 3.5 import jdk.nashorn.internal.ir.IfNode; 3.6 import jdk.nashorn.internal.ir.LiteralNode; 3.7 +import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; 3.8 import jdk.nashorn.internal.ir.Node; 3.9 import jdk.nashorn.internal.ir.TernaryNode; 3.10 import jdk.nashorn.internal.ir.UnaryNode; 3.11 @@ -141,6 +142,10 @@ 3.12 return null; 3.13 } 3.14 3.15 + if (rhsNode instanceof ArrayLiteralNode) { 3.16 + return null; 3.17 + } 3.18 + 3.19 final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode; 3.20 final boolean rhsInteger = rhs.getType().isInteger(); 3.21 3.22 @@ -212,6 +217,10 @@ 3.23 final LiteralNode<?> lhs = (LiteralNode<?>)parent.lhs(); 3.24 final LiteralNode<?> rhs = (LiteralNode<?>)parent.rhs(); 3.25 3.26 + if (lhs instanceof ArrayLiteralNode || rhs instanceof ArrayLiteralNode) { 3.27 + return null; 3.28 + } 3.29 + 3.30 final Type widest = Type.widest(lhs.getType(), rhs.getType()); 3.31 3.32 boolean isInteger = widest.isInteger();
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/basic/JDK-8012083.js Thu May 23 13:10:58 2013 +0200 4.3 @@ -0,0 +1,70 @@ 4.4 +/* 4.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * JDK-8012093 - array literals can only be subject to constant evaluation under very special 4.29 + * circumstances. 4.30 + * 4.31 + * @test 4.32 + * @run 4.33 + */ 4.34 + 4.35 + 4.36 +var w00t = 17; 4.37 +print(+[w00t]); 4.38 + 4.39 +var empty = []; 4.40 +print(empty == false); 4.41 + 4.42 +print([] == false); 4.43 +print([] === false); 4.44 +print(!![]); 4.45 + 4.46 +print(~[]); 4.47 +print(![]); 4.48 +print(![17]); 4.49 +print(![17,1,2]); 4.50 + 4.51 +var one = 1; 4.52 +var two = 2; 4.53 +var a1 = [one]; 4.54 +var a2 = [two]; 4.55 +print(+a1 + +a2); //3 4.56 + 4.57 +var x = 1; 4.58 +print(+["apa"]); 4.59 +print(+[]); //0 4.60 +print(+[1]); //1 4.61 +print(+[x]); //1 4.62 +print(+[1,2,3]); //NaN 4.63 +var a = []; 4.64 +var b = [1]; 4.65 +print(a/b); 4.66 +print(++[[]][+[]]+[+[]]); //10 4.67 +print(+[] == 0); 4.68 + 4.69 +var first = [![]+[]][+[]][+[]]+[![]+[]][+[]][+!+[]]+[!+[]+[]][+![]][+![]]+[![]+[]][+[]][+!+[]]+[![]+[]][+[]][+!+[]+!+[]]; 4.70 +var second =(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]; 4.71 + 4.72 +print(first + " " + second); 4.73 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/script/basic/JDK-8012083.js.EXPECTED Thu May 23 13:10:58 2013 +0200 5.3 @@ -0,0 +1,19 @@ 5.4 +17 5.5 +true 5.6 +true 5.7 +false 5.8 +true 5.9 +-1 5.10 +false 5.11 +false 5.12 +false 5.13 +3 5.14 +NaN 5.15 +0 5.16 +1 5.17 +1 5.18 +NaN 5.19 +0 5.20 +10 5.21 +true 5.22 +fatal fail