GenerateWrapper and InstrumentableNode instead.@Retention(value=RUNTIME) @Target(value=TYPE) @Deprecated public @interface Instrumentable
Marks a guest language AST node class as instrumentable: an AST location where
Truffle instruments are
permitted to listen to before and after execution events. An instrumentable node must provide a
SourceSection and a wrapper factory to create a wrapper for the
instrumentable node. Wrapper factories can be inherited by subclasses.
Instrumentable nodes must extend Node. The instrumentation framework will, when
needed during execution, replace the instrumentable node with a
InstrumentableFactory.WrapperNode and delegate to
the original node. After the replacement of an instrumentable node with a wrapper we refer to the
original node as an instrumented node.
Wrappers can be generated automatically using an annotation processor. For that a class literal
named {WrappedNode}Wrapper must be used. If the referenced class was not found on the class path
it will get generated. If the automatically generated wrapper factory and wrapper classes are not
suitable for the needs of the guest language then InstrumentableFactory can also be
implemented manually and referenced in Instrumentable.factory() using a class literal.
Example for a minimal implementation of an instrumentable node with a
generated wrapper. For that at least one method starting with execute must be non-private and
non-final.
@Instrumentable(factory = BaseNodeWrapper.class)
public abstract class BaseNode extends Node {
public abstract Object execute(VirtualFrame frame);
}
If the instrumentable node requires more than one parameter it the constructor it can either
provide a default constructor or it can also provide a copy constructor. For example:
@Instrumentable(factory = BaseNodeWrapper.class)
public abstract class BaseNode extends Node {
private final String addtionalData;
public BaseNode(String additonalData) {
this.additionalData = additionalData;
}
public BaseNode(BaseNode delegate) {
this.additionalData = delegate.additionalData;
}
public abstract Object execute(VirtualFrame frame);
}
InstrumentableFactory.WrapperNode,
ProbeNode| Modifier and Type | Required Element and Description |
|---|---|
Class<? extends InstrumentableFactory<? extends Node>> |
factory
Deprecated.
Assigns a wrapper factory to a
node class annotated as instrumentable. |
public abstract Class<? extends InstrumentableFactory<? extends Node>> factory
node class annotated as instrumentable. To use the generated wrapper factory use the is generated with the original
class name and the "Wrapper" suffix. So if the class was called StatementNode
then the generated factory class will be called StatementNodeWraper.
@Instrumentable(factory = BaseNodeWrapper.class)
public abstract class BaseNode extends Node {
public abstract Object execute(VirtualFrame frame);
}