public final class CompilerDirectives
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
CompilerDirectives.CompilationFinal
Marks fields that should be considered final for a Truffle compilation although they are not
final while executing in the interpreter.
|
static interface |
CompilerDirectives.TruffleBoundary
Marks a method that it is considered as a boundary for Truffle partial evaluation.
|
static interface |
CompilerDirectives.ValueType
Marks classes as value types.
|
Modifier and Type | Field and Description |
---|---|
static double |
FASTPATH_PROBABILITY |
static double |
LIKELY_PROBABILITY |
static double |
SLOWPATH_PROBABILITY |
static double |
UNLIKELY_PROBABILITY |
Constructor and Description |
---|
CompilerDirectives() |
Modifier and Type | Method and Description |
---|---|
static void |
bailout(java.lang.String reason)
Bails out of a compilation (e.g., for guest language features that should never be compiled).
|
static boolean |
inCompiledCode()
Returns a boolean value indicating whether the method is executed in the compiled code.
|
static boolean |
inInterpreter()
Returns a boolean value indicating whether the method is executed in the interpreter.
|
static boolean |
injectBranchProbability(double probability,
boolean condition)
Injects a probability for the given condition into the probability information of the
immediately succeeding branch instruction for the condition.
|
static <T> T |
interpreterOnly(java.util.concurrent.Callable<T> callable)
Directive for the compiler that the given callable should only be executed in the
interpreter.
|
static void |
interpreterOnly(java.lang.Runnable runnable)
Directive for the compiler that the given runnable should only be executed in the interpreter
and ignored in the compiled code.
|
static boolean |
isCompilationConstant(java.lang.Object value)
Returns a boolean indicating whether or not a given value is seen as constant in optimized
code.
|
static void |
materialize(java.lang.Object obj)
Ensures that the given object is not virtual, i.e., not removed by Escape Analysis at the
point of this call.
|
static void |
transferToInterpreter()
Directive for the compiler to discontinue compilation at this code position and instead
insert a transfer to the interpreter.
|
static void |
transferToInterpreterAndInvalidate()
Directive for the compiler to discontinue compilation at this code position and instead
insert a transfer to the interpreter, invalidating the currently executing machine code.
|
static <T> T |
unsafeCast(java.lang.Object value,
java.lang.Class<T> type,
boolean condition)
Casts the given value to the value of the given type without any checks.
|
static <T> T |
unsafeCast(java.lang.Object value,
java.lang.Class<T> type,
boolean condition,
boolean nonNull)
Casts the given value to the value of the given type without any checks.
|
static boolean |
unsafeGetBoolean(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a boolean value within an object.
|
static byte |
unsafeGetByte(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a byte value within an object.
|
static double |
unsafeGetDouble(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a double value within an object.
|
static boolean |
unsafeGetFinalBoolean(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final boolean value within an object.
|
static byte |
unsafeGetFinalByte(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final byte value within an object.
|
static double |
unsafeGetFinalDouble(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final double value within an object.
|
static float |
unsafeGetFinalFloat(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final float value within an object.
|
static int |
unsafeGetFinalInt(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final int value within an object.
|
static long |
unsafeGetFinalLong(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final long value within an object.
|
static java.lang.Object |
unsafeGetFinalObject(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final Object value within an object.
|
static short |
unsafeGetFinalShort(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a final short value within an object.
|
static float |
unsafeGetFloat(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a float value within an object.
|
static int |
unsafeGetInt(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to an int value within an object.
|
static long |
unsafeGetLong(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a long value within an object.
|
static java.lang.Object |
unsafeGetObject(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to an Object value within an object.
|
static short |
unsafeGetShort(java.lang.Object receiver,
long offset,
boolean condition,
java.lang.Object locationIdentity)
Unsafe access to a short value within an object.
|
static void |
unsafePutBoolean(java.lang.Object receiver,
long offset,
boolean value,
java.lang.Object locationIdentity)
Write a boolean value within an object.
|
static void |
unsafePutByte(java.lang.Object receiver,
long offset,
byte value,
java.lang.Object locationIdentity)
Write a byte value within an object.
|
static void |
unsafePutDouble(java.lang.Object receiver,
long offset,
double value,
java.lang.Object locationIdentity)
Write a double value within an object.
|
static void |
unsafePutFloat(java.lang.Object receiver,
long offset,
float value,
java.lang.Object locationIdentity)
Write a float value within an object.
|
static void |
unsafePutInt(java.lang.Object receiver,
long offset,
int value,
java.lang.Object locationIdentity)
Write an int value within an object.
|
static void |
unsafePutLong(java.lang.Object receiver,
long offset,
long value,
java.lang.Object locationIdentity)
Write a long value within an object.
|
static void |
unsafePutObject(java.lang.Object receiver,
long offset,
java.lang.Object value,
java.lang.Object locationIdentity)
Write an Object value within an object.
|
static void |
unsafePutShort(java.lang.Object receiver,
long offset,
short value,
java.lang.Object locationIdentity)
Write a short value within an object.
|
public static final double LIKELY_PROBABILITY
public static final double UNLIKELY_PROBABILITY
public static final double SLOWPATH_PROBABILITY
public static final double FASTPATH_PROBABILITY
public static void transferToInterpreter()
public static void transferToInterpreterAndInvalidate()
public static boolean inInterpreter()
true
when executed in the interpreter, false
in compiled code.public static boolean inCompiledCode()
false
when executed in the interpreter, true
in compiled code.public static boolean isCompilationConstant(java.lang.Object value)
false
. This API may be used in combination with inCompiledCode()
to
implement compilation constant assertions in the following way:
void assertCompilationConstant(Object value) {
if (inCompiledCode()) {
if (!isCompilationConstant(value)) {
throw new AssertionError("Given value is not constant");
}
}
}
Note that optimizations that a compiler will apply to code that is conditional on
isCompilationConstant
may be limited. For this reason
isCompilationConstant
is not recommended for use to select between alternate
implementations of functionality depending on whether a value is constant. Instead, it is
intended for use as a diagnostic mechanism, such as illustrated above.value
- true
when given value is seen as compilation constant, false
if not
compilation constant.public static void interpreterOnly(java.lang.Runnable runnable)
runnable
- the closure that should only be executed in the interpreterpublic static <T> T interpreterOnly(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
callable
- the closure that should only be executed in the interpreterjava.lang.Exception
- If the closure throws an exception when executed in the interpreter.public static boolean injectBranchProbability(double probability, boolean condition)
if (injectBranchProbability(0.9, a > b)) {
// ...
}
Example usage for a combined condition (it specifies that the likelihood for a to be greater
than b is 90% and under the assumption that this is true, the likelihood for a being 0 is
10%):
if (injectBranchProbability(0.9, a > b) && injectBranchProbability(0.1, a == 0)) {
// ...
}
There are predefined constants for commonly used probabilities (see
LIKELY_PROBABILITY
, UNLIKELY_PROBABILITY
, SLOWPATH_PROBABILITY
,
FASTPATH_PROBABILITY
).probability
- the probability value between 0.0 and 1.0 that should be injectedpublic static void bailout(java.lang.String reason)
reason
- the reason for the bailoutpublic static <T> T unsafeCast(java.lang.Object value, java.lang.Class<T> type, boolean condition)
value
- the value that is known to have the specified typetype
- the specified new type of the valuecondition
- the condition that makes this cast safe also at an earlier location of the
programpublic static <T> T unsafeCast(java.lang.Object value, java.lang.Class<T> type, boolean condition, boolean nonNull)
value
- the value that is known to have the specified typetype
- the specified new type of the valuecondition
- the condition that makes this cast safe also at an earlier location of the
programnonNull
- whether value is known to never be nullpublic static boolean unsafeGetBoolean(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static byte unsafeGetByte(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static short unsafeGetShort(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static int unsafeGetInt(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static long unsafeGetLong(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static float unsafeGetFloat(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static double unsafeGetDouble(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static java.lang.Object unsafeGetObject(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutBoolean(java.lang.Object receiver, long offset, boolean value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutByte(java.lang.Object receiver, long offset, byte value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutShort(java.lang.Object receiver, long offset, short value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutInt(java.lang.Object receiver, long offset, int value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutLong(java.lang.Object receiver, long offset, long value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutFloat(java.lang.Object receiver, long offset, float value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutDouble(java.lang.Object receiver, long offset, double value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void unsafePutObject(java.lang.Object receiver, long offset, java.lang.Object value, java.lang.Object locationIdentity)
receiver
- the object that is written tooffset
- the offset at which to write to the object in bytesvalue
- the value to be writtenlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static boolean unsafeGetFinalBoolean(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static byte unsafeGetFinalByte(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static short unsafeGetFinalShort(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static int unsafeGetFinalInt(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static long unsafeGetFinalLong(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static float unsafeGetFinalFloat(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static double unsafeGetFinalDouble(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static java.lang.Object unsafeGetFinalObject(java.lang.Object receiver, long offset, boolean condition, java.lang.Object locationIdentity)
receiver
- the object that is accessedoffset
- the offset at which to access the object in bytescondition
- the condition that makes this access safe also at an earlier location in the
programlocationIdentity
- the location identity token that can be used for improved global
value numbering or nullpublic static void materialize(java.lang.Object obj)
obj
- the object to exclude from Escape Analysis