8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars
authorlagergren
Mon, 25 Mar 2013 12:01:06 +0100
changeset 16531 8f1b0de50d07
parent 16530 201d682e75f4
child 16532 fe016e9cae59
8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars Reviewed-by: hannesw, sundar
nashorn/src/jdk/nashorn/internal/codegen/Attr.java
nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java
nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/encoding/AsciiTables.java
nashorn/test/script/basic/JDK-8017010.js
nashorn/test/script/basic/JDK-8017010.js.EXPECTED
nashorn/test/script/basic/NASHORN-258.js
nashorn/test/script/basic/NASHORN-258.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java	Sat Mar 23 00:58:39 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/codegen/Attr.java	Mon Mar 25 12:01:06 2013 +0100
@@ -577,7 +577,7 @@
 
     @Override
     public Node leaveIndexNode(final IndexNode indexNode) {
-        newTemporary(Type.OBJECT, indexNode); //TORO
+        newTemporary(Type.OBJECT, indexNode); //TODO
         return indexNode;
     }
 
@@ -1470,8 +1470,13 @@
         assignmentDest.accept(new NodeVisitor() {
             @Override
             public Node leaveIndexNode(final IndexNode indexNode) {
+                assert indexNode.getSymbol().isTemp();
                 final Node index = indexNode.getIndex();
-                index.getSymbol().setNeedsSlot(!index.getSymbol().isConstant());
+                //only temps can be set as needing slots. the others will self resolve
+                //it is illegal to take a scope var and force it to be a slot, that breaks
+                if (index.getSymbol().isTemp() && !index.getSymbol().isConstant()) {
+                     index.getSymbol().setNeedsSlot(true);
+                }
                 return indexNode;
             }
         });
--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java	Sat Mar 23 00:58:39 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/ByteCodeMachine.java	Mon Mar 25 12:01:06 2013 +0100
@@ -1459,4 +1459,4 @@
     private int finish() {
         return bestLen;
     }
-}
\ No newline at end of file
+}
--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/encoding/AsciiTables.java	Sat Mar 23 00:58:39 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/joni/encoding/AsciiTables.java	Mon Mar 25 12:01:06 2013 +0100
@@ -154,4 +154,4 @@
             {0x59, 0x79},
             {0x5a, 0x7a}
     };
-}
\ No newline at end of file
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8017010.js	Mon Mar 25 12:01:06 2013 +0100
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+/**
+ * JDK-8010710 - slot/scope problem with temporary expressions
+ * as array index in self modifying assigns
+ *
+ * @test
+ * @run 
+ */
+function zero() {
+    return 0;
+}
+
+//try complex self modifying assignment and force slots to temporary value index operators
+var a = [1, 2, 3, 4, 5];
+var b = [a, a];
+print(b[zero() + 1][2 + a[0]] += 10);
+
+//repro for NASHORN-258 that never made it
+function AddRoundKey() {        
+    var r=0;  
+    state[r][1] &= 17;    
+}
+
+var srcFiles = [];
+for(i=0;i<100;i++) {
+    srcFiles.push('dummy');
+}
+var added = '';
+
+//this broke the javafx build system. verify it works
+function bouncingBall() {
+    for (j=0; j<100; j++) {
+	added += srcFiles[j];
+    }
+}
+bouncingBall();
+print(added);
+
+//this is how they should have done it for speed, that works always, verify this too
+function bouncingBall2() {
+    for (var k=0; k<100; k++) {
+	added += srcFiles[k];
+    }
+}
+bouncingBall2();
+print(added);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8017010.js.EXPECTED	Mon Mar 25 12:01:06 2013 +0100
@@ -0,0 +1,3 @@
+14
+dummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummy
+dummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummydummy
--- a/nashorn/test/script/basic/NASHORN-258.js	Sat Mar 23 00:58:39 2013 +0100
+++ b/nashorn/test/script/basic/NASHORN-258.js	Mon Mar 25 12:01:06 2013 +0100
@@ -29,6 +29,16 @@
  */
 
 function test3(a) {
+    for (i = 0; i < a.length ; i++) {
+	for (j = 0; j < a[i].length ; j++) {
+	    for (k = 0; k < a[i][j].length ; k++) {
+		a[i][j][k] *= 8;
+	    }
+	}
+    }
+}
+
+function test3local(a) {
     for (var i = 0; i < a.length ; i++) {
 	for (var j = 0; j < a[i].length ; j++) {
 	    for (var k = 0; k < a[i][j].length ; k++) {
@@ -45,6 +55,8 @@
 test3(array);
 print(array);
 
+test3local(array);
+print(array);
 
 function outer() {
     
--- a/nashorn/test/script/basic/NASHORN-258.js.EXPECTED	Sat Mar 23 00:58:39 2013 +0100
+++ b/nashorn/test/script/basic/NASHORN-258.js.EXPECTED	Mon Mar 25 12:01:06 2013 +0100
@@ -1,2 +1,3 @@
 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
+64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64
 1,1,8,1,1,8,1,1,8,1,1,8,1,1,8,1,1,8,1,1,8,1,1,8,1,1,8