# HG changeset patch # User Michael Van De Vanter # Date 1409108245 25200 # Node ID f0c3de09f12a90b4a600a559b8f7d25caed5ab97 # Parent a1427e40deaf2f065336948f1a910dabf32ed843# Parent e01b0b9a5f886f8810ba09668632acd675cccf76 Merge with e01b0b9a5f886f8810ba09668632acd675cccf76 diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java --- a/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Aug 26 19:57:25 2014 -0700 @@ -379,7 +379,7 @@ callArgs.format("%s%s", sep, v.getSimpleName()); sep = ", "; } - f.format(") { return new %s(%s); }", genClassName, callArgs); + f.format(") { return USE_GENERATED_NODES ? new %s(%s) : new %s(%s); }", genClassName, callArgs, node.getSimpleName(), callArgs); throw new ElementException(constructor, "Missing Node class factory method '%s'", f); } if (!create.getModifiers().containsAll(asList(PUBLIC, STATIC))) { diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractFixedGuardNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractFixedGuardNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/AbstractFixedGuardNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -32,7 +32,7 @@ @NodeInfo public abstract class AbstractFixedGuardNode extends DeoptimizingFixedWithNextNode implements Simplifiable, GuardingNode { - @Input(InputType.Condition) LogicNode condition; + @Input(InputType.Condition) protected LogicNode condition; private final DeoptimizationReason reason; private final DeoptimizationAction action; private boolean negated; diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FloatingAnchoredNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FloatingAnchoredNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/FloatingAnchoredNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -30,7 +30,7 @@ @NodeInfo public abstract class FloatingAnchoredNode extends FloatingNode { - @Input(InputType.Anchor) AnchoringNode anchor; + @Input(InputType.Anchor) protected AnchoringNode anchor; public FloatingAnchoredNode(Stamp stamp) { super(stamp); diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -44,7 +44,7 @@ @NodeInfo(nameTemplate = "Guard(!={p#negated}) {p#reason/s}", allowedUsageTypes = {InputType.Guard}) public class GuardNode extends FloatingAnchoredNode implements Canonicalizable, IterableNodeType, GuardingNode { - @Input(InputType.Condition) LogicNode condition; + @Input(InputType.Condition) protected LogicNode condition; private final DeoptimizationReason reason; private Constant speculation; private DeoptimizationAction action; diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MergeNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MergeNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MergeNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -47,10 +47,10 @@ return USE_GENERATED_NODES ? MergeNodeGen.class : MergeNode.class; } - MergeNode() { + protected MergeNode() { } - @Input(InputType.Association) NodeInputList ends = new NodeInputList<>(this); + @Input(InputType.Association) protected NodeInputList ends = new NodeInputList<>(this); @Override public void generate(NodeLIRBuilderTool gen) { diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -39,7 +39,7 @@ @NodeInfo public abstract class PhiNode extends FloatingNode implements Simplifiable { - @Input(InputType.Association) MergeNode merge; + @Input(InputType.Association) protected MergeNode merge; protected PhiNode(Stamp stamp, MergeNode merge) { super(stamp); diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -33,7 +33,7 @@ @NodeInfo(nameTemplate = "ValuePhi({i#values})") public class ValuePhiNode extends PhiNode { - @Input NodeInputList values; + @Input protected NodeInputList values; /** * Create a value phi with the specified stamp. diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AbstractNewArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AbstractNewArrayNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/AbstractNewArrayNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -34,7 +34,7 @@ @NodeInfo public class AbstractNewArrayNode extends AbstractNewObjectNode implements ArrayLengthProvider { - @Input ValueNode length; + @Input protected ValueNode length; @Override public ValueNode length() { diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MonitorIdNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MonitorIdNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MonitorIdNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -42,7 +42,7 @@ return USE_GENERATED_NODES ? new MonitorIdNodeGen(lockDepth) : new MonitorIdNode(lockDepth); } - MonitorIdNode(int lockDepth) { + protected MonitorIdNode(int lockDepth) { super(StampFactory.forVoid()); this.lockDepth = lockDepth; } diff -r a1427e40deaf -r f0c3de09f12a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java Tue Aug 26 19:57:25 2014 -0700 @@ -51,7 +51,7 @@ return USE_GENERATED_NODES ? new NewArrayNodeGen(elementType, length, fillContents) : new NewArrayNode(elementType, length, fillContents); } - NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { + protected NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { super(StampFactory.exactNonNull(elementType.getArrayClass()), length, fillContents); } diff -r a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Instrumentable.java Tue Aug 26 19:57:25 2014 -0700 @@ -24,8 +24,6 @@ */ package com.oracle.truffle.api.instrument; -import com.oracle.truffle.api.*; - /** * Any Truffle node implementing this interface can be "instrumented" by installing a {@link Probe} * that intercepts {@link ExecutionEvents} at the node and routes them to any {@link Instrument}s @@ -39,9 +37,7 @@ * part (and not the root of) of a well-formed Truffle AST that is not being executed. The AST * may be modified. * - * @param context access to language implementation context - * @return a {@link Probe} to which tools may attach {@link Instrument}s that will receive - * {@link ExecutionEvents} + * @return The probe that was created. */ - public Probe probe(ExecutionContext context); + Probe probe(); } diff -r a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java Tue Aug 26 19:57:25 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 a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Tue Aug 26 19:57:25 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,18 +91,23 @@ } @Override - public Probe probe(ExecutionContext context) { + public Probe probe() { Node parent = getParent(); - if (parent == null) + if (parent == null) { throw new IllegalStateException("Cannot probe a node without a parent"); + } - if (parent instanceof SLExpressionWrapper) + if (parent instanceof SLExpressionWrapper) { return ((SLExpressionWrapper) parent).getProbe(); + } - SLExpressionWrapper wrapper = new SLExpressionWrapper((SLContext) context, this); + // Create a new wrapper/probe with this node as its child. + final SLExpressionWrapper wrapper = new SLExpressionWrapper(getRootNodeSLContext(this), this); + + // Replace this node in the AST with the wrapper this.replace(wrapper); - wrapper.insertChild(); + return wrapper.getProbe(); } } diff -r a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java Tue Aug 26 19:57:25 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 a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Tue Aug 26 19:57:25 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) @@ -98,11 +97,19 @@ } // Create a new wrapper/probe with this node as its child. - SLStatementWrapper wrapper = new SLStatementWrapper((SLContext) context, this); + final SLStatementWrapper wrapper = new SLStatementWrapper(getRootNodeSLContext(this), this); // Replace this node in the AST with the wrapper this.replace(wrapper); 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 a1427e40deaf -r f0c3de09f12a graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapper.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapper.java Tue Aug 26 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLExpressionWrapper.java Tue Aug 26 19:57:25 2014 -0700 @@ -151,10 +151,4 @@ return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame)); } - /** - * Sets the parent pointer of this wrapper's child. - */ - public void insertChild() { - insert(this.child); - } } diff -r a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLInstrumenter.java Tue Aug 26 19:57:25 2014 -0700 @@ -29,18 +29,14 @@ 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.*; /** - * A visitor which traverses a completely parsed Simple (not yet executed) AST and instruments some - * of them. + * A visitor which traverses a completely parsed Simple AST (presumed not yet executed) and + * instruments some of them. */ public class SLInstrumenter implements NodeVisitor { - private final SLContext context; - - public SLInstrumenter(SLContext context) { - this.context = context; + public SLInstrumenter() { } /** @@ -55,7 +51,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) @@ -65,7 +61,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 a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Aug 26 19:57:25 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 a1427e40deaf -r f0c3de09f12a 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 13:54:53 2014 -0700 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Aug 26 19:57:25 2014 -0700 @@ -23,6 +23,7 @@ package com.oracle.truffle.sl.runtime; import java.io.*; +import java.util.*; import com.oracle.truffle.api.*; import com.oracle.truffle.api.dsl.*; @@ -33,6 +34,7 @@ import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.builtins.*; import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.nodes.instrument.*; import com.oracle.truffle.sl.nodes.local.*; import com.oracle.truffle.sl.parser.*; @@ -130,7 +132,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); @@ -154,6 +156,17 @@ Parser.parseSL(this, source); + List functionList = getFunctionRegistry().getFunctions(); + + // Since only functions can be global in SL, this guarantees that we instrument + // everything of interest. Parsing must occur before accepting the visitors since + // the visitor which creates our instrumentation points expects a complete AST. + + for (SLFunction function : functionList) { + RootCallTarget rootCallTarget = function.getCallTarget(); + rootCallTarget.getRootNode().accept(new SLInstrumenter()); + } + if (sourceCallback != null) { sourceCallback.endLoading(source); }