# HG changeset patch # User Gilles Duboscq # Date 1339161463 -7200 # Node ID e05bb6f6c58b0baff94b9ebf88995dfa89eff8ee # Parent cedae73d9c2aa296de6e670dc1aa98890cfc63db# Parent bbb1c970cc150e25550b2f60ef9e6b0b01535ecd Merge diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopEx.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopEx.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopEx.java Fri Jun 08 15:17:43 2012 +0200 @@ -98,4 +98,9 @@ public int size() { return whole().nodes().count(); } + + @Override + public String toString() { + return isCounted() ? "Counted" : "" + "Loop (depth=" + lirLoop().depth + ") " + loopBegin(); + } } diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragment.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragment.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragment.java Fri Jun 08 15:17:43 2012 +0200 @@ -227,8 +227,11 @@ newEarlyExit.setNext(newEnd); merge.setNext(next); FrameState exitState = earlyExit.stateAfter(); - FrameState state = exitState.duplicate(); - merge.setStateAfter(state); + FrameState state = null; + if (exitState != null) { + state = exitState.duplicate(); + merge.setStateAfter(state); + } for (Node anchored : earlyExit.anchored().snapshot()) { anchored.replaceFirstInput(earlyExit, merge); @@ -252,7 +255,9 @@ } else { replaceWith = vpn.value(); } - state.replaceFirstInput(vpn, replaceWith); + if (state != null) { + state.replaceFirstInput(vpn, replaceWith); + } for (Node usage : vpn.usages().snapshot()) { if (usage != exitState && !merge.isPhiAtMerge(usage)) { usage.replaceFirstInput(vpn, replaceWith); diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragmentInside.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragmentInside.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopFragmentInside.java Fri Jun 08 15:17:43 2012 +0200 @@ -87,7 +87,12 @@ mergeEarlyExits(); - FixedNode entry = getDuplicatedNode(this.loop().loopBegin()); + BeginNode entry = getDuplicatedNode(this.loop().loopBegin()); + FrameState state = entry.stateAfter(); + if (state != null) { + entry.setStateAfter(null); + GraphUtil.killWithUnusedFloatingInputs(state); + } loop.entryPoint().replaceAtPredecessor(entry); end.setNext(loop.entryPoint()); } @@ -98,11 +103,8 @@ LoopFragmentWhole whole = loop().whole(); whole.nodes(); // init nodes bitmap in whole nodes = whole.nodes.copy(); - // remove the loop begin, its FS and the phis - LoopBeginNode loopBegin = loop().loopBegin(); - //nodes.clear(loopBegin); - nodes.clear(loopBegin.stateAfter()); - for (PhiNode phi : loopBegin.phis()) { + // remove the phis + for (PhiNode phi : loop().loopBegin().phis()) { nodes.clear(phi); } } @@ -222,8 +224,12 @@ assert endsToMerge.size() > 1; MergeNode newExitMerge = graph.add(new MergeNode()); newExit = newExitMerge; - FrameState duplicateState = loopBegin.stateAfter().duplicate(); - newExitMerge.setStateAfter(duplicateState); + FrameState state = loopBegin.stateAfter(); + FrameState duplicateState = null; + if (state != null) { + duplicateState = state.duplicate(); + newExitMerge.setStateAfter(duplicateState); + } for (EndNode end : endsToMerge) { newExitMerge.addForwardEnd(end); } @@ -237,7 +243,9 @@ firstPhi.addInput(prim); } ValueNode initializer = firstPhi; - duplicateState.replaceFirstInput(phi, firstPhi); // fix the merge's state after + if (duplicateState != null) { + duplicateState.replaceFirstInput(phi, firstPhi); // fix the merge's state after + } if (phi.type() == PhiType.Virtual) { initializer = GraphUtil.mergeVirtualChain(graph, firstPhi, newExitMerge); } diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Fri Jun 08 15:17:43 2012 +0200 @@ -924,6 +924,7 @@ assert !node.isDeleted() : "trying to duplicate deleted node"; Node replacement = replacements.replacement(node); if (replacement != node) { + assert replacement != null; newNodes.put(node, replacement); } else { Node newNode = node.clone(graph); diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/loop/LoopEscape.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/loop/LoopEscape.java Fri Jun 08 15:17:43 2012 +0200 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2012, 2012, 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. + */ +// Checkstyle: stop +package com.oracle.graal.jtt.loop; + +import org.junit.*; + +/* + * Test around an object that escapes directly from inside a loop (no virtual phi on the loop) + */ +public class LoopEscape { + public static L ll = new L(0, 1, 2); + + private static class L { + public int a; + public int b; + public int c; + public L(int a, int b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + } + + + public static int test0(int count) { + L l = new L(5, 5, 5); + for (int i = 0; i < count; i++) { + l.a++; + l.b--; + l.c = 4; + } + + return l.a + l.b * 10 + l.c * 100; + } + + public static int test1(int count) { + L l = new L(5, 5, 5); + for (int i = 0; i < count; i++) { + if (l.a % 2 == 0) { + l.a++; + l.b--; + l.c = 4; + } else { + l.a++; + } + } + + return l.a + l.b * 10 + l.c * 100; + } + + @Test + public void run10() throws Throwable { + Assert.assertEquals(555, test1(0)); + } + + @Test + public void run11() throws Throwable { + Assert.assertEquals(556, test1(1)); + } + + @Test + public void run12() throws Throwable { + Assert.assertEquals(447, test1(2)); + } + + @Test + public void run00() throws Throwable { + Assert.assertEquals(555, test0(0)); + } + + @Test + public void run01() throws Throwable { + Assert.assertEquals(446, test0(1)); + } + + @Test + public void run02() throws Throwable { + Assert.assertEquals(437, test0(2)); + } + + @Test + public void run05() throws Throwable { + Assert.assertEquals(410, test0(5)); + } +} diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java Fri Jun 08 15:17:43 2012 +0200 @@ -42,7 +42,7 @@ } public UnsafeCastNode(ValueNode object, RiResolvedType toType) { - super(StampFactory.declared(toType)); + super(StampFactory.declared(toType, object.stamp().nonNull())); this.object = object; this.toType = toType; } diff -r bbb1c970cc15 -r e05bb6f6c58b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Fri Jun 08 12:22:01 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java Fri Jun 08 15:17:43 2012 +0200 @@ -145,7 +145,7 @@ return declared(type, true); } - private static Stamp declared(RiResolvedType type, boolean nonNull) { + public static Stamp declared(RiResolvedType type, boolean nonNull) { assert type != null; assert type.kind(false) == RiKind.Object; RiResolvedType exact = type.exactType(); diff -r bbb1c970cc15 -r e05bb6f6c58b mx/commands.py --- a/mx/commands.py Fri Jun 08 12:22:01 2012 +0200 +++ b/mx/commands.py Fri Jun 08 15:17:43 2012 +0200 @@ -689,7 +689,7 @@ if len(neg) != 0: classes = [c for c in classes if not containsAny(c, neg)] - vm(['-XX:-BootstrapGraal', '-XX:CompileOnly=com/oracle/graal/jtt', '-XX:CompileCommand=exclude,com/oracle/graal/jtt*.run*', '-XX:CompileCommand=quiet', '-Xcomp', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) + vm(['-XX:-BootstrapGraal', '-XX:CompileOnly=com/oracle/graal/jtt', '-XX:CompileCommand=compileonly,java/lang/Object::', '-XX:CompileCommand=quiet', '-Xcomp', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) def buildvms(args): """build one or more VMs in various configurations"""