# HG changeset patch # User David Piorkowski # Date 1409076030 25200 # Node ID 997899955e7267659acd3dcd36c91e1373ebbe8c # Parent 7ef0a23555402c71734ccee51efa300dc145333f Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable SL/Instrumentation: SLRootNode's now store SLContext. New method added to SLStatementNode to find the root node and get its SLContext diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumentable.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumentable.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumentable.java Tue Aug 26 11:00:30 2014 -0700 @@ -31,7 +31,8 @@ /** * Optionally applies instrumentation at a Truffle AST node, depending on guest * language characteristics and use-case policy. Ideally, the parent node of the guest language - * implements this interface. + * implements this interface. This interfaces assumes that the instrumented node has access to + * the {@link ExecutionContext} for the guest language. * * - * @param context The {@link ExecutionContext} of the guest language used to create probes on - * the wrapper. * @return The probe that was created. */ - public Probe probe(ExecutionContext context); + public Probe probe(); } diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java Tue Aug 26 11:00:30 2014 -0700 @@ -213,7 +213,7 @@ for (SLFunction function : functionList) { RootCallTarget rootCallTarget = function.getCallTarget(); - rootCallTarget.getRootNode().accept(new SLInstrumenter(slContext)); + rootCallTarget.getRootNode().accept(new SLInstrumenter()); } // We iterate over all tags the SLInsturmenter tagged as assignments and attach our diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Tue Aug 26 11:00:30 2014 -0700 @@ -24,7 +24,6 @@ import java.math.*; -import com.oracle.truffle.api.*; import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.instrument.*; @@ -92,7 +91,7 @@ } @Override - public Probe probe(ExecutionContext context) { + public Probe probe() { Node parent = getParent(); if (parent == null) @@ -101,7 +100,7 @@ if (parent instanceof SLExpressionWrapper) return ((SLExpressionWrapper) parent).getProbe(); - SLExpressionWrapper wrapper = new SLExpressionWrapper((SLContext) context, this); + SLExpressionWrapper wrapper = new SLExpressionWrapper(getRootNodeSLContext(this), this); this.replace(wrapper); wrapper.insertChild(); return wrapper.getProbe(); diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java Tue Aug 26 11:00:30 2014 -0700 @@ -26,6 +26,7 @@ import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.sl.builtins.*; import com.oracle.truffle.sl.nodes.controlflow.*; +import com.oracle.truffle.sl.runtime.*; /** * The root of all SL execution trees. It is a Truffle requirement that the tree root extends the @@ -49,12 +50,16 @@ /** The name of the function, for printing purposes only. */ private final String name; - public SLRootNode(FrameDescriptor frameDescriptor, SLExpressionNode bodyNode, String name) { + /** The Simple execution context for this tree **/ + private final SLContext context; + + public SLRootNode(SLContext context, FrameDescriptor frameDescriptor, SLExpressionNode bodyNode, String name) { super(null, frameDescriptor); /* Deep copy the body before any specialization occurs during execution. */ this.uninitializedBodyNode = NodeUtil.cloneNode(bodyNode); this.bodyNode = bodyNode; this.name = name; + this.context = context; } @Override @@ -69,11 +74,15 @@ @Override public RootNode split() { - return new SLRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBodyNode), name); + return new SLRootNode(this.context, getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBodyNode), name); } @Override public String toString() { return "root " + name; } + + public SLContext getSLContext() { + return this.context; + } } diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Tue Aug 26 11:00:30 2014 -0700 @@ -24,7 +24,6 @@ import java.io.*; -import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.instrument.*; import com.oracle.truffle.api.nodes.*; @@ -87,7 +86,7 @@ } @Override - public Probe probe(ExecutionContext context) { + public Probe probe() { Node parent = getParent(); if (parent == null) @@ -96,9 +95,17 @@ if (parent instanceof SLStatementWrapper) return ((SLStatementWrapper) parent).getProbe(); - SLStatementWrapper wrapper = new SLStatementWrapper((SLContext) context, this); + SLStatementWrapper wrapper = new SLStatementWrapper(getRootNodeSLContext(this), this); this.replace(wrapper); wrapper.insertChild(); return wrapper.getProbe(); } + + protected SLContext getRootNodeSLContext(Node node) { + assert node != null; + + if (node instanceof SLRootNode) + return ((SLRootNode) node).getSLContext(); + return getRootNodeSLContext(node.getParent()); + } } diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java Tue Aug 26 11:00:30 2014 -0700 @@ -29,7 +29,6 @@ import com.oracle.truffle.sl.nodes.*; import com.oracle.truffle.sl.nodes.controlflow.*; import com.oracle.truffle.sl.nodes.local.*; -import com.oracle.truffle.sl.runtime.*; /** * This is a general purpose visitor which traverses a completely parsed Simple AST and instruments @@ -39,10 +38,7 @@ */ public class SLInstrumenter implements NodeVisitor { - private final SLContext context; - - public SLInstrumenter(SLContext context) { - this.context = context; + public SLInstrumenter() { } /** @@ -57,7 +53,7 @@ if (node instanceof SLExpressionNode && node.getParent() != null) { SLExpressionNode expressionNode = (SLExpressionNode) node; if (expressionNode.getSourceSection() != null) { - Probe probe = expressionNode.probe(context); + Probe probe = expressionNode.probe(); // probe.tagAs(STATEMENT); if (node instanceof SLWriteLocalVariableNode) @@ -67,7 +63,7 @@ SLStatementNode statementNode = (SLStatementNode) node; if (statementNode.getSourceSection() != null) { - Probe probe = statementNode.probe(context); + Probe probe = statementNode.probe(); probe.tagAs(STATEMENT); if (node instanceof SLWhileNode) diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Aug 26 11:00:30 2014 -0700 @@ -115,7 +115,7 @@ assert lexicalScope == null : "Wrong scoping of blocks in parser"; final SLFunctionBodyNode functionBodyNode = new SLFunctionBodyNode(functionSrc, methodBlock); - final SLRootNode rootNode = new SLRootNode(frameDescriptor, functionBodyNode, functionName); + final SLRootNode rootNode = new SLRootNode(this.context, frameDescriptor, functionBodyNode, functionName); context.getFunctionRegistry().register(functionName, rootNode); diff -r 7ef0a2355540 -r 997899955e72 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Aug 26 09:35:08 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Aug 26 11:00:30 2014 -0700 @@ -130,7 +130,7 @@ /* The name of the builtin function is specified via an annotation on the node class. */ String name = builtinBodyNode.getClass().getAnnotation(NodeInfo.class).shortName(); /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */ - SLRootNode rootNode = new SLRootNode(new FrameDescriptor(), builtinBodyNode, name); + SLRootNode rootNode = new SLRootNode(this, new FrameDescriptor(), builtinBodyNode, name); /* Register the builtin function in our function registry. */ getFunctionRegistry().register(name, rootNode);