APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.lang

public final Class LazyConstantImpl<T>

extends Object
implements LazyConstant<T>
Class Inheritance
All Implemented Interfaces
java.lang.LazyConstant, java.util.function.Supplier
Annotations
@AOTSafeClassInitializer
Type Parameters
<T>
type of the constant
Imports
jdk.internal.misc.Unsafe, jdk.internal.vm.annotation.AOTSafeClassInitializer, .DontInline, .ForceInline, .Stable, java.util.NoSuchElementException, .Objects, java.util.function.Supplier

The sole implementation of the LazyConstant interface.

Implementation Note

This implementation can be used early in the boot sequence as it does not rely on reflection, MethodHandles, Streams etc.

Field Summary

Modifier and TypeField and Description
private volatile Object
private T
private static final long
private static final Unsafe

Constructor Summary

AccessConstructor and Description
private
LazyConstantImpl(Supplier<? extends T> computingFunction)

Method Summary

Modifier and TypeMethod and Description
public T
get()

Implements java.lang.LazyConstant.get.

Returns the initialized content of this constant, computing it if necessary.

private T
private T
public static String
public static <T> LazyConstantImpl<T>
ofLazy(Supplier<? extends T> computingFunction)

public T
orElse(T other)

private void
private void
setRelease(T newValue)

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.LazyConstant.toString.

Returns a string suitable for debugging.

private String
pack-priv static NoSuchElementException
unableToAccessConstant(String exceptionType, Throwable cause)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

computingFunctionOrExceptionTypeback to summary
private volatile Object computingFunctionOrExceptionType
constantback to summary
private T constant
Annotations
@Stable
CONSTANT_OFFSETback to summary
private static final long CONSTANT_OFFSET
UNSAFEback to summary
private static final Unsafe UNSAFE

Constructor Detail

LazyConstantImplback to summary
private LazyConstantImpl(Supplier<? extends T> computingFunction)

Method Detail

getback to summary
public T get()

Implements java.lang.LazyConstant.get.

Doc from java.lang.LazyConstant.get.

Returns the initialized content of this constant, computing it if necessary.

If this constant is not initialized, first computes and initializes it using the computing function.

After this method returns successfully, the constant is guaranteed to be initialized.

If an unchecked exception is thrown when evaluating the computing function or if the computing function returns null, this lazy constant is not initialized but transitions to an error state whereafter a NoSuchElementException is thrown as described in the Exception handling section.

Annotations
@ForceInline
@Override
getAcquireback to summary
private T getAcquire()
Annotations
@SuppressWarnings:unchecked
@ForceInline
getSlowPathback to summary
private T getSlowPath()
Annotations
@DontInline
isolateToStringback to summary
public static String isolateToString(Object input)
ofLazyback to summary
public static <T> LazyConstantImpl<T> ofLazy(Supplier<? extends T> computingFunction)
orElseback to summary
public T orElse(T other)
Annotations
@ForceInline
preventReentryback to summary
private void preventReentry()
setReleaseback to summary
private void setRelease(T newValue)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.lang.LazyConstant.toString.

Doc from java.lang.LazyConstant.toString.

Returns a string suitable for debugging.

This method never triggers initialization of this lazy constant and will observe initialization by other threads atomically (i.e., it observes the content if and only if the initialization has already completed).

If this lazy constant is initialized, an implementation-dependent string containing the Object#toString() of the content will be returned; otherwise, an implementation-dependent string is returned that indicates this lazy constant is not yet initialized.

Annotations
@Override
toStringSuffixback to summary
private String toStringSuffix()
unableToAccessConstantback to summary
pack-priv static NoSuchElementException unableToAccessConstant(String exceptionType, Throwable cause)