Elide GraalVM25.6.0-elide.4
All types
Versions and modules

Assumption

Javainterfacein com.oracle.truffle.apisince 0.8 or earlier

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 Assumption.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.

Fields2

Assumption ALWAYS_VALID

ALWAYS_VALID

since 22.1
Assumption ALWAYS_VALID

An assumption that is always valid and fails with an UnsupportedOperationException if invalidated.

Assumption NEVER_VALID

NEVER_VALID

since 22.1
Assumption NEVER_VALID

An assumption that is never valid.

Methods9

void check()

check

since 0.8 or earlier
void check() throws InvalidAssumptionException

Checks that this assumption is still valid. The method throws an exception, if this is no longer the case. This method is preferred over the isValid() method when writing guest language interpreter code. The catch block should perform a node rewrite (see Node.replace(Node)) with a node that no longer relies on the assumption.

Throws

InvalidAssumptionException
If the assumption is no longer valid.
boolean isValid()

isValid

since 0.8 or earlier
boolean isValid()

Checks whether the assumption is still valid.

Returns

boolean
a boolean value indicating the validity of the assumption
void invalidate()

invalidate

since 0.8 or earlier
void invalidate()

Invalidates this assumption. Performs no operation, if the assumption is already invalid.

void invalidate(String)

invalidate

defaultsince 0.33
default void invalidate(String message)

Invalidates this assumption. Performs no operation, if the assumption is already invalid.

Parameters

messageString
a message stating the reason of the invalidation
String getName()

getName

since 0.8 or earlier
String getName()

A name for the assumption that is used for debug output.

Returns

String
the name of the assumption
static boolean isValidAssumption(Assumption)

isValidAssumption

staticsince 19.0
static boolean isValidAssumption(Assumption assumption)

Checks whether an assumption is not null and valid.

Parameters

assumptionAssumption
No description.

Returns

boolean
No description.
static boolean isValidAssumption(Assumption[])

isValidAssumption

staticsince 19.0
static boolean isValidAssumption(Assumption[] assumptions)

Checks whether all assumptions in an array are not null and valid. Returns false if the assumptions array itself is null. This method is designed for compilation. Note that the provided assumptions array must be a compilation final array with dimensions set to one.

Parameters

assumptionsAssumption[]
No description.

Returns

boolean
No description.
static Assumption create()

create

staticsince 22.1
static Assumption create()

Creates a new assumption with a name. Shortcut for TruffleRuntime.createAssumption().

Returns

Assumption
No description.
static Assumption create(String)

create

staticsince 22.1
static Assumption create(String name)

Creates a new assumption with a name. Shortcut for TruffleRuntime.createAssumption(String).

Parameters

nameString
No description.

Returns

Assumption
No description.