changeset 19737:de35dd773272

Fixed an issue with nested loop explosion. Added a unit test to prevent future regressions.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 09 Mar 2015 18:11:19 +0100
parents 19a4fbe393d0
children 2bad5984e4fe
files graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/NestedExplodedLoopTestNode.java
diffstat 3 files changed, 58 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon Mar 09 17:41:20 2015 +0100
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Mon Mar 09 18:11:19 2015 +0100
@@ -539,9 +539,10 @@
             private void peelIteration(BciBlock[] blocks, BciBlock header, ExplodedLoopContext context) {
                 while (true) {
                     processBlock(this, header);
-                    for (int j = header.getId() + 1; j <= header.loopEnd; ++j) {
+                    int j = header.getId() + 1;
+                    while (j <= header.loopEnd) {
                         BciBlock block = blocks[j];
-                        iterateBlock(blocks, block);
+                        j = iterateBlock(blocks, block);
                     }
 
                     int[] targets = context.targetPeelIteration;
--- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java	Mon Mar 09 17:41:20 2015 +0100
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java	Mon Mar 09 18:11:19 2015 +0100
@@ -48,6 +48,13 @@
     }
 
     @Test
+    public void nestedLoopExplosion() {
+        FrameDescriptor fd = new FrameDescriptor();
+        AbstractTestNode result = new AddTestNode(new NestedExplodedLoopTestNode(5), new ConstantTestNode(17));
+        assertPartialEvalEquals("constant42", new RootTestNode(fd, "addConstants", result));
+    }
+
+    @Test
     public void sequenceConstants() {
         FrameDescriptor fd = new FrameDescriptor();
         AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new ConstantTestNode(40), new ConstantTestNode(42)});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/NestedExplodedLoopTestNode.java	Mon Mar 09 18:11:19 2015 +0100
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015, 2015, 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.
+ */
+package com.oracle.graal.truffle.test.nodes;
+
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.nodes.*;
+
+@NodeInfo
+public class NestedExplodedLoopTestNode extends AbstractTestNode {
+
+    private final int count;
+
+    public NestedExplodedLoopTestNode(int count) {
+        this.count = count;
+    }
+
+    @ExplodeLoop
+    @Override
+    public int execute(VirtualFrame frame) {
+        int result = 0;
+        for (int i = 0; i < count; ++i) {
+            for (int j = 0; j < count; ++j) {
+                result++;
+            }
+        }
+        return result;
+    }
+}