# HG changeset patch # User Lukas Stadler # Date 1367605694 -7200 # Node ID 8ccca4b4f880f5fe2bff46092c34a315e96ffd1d # Parent 58a2ff06f4b4d2f87dad03afa1adc449d649f98c# Parent cf9b3e717bdad4d46272dfa8b8be1fc8c9cfb492 Merge (fixed: cf9b3e717bda GraphBuilderPhase.genGoto does not need to provide a probability to createTarget) diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/WriteBarrierVerificationTest.java Fri May 03 20:28:14 2013 +0200 @@ -23,12 +23,14 @@ package com.oracle.graal.compiler.test; import java.util.*; +import java.util.concurrent.*; import org.junit.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; +import com.oracle.graal.debug.internal.*; import com.oracle.graal.hotspot.phases.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.LocationNode.LocationIdentity; @@ -615,9 +617,10 @@ } private void test(final String snippet, final int expectedBarriers, final int... removedBarrierIndices) { - Debug.scope("WriteBarrierVerificationTest", new DebugDumpScope(snippet), new Runnable() { - public void run() { + AssertionError expectedError = Debug.scope("WriteBarrierVerificationTest", new DebugDumpScope(snippet), new Callable() { + + public AssertionError call() { final StructuredGraph graph = parse(snippet); HighTierContext highTierContext = new HighTierContext(runtime(), new Assumptions(false), replacements); MidTierContext midTierContext = new MidTierContext(runtime(), new Assumptions(false), replacements, runtime().getTarget(), OptimisticOptimizations.ALL); @@ -690,8 +693,10 @@ } }; + DebugConfig config = DebugScope.getConfig(); try { ReentrantNodeIterator.apply(closure, graph.start(), new State(), null); + Debug.setConfig(Debug.fixedConfig(false, false, false, false, config.dumpHandlers(), config.output())); new WriteBarrierVerificationPhase().apply(graph); } catch (AssertionError error) { /* @@ -699,10 +704,15 @@ * test. */ Assert.assertTrue(error.getMessage().equals("Write barrier must be present")); - throw new AssertionError(); + return error; + } finally { + Debug.setConfig(config); } - + return null; } }); + if (expectedError != null) { + throw expectedError; + } } } diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Fri May 03 20:28:14 2013 +0200 @@ -36,8 +36,8 @@ import static com.oracle.graal.hotspot.nodes.NewMultiArrayStubCall.*; import static com.oracle.graal.hotspot.nodes.ThreadIsInterruptedStubCall.*; import static com.oracle.graal.hotspot.replacements.SystemSubstitutions.*; +import static com.oracle.graal.hotspot.stubs.ExceptionHandlerStub.*; import static com.oracle.graal.hotspot.stubs.IdentityHashCodeStub.*; -import static com.oracle.graal.hotspot.stubs.ExceptionHandlerStub.*; import static com.oracle.graal.hotspot.stubs.NewArrayStub.*; import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*; import static com.oracle.graal.hotspot.stubs.NewMultiArrayStub.*; @@ -66,7 +66,6 @@ import com.oracle.graal.hotspot.bridge.*; import com.oracle.graal.hotspot.bridge.CompilerToVM.CodeInstallResult; import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.hotspot.phases.*; import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.hotspot.stubs.*; import com.oracle.graal.java.*; @@ -89,6 +88,8 @@ */ public abstract class HotSpotRuntime implements GraalCodeCacheProvider, DisassemblerProvider, BytecodeDisassemblerProvider { + public static final Descriptor OSR_MIGRATION_END = new Descriptor("OSR_migration_end", true, void.class, long.class); + public final HotSpotVMConfig config; protected final RegisterConfig regConfig; @@ -215,7 +216,7 @@ // @formatter:off - addRuntimeCall(OnStackReplacementPhase.OSR_MIGRATION_END, config.osrMigrationEndStub, + addRuntimeCall(OSR_MIGRATION_END, config.osrMigrationEndStub, /* temps */ null, /* ret */ ret(Kind.Void), /* arg0: long */ javaCallingConvention(Kind.Long)); @@ -840,6 +841,30 @@ graph.removeFixed(commit); } else if (n instanceof CheckCastNode) { checkcastSnippets.lower((CheckCastNode) n, tool); + } else if (n instanceof OSRStartNode) { + OSRStartNode osrStart = (OSRStartNode) n; + StartNode newStart = graph.add(new StartNode()); + LocalNode buffer = graph.unique(new LocalNode(0, StampFactory.forKind(wordKind()))); + RuntimeCallNode migrationEnd = graph.add(new RuntimeCallNode(OSR_MIGRATION_END, buffer)); + migrationEnd.setStateAfter(osrStart.stateAfter()); + + newStart.setNext(migrationEnd); + FixedNode next = osrStart.next(); + osrStart.setNext(null); + migrationEnd.setNext(next); + graph.setStart(newStart); + + // mirroring the calculations in c1_GraphBuilder.cpp (setup_osr_entry_block) + int localsOffset = (graph.method().getMaxLocals() - 1) * 8; + for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.class)) { + int size = FrameStateBuilder.stackSlots(osrLocal.kind()); + int offset = localsOffset - (osrLocal.index() + size - 1) * 8; + UnsafeLoadNode load = graph.add(new UnsafeLoadNode(buffer, offset, ConstantNode.forInt(0, graph), osrLocal.kind())); + osrLocal.replaceAndDelete(load); + graph.addBeforeFixed(migrationEnd, load); + } + osrStart.replaceAtUsages(newStart); + osrStart.safeDelete(); } else if (n instanceof CheckCastDynamicNode) { checkcastSnippets.lower((CheckCastDynamicNode) n); } else if (n instanceof InstanceOfNode) { diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java Fri May 03 20:28:14 2013 +0200 @@ -22,20 +22,14 @@ */ package com.oracle.graal.hotspot.phases; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; - import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.RuntimeCallTarget.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; -import com.oracle.graal.graph.Node.*; +import com.oracle.graal.graph.Node.Verbosity; import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.java.*; import com.oracle.graal.loop.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; import com.oracle.graal.nodes.util.*; import com.oracle.graal.phases.*; @@ -43,29 +37,6 @@ public class OnStackReplacementPhase extends Phase { - public static final Descriptor OSR_MIGRATION_END = new Descriptor("OSR_migration_end", true, void.class, long.class); - - public class OSREntryProxyNode extends FloatingNode implements LIRLowerable { - - @Input private ValueNode object; - @Input(notDataflow = true) private final RuntimeCallNode anchor; - - public OSREntryProxyNode(ValueNode object, RuntimeCallNode anchor) { - super(object.stamp()); - this.object = object; - this.anchor = anchor; - } - - public RuntimeCallNode getAnchor() { - return anchor; - } - - @Override - public void generate(LIRGeneratorTool generator) { - generator.setResult(this, generator.operand(object)); - } - } - @Override protected void run(StructuredGraph graph) { if (graph.getEntryBCI() == StructuredGraph.INVOCATION_ENTRY_BCI) { @@ -114,39 +85,29 @@ Debug.dump(graph, "OnStackReplacement loop peeling result"); } while (true); - LocalNode buffer = graph.unique(new LocalNode(0, StampFactory.forKind(wordKind()))); - RuntimeCallNode migrationEnd = graph.add(new RuntimeCallNode(OSR_MIGRATION_END, buffer)); FrameState osrState = osr.stateAfter(); - migrationEnd.setStateAfter(osrState); osr.setStateAfter(null); - + OSRStartNode osrStart = graph.add(new OSRStartNode()); StartNode start = graph.start(); - FixedNode rest = start.next(); - start.setNext(migrationEnd); FixedNode next = osr.next(); osr.setNext(null); - migrationEnd.setNext(next); + osrStart.setNext(next); + graph.setStart(osrStart); + osrStart.setStateAfter(osrState); - FrameState oldStartState = start.stateAfter(); - start.setStateAfter(null); - GraphUtil.killWithUnusedFloatingInputs(oldStartState); - - // mirroring the calculations in c1_GraphBuilder.cpp (setup_osr_entry_block) - int localsOffset = (graph.method().getMaxLocals() - 1) * 8; for (int i = 0; i < osrState.localsSize(); i++) { ValueNode value = osrState.localAt(i); if (value != null) { ProxyNode proxy = (ProxyNode) value; - int size = FrameStateBuilder.stackSlots(value.kind()); - int offset = localsOffset - (i + size - 1) * 8; - UnsafeLoadNode load = graph.add(new UnsafeLoadNode(buffer, offset, ConstantNode.forInt(0, graph), value.kind())); - OSREntryProxyNode newProxy = graph.add(new OSREntryProxyNode(load, migrationEnd)); - proxy.replaceAndDelete(newProxy); - graph.addBeforeFixed(migrationEnd, load); + /* + * we need to drop the stamp and go back to the kind since the types we see during + * OSR may be too precise (if a branch was not parsed for example). + */ + proxy.replaceAndDelete(graph.unique(new OSRLocalNode(i, StampFactory.forKind(proxy.kind())))); } } - GraphUtil.killCFG(rest); + GraphUtil.killCFG(start); Debug.dump(graph, "OnStackReplacement result"); new DeadCodeEliminationPhase().apply(graph); diff -r 58a2ff06f4b4 -r 8ccca4b4f880 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 Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Fri May 03 20:28:14 2013 +0200 @@ -679,7 +679,7 @@ } private void genGoto() { - appendGoto(createTarget(1, currentBlock.successors.get(0), frameState)); + appendGoto(createTarget(currentBlock.successors.get(0), frameState)); assert currentBlock.numNormalSuccessors() == 1; } diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractLocalNode.java Fri May 03 20:28:14 2013 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009, 2011, 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.nodes; + +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.type.*; + +public abstract class AbstractLocalNode extends FloatingNode { + + private final int index; + + public AbstractLocalNode(int index, Stamp stamp) { + super(stamp); + this.index = index; + } + + /** + * Gets the index of this local in the array of parameters. This is NOT the JVM local index. + * + * @return the index + */ + public int index() { + return index; + } + + @Override + public String toString(Verbosity verbosity) { + if (verbosity == Verbosity.Name) { + return super.toString(Verbosity.Name) + "(" + index + ")"; + } else { + return super.toString(verbosity); + } + } +} diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LocalNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LocalNode.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LocalNode.java Fri May 03 20:28:14 2013 +0200 @@ -23,37 +23,15 @@ package com.oracle.graal.nodes; import com.oracle.graal.graph.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.type.*; /** * The {@code Local} instruction is a placeholder for an incoming argument to a function call. */ @NodeInfo(nameTemplate = "Local({p#index})") -public final class LocalNode extends FloatingNode implements Node.IterableNodeType { - - private final int index; +public final class LocalNode extends AbstractLocalNode implements Node.IterableNodeType { public LocalNode(int index, Stamp stamp) { - super(stamp); - this.index = index; - } - - /** - * Gets the index of this local in the array of parameters. This is NOT the JVM local index. - * - * @return the index - */ - public int index() { - return index; - } - - @Override - public String toString(Verbosity verbosity) { - if (verbosity == Verbosity.Name) { - return super.toString(Verbosity.Name) + "(" + index + ")"; - } else { - return super.toString(verbosity); - } + super(index, stamp); } } diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Fri May 03 20:28:14 2013 +0200 @@ -44,20 +44,22 @@ private final Set leafGraphIds = new HashSet<>(4); - private final StartNode start; + private StartNode start; private final ResolvedJavaMethod method; private final long graphId; private final int entryBCI; /** - * Creates a new Graph containing a single {@link AbstractBeginNode} as the {@link #start() start} node. + * Creates a new Graph containing a single {@link AbstractBeginNode} as the {@link #start() + * start} node. */ public StructuredGraph() { this(null, null); } /** - * Creates a new Graph containing a single {@link AbstractBeginNode} as the {@link #start() start} node. + * Creates a new Graph containing a single {@link AbstractBeginNode} as the {@link #start() + * start} node. */ public StructuredGraph(String name, ResolvedJavaMethod method) { this(name, method, uniqueGraphIds.incrementAndGet(), INVOCATION_ENTRY_BCI); @@ -73,7 +75,7 @@ private StructuredGraph(String name, ResolvedJavaMethod method, long graphId, int entryBCI) { super(name); - this.start = add(new StartNode()); + this.setStart(add(new StartNode())); this.method = method; this.graphId = graphId; this.entryBCI = entryBCI; @@ -116,6 +118,10 @@ return graphId; } + public void setStart(StartNode start) { + this.start = start; + } + /** * @return the {@link Set} that contains the {@link #graphId()} of all graphs that were * incorporated into this one (e.g. by inlining). diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java Fri May 03 20:27:45 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConvertNode.java Fri May 03 20:28:14 2013 +0200 @@ -41,7 +41,7 @@ I2B(Int, Byte, false), I2C(Int, Char, false), I2S(Int, Short, false), - F2D(Float, Double, false), + F2D(Float, Double, true), D2F(Double, Float, false), I2F(Int, Float, false), I2D(Int, Double, true), diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/OSRLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/OSRLocalNode.java Fri May 03 20:28:14 2013 +0200 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2009, 2011, 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.nodes.extended; + +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; + +@NodeInfo(nameTemplate = "OSRLocal({p#index})") +public class OSRLocalNode extends AbstractLocalNode implements Node.IterableNodeType { + + public OSRLocalNode(int index, Stamp stamp) { + super(index, stamp); + } + +} diff -r 58a2ff06f4b4 -r 8ccca4b4f880 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/OSRStartNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/OSRStartNode.java Fri May 03 20:28:14 2013 +0200 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 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. + */ +package com.oracle.graal.nodes.extended; + +import com.oracle.graal.graph.iterators.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; + +public class OSRStartNode extends StartNode implements Lowerable { + + @Override + public void lower(LoweringTool tool, LoweringType loweringType) { + if (loweringType == LoweringType.AFTER_GUARDS) { + tool.getRuntime().lower(this, tool); + } + } + + public NodeIterable getOSRLocals() { + return usages().filter(OSRLocalNode.class); + } +}