Package com.oracle.truffle.api.dsl
Class Introspection
java.lang.Object
com.oracle.truffle.api.dsl.Introspection
Contains introspection utilities for Truffle DSL. The contained utilities are only usable if the
operation node is annotated with
Introspectable
.
Introspection is useful for using testing the node declaration and verifying that particular specializations become active.
Example for using introspection in unit testing:
@Introspectable
abstract static class NegateNode extends Node {
abstract Object execute(Object o);
@Specialization(guards = "cachedvalue == value", limit = "1")
protected static int doInt(int value,
@Cached("value") int cachedvalue) {
return -cachedvalue;
}
@Specialization(replaces = "doInt")
protected static int doGeneric(int value) {
return -value;
}
}
public void testUsingIntrospection() {
NegateNode node = null; // NegateNodeGen.create();
SpecializationInfo info;
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 1;
node.execute(1);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 1;
node.execute(2);
info = Introspection.getSpecialization(node, "doInt");
assert info.getInstances() == 0;
info = Introspection.getSpecialization(node, "doGeneric");
assert info.getInstances() == 1;
}
- Since:
- 0.22
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Internal marker interface for DSL generated code to access reflection information.static final class
Represents dynamic introspection information of a specialization of a DSL operation. -
Method Summary
Modifier and TypeMethodDescriptiongetSpecialization
(Node inlineParent, Node node, String methodName) LikegetSpecialization(Node, String)
but must be used for nodes that wereinlined
.getSpecialization
(Node node, String methodName) Returns introspection information for the first specialization that matches a given method name.static List
<Introspection.SpecializationInfo> getSpecializations
(Node node) Returns introspection information for all declared specializations as unmodifiable list.static List
<Introspection.SpecializationInfo> getSpecializations
(Node inlineParent, Node node) LikegetSpecializations(Node)
but must be used for nodes that wereinlined
.static boolean
isIntrospectable
(Node node) Returnstrue
if the given node is introspectable.
-
Method Details
-
isIntrospectable
Returnstrue
if the given node is introspectable. If something is introspectable is determined by if the node is generated by Truffle DSL, if is annotated withIntrospectable
and if the DSL implementation supports introspection.- Parameters:
node
- a DSL generated node- Returns:
- true if the given node is introspectable
- Since:
- 0.22
-
getSpecialization
Returns introspection information for the first specialization that matches a given method name. A node must declare at least one specialization and must be annotated withIntrospectable
otherwise anIllegalArgumentException
is thrown. If multiple specializations with the same method name are declared then an undefined specialization is going to be returned. In such cases disambiguate them by renaming the specialzation method name. The returned introspection information is not updated when the state of the given operation node is updated. The implementation of this method might be slow, do not use it in performance critical code.For a node was
inlined
usegetSpecialization(Node, Node, String)
.- Parameters:
node
- a introspectable DSL operation with at least one specializationmethodName
- the Java method name of the specialization to introspect- Returns:
- introspection info for the method
- Since:
- 0.22
- See Also:
-
getSpecialization
public static Introspection.SpecializationInfo getSpecialization(Node inlineParent, Node node, String methodName) LikegetSpecialization(Node, String)
but must be used for nodes that wereinlined
.- Parameters:
inlineParent
- the inlined parent node.node
- a introspectable DSL operation with at least one specializationmethodName
- the Java method name of the specialization to introspect- Returns:
- introspection info for the method
- Since:
- 23.0
- See Also:
-
getSpecializations
Returns introspection information for all declared specializations as unmodifiable list. A given node must declare at least one specialization and must be annotated withIntrospectable
otherwise anIllegalArgumentException
is thrown. The returned introspection information is not updated when the state of the given operation node is updated. The implementation of this method might be slow, do not use it in performance critical code.For a node was
inlined
usegetSpecialization(Node, Node, String)
.- Parameters:
node
- a introspectable DSL operation with at least one specialization- Since:
- 0.22
- See Also:
-
getSpecializations
public static List<Introspection.SpecializationInfo> getSpecializations(Node inlineParent, Node node) LikegetSpecializations(Node)
but must be used for nodes that wereinlined
.- Parameters:
inlineParent
- the inlined parent node.node
- a introspectable DSL operation with at least one specialization- Since:
- 23.0
- See Also:
-