# HG changeset patch # User Thomas Wuerthinger # Date 1425921079 -3600 # Node ID de35dd77327267d7e1f24afec48989a7f2608b22 # Parent 19a4fbe393d0fa041c9443b0f65735bce1396d71 Fixed an issue with nested loop explosion. Added a unit test to prevent future regressions. diff -r 19a4fbe393d0 -r de35dd773272 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- 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; diff -r 19a4fbe393d0 -r de35dd773272 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java --- 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)}); diff -r 19a4fbe393d0 -r de35dd773272 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/NestedExplodedLoopTestNode.java --- /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; + } +}