Package com.oracle.truffle.api
Interface Assumption
public interface Assumption
An assumption is a global boolean flag that starts with the value true (i.e., the assumption is
valid) and can subsequently be invalidated (using
invalidate()
). Once
invalidated, an assumption can never get valid again. Assumptions can be created using the
TruffleRuntime.createAssumption()
or the TruffleRuntime.createAssumption(String)
method. The Truffle compiler has special knowledge of this class in order to produce efficient
machine code for checking an assumption in case the assumption object is a compile time constant.
Therefore, assumptions should be stored in final fields in Truffle nodes.
All instances of classes implementing Assumption
must be held in final
fields for
compiler optimizations to take effect.
Do not manually subclass the Assumption
interface. This class is only intended to be
subclassed by Truffle runtime implementations to avoid polymorphism in performance sensitive
methods.
- Since:
- 0.8 or earlier
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Assumption
An assumption that is always valid and fails with anUnsupportedOperationException
if invalidated.static final Assumption
An assumption that is never valid. -
Method Summary
Modifier and TypeMethodDescriptionvoid
check()
Checks that this assumption is still valid.static Assumption
create()
Creates a new assumption with a name.static Assumption
Creates a new assumption with a name.getName()
A name for the assumption that is used for debug output.void
Invalidates this assumption.default void
invalidate
(String message) Invalidates this assumption.boolean
isValid()
Checks whether the assumption is still valid.static boolean
isValidAssumption
(Assumption assumption) Checks whether an assumption is notnull
and valid.static boolean
isValidAssumption
(Assumption[] assumptions) Checks whether all assumptions in an array are notnull
and valid.
-
Field Details
-
ALWAYS_VALID
An assumption that is always valid and fails with anUnsupportedOperationException
if invalidated.- Since:
- 22.1
-
NEVER_VALID
An assumption that is never valid.- Since:
- 22.1
-
-
Method Details
-
check
Checks that this assumption is still valid. The method throws an exception, if this is no longer the case. This method is preferred over theisValid()
method when writing guest language interpreter code. The catch block should perform a node rewrite (seeNode.replace(Node)
) with a node that no longer relies on the assumption.- Throws:
InvalidAssumptionException
- If the assumption is no longer valid.- Since:
- 0.8 or earlier
-
isValid
boolean isValid()Checks whether the assumption is still valid.- Returns:
- a boolean value indicating the validity of the assumption
- Since:
- 0.8 or earlier
-
invalidate
void invalidate()Invalidates this assumption. Performs no operation, if the assumption is already invalid.- Since:
- 0.8 or earlier
-
invalidate
Invalidates this assumption. Performs no operation, if the assumption is already invalid.- Parameters:
message
- a message stating the reason of the invalidation- Since:
- 0.33
-
getName
String getName()A name for the assumption that is used for debug output.- Returns:
- the name of the assumption
- Since:
- 0.8 or earlier
-
isValidAssumption
Checks whether an assumption is notnull
and valid.- Since:
- 19.0
-
isValidAssumption
Checks whether all assumptions in an array are notnull
and valid. Returnsfalse
if the assumptions array itself isnull
. This method is designed for compilation. Note that the provided assumptions array must be a compilation final array withdimensions
set to one.- Since:
- 19.0
-
create
Creates a new assumption with a name. Shortcut forTruffleRuntime.createAssumption()
.- Since:
- 22.1
-
create
Creates a new assumption with a name. Shortcut forTruffleRuntime.createAssumption(String)
.- Since:
- 22.1
-