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

ConstantOptionKey

Javaclassin org.graalvm.optionssince 25.1

public final class ConstantOptionKey<T> extends OptionKey<T>
Inheritance
  1. Object
  2. OptionKey
  3. ConstantOptionKey

Represents an OptionKey whose value is fixed before the polyglot runtime is initialized and cannot be changed afterwards. Because the value is immutable after initialization, getConstantValue() is eligible for constant folding by the compiler, allowing branches guarded by this option to be eliminated from compiled code.

The option value is initialized from the system property -Dpolyglot.<option-name>=<value>, which must be set before the polyglot runtime is initialized (i.e. before the containing class is loaded). If the system property is absent, the default value is used. On HotSpot, this means the property must be present on the JVM command line. In a GraalVM native image, the property is read during image building, so the value is baked into the image.

Once the value has been set, getConstantValue() returns the same value for the lifetime of the runtime. The GraalVM compiler constant-folds calls to this method when the receiver is a known heap constant (e.g. a static final field), enabling dead-branch elimination.

Members shown

Constructors2

ConstantOptionKey(T)

ConstantOptionKey

since 25.1
public ConstantOptionKey(T defaultValue)

Constructs a new constant option key with the given default value. The default value is used when no value is specified via the system property -Dpolyglot.<option-name>. Throws IllegalArgumentException if no default OptionType could be resolved for the given type. The default value must not be null.

Parameters

defaultValueT
No description.
ConstantOptionKey(T, OptionType<T>)

ConstantOptionKey

since 25.1
public ConstantOptionKey(T defaultValue, OptionType<T> type)

Constructs a new constant option key with an explicit option type and default value. The default value is used when no value is specified via the system property -Dpolyglot.<option-name>.

Parameters

defaultValueT
No description.
typeOptionType<T>
No description.

Methods2 + 5 inherited

T getConstantValue()

getConstantValue

since 25.1
public T getConstantValue()

Returns the constant value of this option key. The value is fixed at class initialization time and remains immutable for the lifetime of the runtime, making this method eligible for constant folding by the GraalVM compiler when the receiver is a heap constant.

Returns

T
No description.

Throws

IllegalStateExceptionunchecked
if the value has not been set yet, which should not happen in normal usage as the generated option descriptors static initializer sets the value at class load time.
void setConstantValue(T)

setConstantValue

since 25.1
public void setConstantValue(T value)

Sets the constant value of this option key. This method is intended to be called from the generated option descriptors static initializer and must not be called after the polyglot runtime has started. In a native image, it must not be called at image run time.

Parameters

valueT
No description.

Throws

IllegalStateExceptionunchecked
if the value has already been set, or if called at native image run time.

Inherited members