# HG changeset patch # User Christian Humer # Date 1390238717 -3600 # Node ID 190d29710e97263f5d7ed0011447e1a84129d076 # Parent 193e3917dc078a009fa5716ec599e22955020bf3# Parent e749c19405ce29db9317d643ac02271a1734c48a Merge. diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/AssumptionPartialEvaluationTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -42,8 +42,8 @@ FrameDescriptor fd = new FrameDescriptor(); Assumption assumption = Truffle.getRuntime().createAssumption(); AbstractTestNode result = new ConstantWithAssumptionTestNode(assumption, 42); - RootTestNode rootNode = new RootTestNode("constantValue", result); - InstalledCode installedCode = assertPartialEvalEquals("constant42", rootNode, fd); + RootTestNode rootNode = new RootTestNode(fd, "constantValue", result); + InstalledCode installedCode = assertPartialEvalEquals("constant42", rootNode); Assert.assertTrue(installedCode.isValid()); try { assertEquals(42, installedCode.execute(null, null, null)); diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -45,7 +45,6 @@ import com.oracle.graal.truffle.*; import com.oracle.graal.virtual.phases.ea.*; import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; public class PartialEvaluationTest extends GraalCompilerTest { @@ -64,13 +63,13 @@ DebugEnvironment.initialize(System.out); } - protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, FrameDescriptor descriptor) { - return assertPartialEvalEquals(methodName, root, descriptor, Arguments.EMPTY_ARGUMENTS); + protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root) { + return assertPartialEvalEquals(methodName, root, Arguments.EMPTY_ARGUMENTS); } - protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, FrameDescriptor descriptor, Arguments arguments) { + protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, Arguments arguments) { Assumptions assumptions = new Assumptions(true); - StructuredGraph actual = partialEval(root, descriptor, arguments, assumptions, true); + StructuredGraph actual = partialEval(root, arguments, assumptions, true); InstalledCode result = new TruffleCompilerImpl().compileMethodHelper(actual, GraphBuilderConfiguration.getDefault(), assumptions, root.toString()); StructuredGraph expected = parseForComparison(methodName); removeFrameStates(actual); @@ -78,21 +77,21 @@ return result; } - protected void assertPartialEvalNoInvokes(RootNode root, FrameDescriptor descriptor) { - assertPartialEvalNoInvokes(root, descriptor, Arguments.EMPTY_ARGUMENTS); + protected void assertPartialEvalNoInvokes(RootNode root) { + assertPartialEvalNoInvokes(root, Arguments.EMPTY_ARGUMENTS); } - protected void assertPartialEvalNoInvokes(RootNode root, FrameDescriptor descriptor, Arguments arguments) { + protected void assertPartialEvalNoInvokes(RootNode root, Arguments arguments) { Assumptions assumptions = new Assumptions(true); - StructuredGraph actual = partialEval(root, descriptor, arguments, assumptions, true); + StructuredGraph actual = partialEval(root, arguments, assumptions, true); removeFrameStates(actual); for (MethodCallTargetNode node : actual.getNodes(MethodCallTargetNode.class)) { Assert.fail("Found invalid method call target node: " + node); } } - protected StructuredGraph partialEval(RootNode root, FrameDescriptor descriptor, Arguments arguments, final Assumptions assumptions, final boolean canonicalizeReads) { - final OptimizedCallTarget compilable = (OptimizedCallTarget) Truffle.getRuntime().createCallTarget(root, descriptor); + protected StructuredGraph partialEval(RootNode root, Arguments arguments, final Assumptions assumptions, final boolean canonicalizeReads) { + final OptimizedCallTarget compilable = (OptimizedCallTarget) Truffle.getRuntime().createCallTarget(root); // Executed AST so that all classes are loaded and initialized. do { diff -r e749c19405ce -r 190d29710e97 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 Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -38,28 +38,28 @@ public void constantValue() { FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new ConstantTestNode(42); - assertPartialEvalEquals("constant42", new RootTestNode("constantValue", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "constantValue", result)); } @Test public void addConstants() { FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new AddTestNode(new ConstantTestNode(40), new ConstantTestNode(2)); - assertPartialEvalEquals("constant42", new RootTestNode("addConstants", result), fd); + 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)}); - assertPartialEvalEquals("constant42", new RootTestNode("sequenceConstants", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "sequenceConstants", result)); } @Test public void localVariable() { FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(42)), new LoadLocalTestNode("x", fd)}); - assertPartialEvalEquals("constant42", new RootTestNode("localVariable", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "localVariable", result)); } @Test @@ -72,7 +72,7 @@ } AbstractTestNode result = new BlockTestNode(children); - assertPartialEvalEquals("constant42", new RootTestNode("longSequenceConstants", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "longSequenceConstants", result)); } @Test @@ -82,7 +82,7 @@ for (int i = 0; i < 20; ++i) { result = new AddTestNode(result, new ConstantTestNode(2)); } - assertPartialEvalEquals("constant42", new RootTestNode("longAddConstants", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "longAddConstants", result)); } @Test @@ -90,7 +90,7 @@ FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(40)), new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(2))), new LoadLocalTestNode("x", fd)}); - assertPartialEvalEquals("constant42", new RootTestNode("mixLocalAndAdd", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "mixLocalAndAdd", result)); } @Test @@ -98,7 +98,7 @@ FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(0)), new LoopTestNode(21, new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(2))))}); - assertPartialEvalEquals("constant42", new RootTestNode("loop", result), fd); + assertPartialEvalEquals("constant42", new RootTestNode(fd, "loop", result)); } @Test @@ -106,6 +106,6 @@ FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(0)), new LoopTestNode(42, new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(1))))}); - assertPartialEvalNoInvokes(new RootTestNode("loop", result), fd); + assertPartialEvalNoInvokes(new RootTestNode(fd, "loop", result)); } } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/RootTestNode.java Mon Jan 20 18:25:17 2014 +0100 @@ -30,8 +30,8 @@ private final String name; @Child AbstractTestNode node; - public RootTestNode(String name, AbstractTestNode node) { - super(null); + public RootTestNode(FrameDescriptor descriptor, String name, AbstractTestNode node) { + super(null, descriptor); this.name = name; this.node = node; } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java Mon Jan 20 18:25:17 2014 +0100 @@ -26,8 +26,6 @@ public class CompilationProfile { - private static final int MIN_INVOKES_AFTER_INLINING = 2; - private int invokeCounter; private int originalInvokeCounter; private int loopAndInvokeCounter; @@ -102,9 +100,9 @@ loopAndInvokeCounter--; } - void reportInliningPerformed() { - invokeCounter = MIN_INVOKES_AFTER_INLINING; - int inliningReprofileCount = TruffleInliningReprofileCount.getValue(); + void reportInliningPerformed(TruffleInlining inlining) { + invokeCounter = inlining.getInvocationReprofileCount(); + int inliningReprofileCount = inlining.getReprofileCount(); loopAndInvokeCounter = inliningReprofileCount; originalInvokeCounter = inliningReprofileCount; } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Mon Jan 20 18:25:17 2014 +0100 @@ -74,18 +74,13 @@ } public CallTarget createCallTarget(RootNode rootNode) { - return createCallTarget(rootNode, new FrameDescriptor()); - } - - @Override - public CallTarget createCallTarget(RootNode rootNode, FrameDescriptor frameDescriptor) { if (!acceptForCompilation(rootNode)) { - return new DefaultCallTarget(rootNode, frameDescriptor); + return new DefaultCallTarget(rootNode); } if (truffleCompiler == null) { truffleCompiler = new TruffleCompilerImpl(); } - return new OptimizedCallTarget(rootNode, frameDescriptor, truffleCompiler, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue()); + return new OptimizedCallTarget(rootNode, truffleCompiler, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue()); } @Override diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Mon Jan 20 18:25:17 2014 +0100 @@ -51,11 +51,10 @@ private boolean compilationEnabled; private int callCount; - protected OptimizedCallTarget(RootNode rootNode, FrameDescriptor descriptor, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) { - super(rootNode, descriptor); + protected OptimizedCallTarget(RootNode rootNode, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) { + super(rootNode); this.compiler = compiler; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); - this.inlining = new TruffleInliningImpl(); this.rootNode.setCallTarget(this); if (TruffleUseTimeForCompilationDecision.getValue()) { @@ -68,6 +67,8 @@ if (TruffleCallTargetProfiling.getValue()) { registerCallTarget(this); } + this.inlining = new TruffleInliningImpl(); + } @Override @@ -204,13 +205,13 @@ public boolean inline() { boolean result = inlining.performInlining(this); if (result) { - compilationProfile.reportInliningPerformed(); + compilationProfile.reportInliningPerformed(inlining); } return result; } public Object executeHelper(PackedFrame caller, Arguments args) { - VirtualFrame frame = createFrame(frameDescriptor, caller, args); + VirtualFrame frame = createFrame(rootNode.getFrameDescriptor(), caller, args); return rootNode.execute(frame); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java Mon Jan 20 18:25:17 2014 +0100 @@ -24,5 +24,18 @@ public interface TruffleInlining { + /** Returns true if reprofiling is required else false. */ boolean performInlining(OptimizedCallTarget callTarget); + + /** + * Returns the minimum number of invocations required until the next inlining can occur. Only + * used if {@link #performInlining(OptimizedCallTarget)} returned true. + */ + int getInvocationReprofileCount(); + + /** + * Returns the number of invocations or loop invocations required until the next inlining can + * occur. Only used if {@link #performInlining(OptimizedCallTarget)} returned true. + */ + int getReprofileCount(); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Mon Jan 20 18:25:17 2014 +0100 @@ -33,8 +33,18 @@ class TruffleInliningImpl implements TruffleInlining { + private static final int MIN_INVOKES_AFTER_INLINING = 2; + private static final PrintStream OUT = TTY.out().out(); + public int getReprofileCount() { + return TruffleCompilerOptions.TruffleInliningReprofileCount.getValue(); + } + + public int getInvocationReprofileCount() { + return MIN_INVOKES_AFTER_INLINING; + } + @Override public boolean performInlining(OptimizedCallTarget target) { final InliningPolicy policy = new InliningPolicy(target); diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameSlotTypeSpecializationTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -49,8 +49,8 @@ TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); - TestRootNode rootNode = new TestRootNode(new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); - CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); + TestRootNode rootNode = new TestRootNode(frameDescriptor, new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); + CallTarget target = runtime.createCallTarget(rootNode); Assert.assertEquals(FrameSlotKind.Int, slot.getKind()); Object result = target.call(); Assert.assertEquals("42", result); @@ -62,8 +62,8 @@ @Child TestChildNode left; @Child TestChildNode right; - public TestRootNode(TestChildNode left, TestChildNode right) { - super(null); + public TestRootNode(FrameDescriptor descriptor, TestChildNode left, TestChildNode right) { + super(null, descriptor); this.left = adoptChild(left); this.right = adoptChild(right); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -65,8 +65,8 @@ TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); - TestRootNode rootNode = new TestRootNode(new AssignLocal(slot), new ReadLocal(slot)); - CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); + TestRootNode rootNode = new TestRootNode(frameDescriptor, new AssignLocal(slot), new ReadLocal(slot)); + CallTarget target = runtime.createCallTarget(rootNode); Object result = target.call(); Assert.assertEquals(42, result); } @@ -76,8 +76,8 @@ @Child TestChildNode left; @Child TestChildNode right; - public TestRootNode(TestChildNode left, TestChildNode right) { - super(null); + public TestRootNode(FrameDescriptor descriptor, TestChildNode left, TestChildNode right) { + super(null, descriptor); this.left = adoptChild(left); this.right = adoptChild(right); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/ReturnTypeSpecializationTest.java Mon Jan 20 18:25:17 2014 +0100 @@ -48,8 +48,8 @@ TruffleRuntime runtime = Truffle.getRuntime(); FrameDescriptor frameDescriptor = new FrameDescriptor(); FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); - TestRootNode rootNode = new TestRootNode(new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); - CallTarget target = runtime.createCallTarget(rootNode, frameDescriptor); + TestRootNode rootNode = new TestRootNode(frameDescriptor, new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot)); + CallTarget target = runtime.createCallTarget(rootNode); Assert.assertEquals(FrameSlotKind.Int, slot.getKind()); Object result = target.call(); Assert.assertEquals("42", result); @@ -61,8 +61,8 @@ @Child TestChildNode left; @Child TestChildNode right; - public TestRootNode(TestChildNode left, TestChildNode right) { - super(null); + public TestRootNode(FrameDescriptor descriptor, TestChildNode left, TestChildNode right) { + super(null, descriptor); this.left = adoptChild(left); this.right = adoptChild(right); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Mon Jan 20 18:25:17 2014 +0100 @@ -28,8 +28,7 @@ /** * Represents the target of a call. Instances of this interface can be created using the - * {@link TruffleRuntime#createCallTarget(com.oracle.truffle.api.nodes.RootNode, FrameDescriptor)} - * method. + * {@link TruffleRuntime#createCallTarget(com.oracle.truffle.api.nodes.RootNode)} method. */ public abstract class CallTarget { diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Mon Jan 20 18:25:17 2014 +0100 @@ -51,17 +51,6 @@ CallTarget createCallTarget(RootNode rootNode); /** - * Creates a new call target for a given root node and a given frame descriptor. - * - * @param rootNode the root node whose - * {@link RootNode#execute(com.oracle.truffle.api.frame.VirtualFrame)} method - * represents the entry point - * @param frameDescriptor the descriptor used for creating a new frame at each invocation - * @return the new call target object - */ - CallTarget createCallTarget(RootNode rootNode, FrameDescriptor frameDescriptor); - - /** * Creates a new assumption object that can be checked and invalidated. * * @return the newly created assumption object diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Mon Jan 20 18:25:17 2014 +0100 @@ -31,11 +31,9 @@ public class DefaultCallTarget extends CallTarget { protected final RootNode rootNode; - protected final FrameDescriptor frameDescriptor; - public DefaultCallTarget(RootNode function, FrameDescriptor frameDescriptor) { + public DefaultCallTarget(RootNode function) { this.rootNode = function; - this.frameDescriptor = frameDescriptor; this.rootNode.setCallTarget(this); } @@ -46,14 +44,10 @@ @Override public Object call(PackedFrame caller, Arguments args) { - VirtualFrame frame = new DefaultVirtualFrame(frameDescriptor, caller, args); + VirtualFrame frame = new DefaultVirtualFrame(rootNode.getFrameDescriptor(), caller, args); return rootNode.execute(frame); } - public FrameDescriptor getFrameDescriptor() { - return frameDescriptor; - } - public RootNode getRootNode() { return rootNode; } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Mon Jan 20 18:25:17 2014 +0100 @@ -41,12 +41,7 @@ @Override public CallTarget createCallTarget(RootNode rootNode) { - return createCallTarget(rootNode, new FrameDescriptor()); - } - - @Override - public CallTarget createCallTarget(RootNode rootNode, FrameDescriptor frameDescriptor) { - return new DefaultCallTarget(rootNode, frameDescriptor); + return new DefaultCallTarget(rootNode); } @Override diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/RootNode.java Mon Jan 20 18:25:17 2014 +0100 @@ -30,15 +30,28 @@ /** * A root node is a node with a method to execute it given only a frame as a parameter. Therefore, a * root node can be used to create a call target using - * {@link TruffleRuntime#createCallTarget(RootNode, FrameDescriptor)}. + * {@link TruffleRuntime#createCallTarget(RootNode)}. */ public abstract class RootNode extends Node { + private CallTarget callTarget; + private final FrameDescriptor frameDescriptor; + protected RootNode() { + this(null, null); } protected RootNode(SourceSection sourceSection) { + this(sourceSection, null); + } + + protected RootNode(SourceSection sourceSection, FrameDescriptor frameDescriptor) { super(sourceSection); + if (frameDescriptor == null) { + this.frameDescriptor = new FrameDescriptor(); + } else { + this.frameDescriptor = frameDescriptor; + } } /** @@ -49,12 +62,14 @@ */ public abstract Object execute(VirtualFrame frame); - private CallTarget callTarget; - public CallTarget getCallTarget() { return callTarget; } + public FrameDescriptor getFrameDescriptor() { + return frameDescriptor; + } + public void setCallTarget(CallTarget callTarget) { this.callTarget = callTarget; } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AnnotationProcessor.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AnnotationProcessor.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/AnnotationProcessor.java Mon Jan 20 18:25:17 2014 +0100 @@ -102,18 +102,18 @@ private static class CodeWriter extends AbstractCodeWriter { - private final Element orignalElement; + private final Element originalElement; private final ProcessingEnvironment env; public CodeWriter(ProcessingEnvironment env, Element originalElement) { this.env = env; - this.orignalElement = originalElement; + this.originalElement = originalElement; } @Override protected Writer createWriter(CodeTypeElement clazz) throws IOException { - JavaFileObject jfo = env.getFiler().createSourceFile(clazz.getQualifiedName(), orignalElement); - return jfo.openWriter(); + JavaFileObject jfo = env.getFiler().createSourceFile(clazz.getQualifiedName(), originalElement); + return new BufferedWriter(jfo.openWriter()); } @Override @@ -121,7 +121,7 @@ if (env == null) { return; } - String comment = CompilerFactory.getCompiler(orignalElement).getHeaderComment(env, orignalElement); + String comment = CompilerFactory.getCompiler(originalElement).getHeaderComment(env, originalElement); if (comment != null) { writeLn(comment); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/RubyRootNode.java --- a/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/RubyRootNode.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/RubyRootNode.java Mon Jan 20 18:25:17 2014 +0100 @@ -22,8 +22,8 @@ protected final String indicativeName; @Child protected RubyNode body; - public RubyRootNode(SourceSection sourceSection, String indicativeName, RubyNode body) { - super(sourceSection); + public RubyRootNode(SourceSection sourceSection, FrameDescriptor descriptor, String indicativeName, RubyNode body) { + super(sourceSection, descriptor); assert indicativeName != null; assert body != null; diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/CoreMethodNodeManager.java --- a/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/CoreMethodNodeManager.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/CoreMethodNodeManager.java Mon Jan 20 18:25:17 2014 +0100 @@ -176,7 +176,7 @@ final CheckArityNode checkArity = new CheckArityNode(context, sourceSection, arity); final SequenceNode block = new SequenceNode(context, sourceSection, checkArity, methodNode); - return new RubyRootNode(sourceSection, methodDetails.getClassAnnotation().name() + "#" + methodDetails.getMethodAnnotation().names()[0] + "(core)", block); + return new RubyRootNode(sourceSection, null, methodDetails.getClassAnnotation().name() + "#" + methodDetails.getMethodAnnotation().names()[0] + "(core)", block); } public static class MethodDetails { diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/ModuleNodes.java --- a/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/ModuleNodes.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/ModuleNodes.java Mon Jan 20 18:25:17 2014 +0100 @@ -96,7 +96,7 @@ final SequenceNode block = new SequenceNode(context, sourceSection, checkArity, readInstanceVariable); - final RubyRootNode pristineRoot = new RubyRootNode(sourceSection, name + "(attr_reader)", block); + final RubyRootNode pristineRoot = new RubyRootNode(sourceSection, null, name + "(attr_reader)", block); final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRoot)); final InlinableMethodImplementation methodImplementation = new InlinableMethodImplementation(callTarget, null, new FrameDescriptor(), pristineRoot, true, false); final RubyMethod method = new RubyMethod(sourceSection, module, new UniqueMethodIdentifier(), null, name, Visibility.PUBLIC, false, methodImplementation); @@ -139,7 +139,7 @@ final SequenceNode block = new SequenceNode(context, sourceSection, checkArity, writeInstanceVariable); - final RubyRootNode pristineRoot = new RubyRootNode(sourceSection, name + "(attr_writer)", block); + final RubyRootNode pristineRoot = new RubyRootNode(sourceSection, null, name + "(attr_writer)", block); final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRoot)); final InlinableMethodImplementation methodImplementation = new InlinableMethodImplementation(callTarget, null, new FrameDescriptor(), pristineRoot, true, false); final RubyMethod method = new RubyMethod(sourceSection, module, new UniqueMethodIdentifier(), null, name + "=", Visibility.PUBLIC, false, methodImplementation); diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/JRubyParser.java --- a/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/JRubyParser.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/JRubyParser.java Mon Jan 20 18:25:17 2014 +0100 @@ -150,11 +150,10 @@ throw new UnsupportedOperationException(); } - final RootNode root = new RubyRootNode(truffleNode.getSourceSection(), indicativeName, truffleNode); + final RootNode root = new RubyRootNode(truffleNode.getSourceSection(), environment.getFrameDescriptor(), indicativeName, truffleNode); // Return the root and the frame descriptor - - return new RubyParserResult(root, environment.getFrameDescriptor()); + return new RubyParserResult(root); } finally { if (debugManager != null) { debugManager.notifyFinishedLoading(source); diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/MethodTranslator.java --- a/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/MethodTranslator.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/MethodTranslator.java Mon Jan 20 18:25:17 2014 +0100 @@ -59,9 +59,9 @@ body = new CatchNextNode(context, sourceSection, body); } - final RubyRootNode pristineRootNode = new RubyRootNode(sourceSection, methodName, body); + final RubyRootNode pristineRootNode = new RubyRootNode(sourceSection, environment.getFrameDescriptor(), methodName, body); - final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRootNode), environment.getFrameDescriptor()); + final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRootNode)); if (isBlock) { return new BlockDefinitionNode(context, sourceSection, methodName, environment.getUniqueMethodIdentifier(), environment.getFrameDescriptor(), environment.needsDeclarationFrame(), diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/ModuleTranslator.java --- a/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/ModuleTranslator.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.parser/src/com/oracle/truffle/ruby/parser/ModuleTranslator.java Mon Jan 20 18:25:17 2014 +0100 @@ -57,9 +57,9 @@ body = new CatchReturnNode(context, sourceSection, body, environment.getReturnID()); - final RubyRootNode pristineRootNode = new RubyRootNode(sourceSection, methodName, body); + final RubyRootNode pristineRootNode = new RubyRootNode(sourceSection, environment.getFrameDescriptor(), methodName, body); - final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRootNode), environment.getFrameDescriptor()); + final CallTarget callTarget = Truffle.getRuntime().createCallTarget(NodeUtil.cloneNode(pristineRootNode)); return new MethodDefinitionNode(context, sourceSection, methodName, environment.getUniqueMethodIdentifier(), environment.getFrameDescriptor(), environment.needsDeclarationFrame(), pristineRootNode, callTarget); diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyContext.java --- a/graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyContext.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyContext.java Mon Jan 20 18:25:17 2014 +0100 @@ -172,7 +172,7 @@ try { final RubyParserResult parseResult = parser.parse(context, source, parserContext, parentFrame); final RubyArguments arguments = new RubyArguments(parentFrame, self, null); - final CallTarget callTarget = Truffle.getRuntime().createCallTarget(parseResult.getRootNode(), parseResult.getFrameDescriptor()); + final CallTarget callTarget = Truffle.getRuntime().createCallTarget(parseResult.getRootNode()); return callTarget.call(null, arguments); } catch (RaiseException e) { diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyParserResult.java --- a/graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyParserResult.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyParserResult.java Mon Jan 20 18:25:17 2014 +0100 @@ -9,7 +9,6 @@ */ package com.oracle.truffle.ruby.runtime; -import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; /** @@ -19,23 +18,15 @@ */ public class RubyParserResult { - private RootNode rootNode; - private FrameDescriptor frameDescriptor; + private final RootNode rootNode; - public RubyParserResult(RootNode rootNode, FrameDescriptor frameDescriptor) { + public RubyParserResult(RootNode rootNode) { assert rootNode != null; - assert frameDescriptor != null; - this.rootNode = rootNode; - this.frameDescriptor = frameDescriptor; } public RootNode getRootNode() { return rootNode; } - public FrameDescriptor getFrameDescriptor() { - return frameDescriptor; - } - } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/CallNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/CallNode.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/CallNode.java Mon Jan 20 18:25:17 2014 +0100 @@ -189,7 +189,7 @@ InlinedDirectCallNode(InlinableDirectCallNode prev, TypedNode inlinedBody) { super(prev.functionNode, prev.argumentsNode, prev.cachedFunction, prev.nextNode); - this.descriptor = cachedFunction.getFrameDescriptor(); + this.descriptor = cachedFunction.getRootNode().getFrameDescriptor(); this.inlinedBody = adoptChild(inlinedBody); } diff -r e749c19405ce -r 190d29710e97 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java Mon Jan 20 18:22:02 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java Mon Jan 20 18:25:17 2014 +0100 @@ -37,8 +37,8 @@ private final String name; private final boolean inlineImmediatly; - private FunctionRootNode(TypedNode body, String name, boolean inlineImmediatly) { - super(null); + private FunctionRootNode(FrameDescriptor frameDescriptor, TypedNode body, String name, boolean inlineImmediatly) { + super(null, frameDescriptor); this.uninitializedBody = NodeUtil.cloneNode(body); this.body = adoptChild(body); this.name = name; @@ -52,14 +52,14 @@ arguments[i] = new ReadArgumentNode(i); } BuiltinNode buitinBody = factory.createNode(arguments, context); - FunctionRootNode root = new FunctionRootNode(buitinBody, name, true); + FunctionRootNode root = new FunctionRootNode(new FrameDescriptor(), buitinBody, name, true); return Truffle.getRuntime().createCallTarget(root); } public static CallTarget createFunction(StatementNode body, FrameDescriptor frameDescriptor, String name, TypedNode returnValue, String[] parameterNames) { FunctionBodyNode bodyContainer = new FunctionBodyNode(frameDescriptor, body, returnValue, parameterNames); - FunctionRootNode root = new FunctionRootNode(bodyContainer, name, false); - return Truffle.getRuntime().createCallTarget(root, frameDescriptor); + FunctionRootNode root = new FunctionRootNode(frameDescriptor, bodyContainer, name, false); + return Truffle.getRuntime().createCallTarget(root); } @Override