Bind
@Retention(CLASS)
@Target({PARAMETER})
public @interface BindBinds and executes an expression at most once for every execution of the node. This is useful if an expression cannot be repeated safely for a guard and its associated specialization method. For example, if a read of a field is volatile two consecutive reads might not lead to the same result. The name the extract parameter can be referred to in cached, guard, limit, assumption expressions or the specialization body. The bind expression may refer to dynamic parameters, previously declared bind or cached parameters and node field declarations.
If a bind parameter only uses cached values, then it is considered also a cached value. If the parameter uses any dynamic parameter then the extract parameter is considered also a dynamic parameter.
Usage examples:
static class DynamicObject {
volatile Object storage;
DynamicObject(Object storage) {
this.storage = storage;
}
}
abstract static class ExtractStorageNode extends Node {
abstract Object execute(Object arg0);
@Specialization(guards = "storage == cachedStorage", limit = "3")
Object s0(DynamicObject a0,
@Bind("a0.storage") Object storage,
@Cached("storage") Object cachedStorage) {
// use storage in specialization and in guard.
return a0;
}
}The special variable $node can be used to bind the current node, and $frame binds the execution frame. Bytecode DSL interpreters can also bind the special variables $rootNode, $bytecodeNode, and $bytecodeIndex. Proxyable nodes can enable explicit bytecode node and index execute parameters through OperationProxy.Proxyable.bindBytecodeNode and OperationProxy.Proxyable.bindBytecodeIndex. During ordinary AST execution, these bindings then use the supplied values rather than operation interpreter state.
See also
Elements1
Nested types
public @interface .DefaultExpressionDefines a default bind expression for a given type.