Top Description Constructors Methods
jdk.internal.loader

public final Class ClassLoaderValue<V>

extends AbstractClassLoaderValue<ClassLoaderValue<V>, V>
Class Inheritance
Type Parameters
<V>
the type of value(s) associated with the root-ClassLoaderValue and all its descendants.
Imports
java.util.Objects, java.util.function.BiFunction

root-ClassLoaderValue. Each instance defines a separate namespace for associated values.

ClassLoaderValue allows associating a computed non-null value with a (ClassLoader, keys...) tuple. The associated value, as well as the keys are strongly reachable from the associated ClassLoader so care should be taken to use such keys and values that only reference types resolvable from the associated ClassLoader. Failing that, ClassLoader leaks are inevitable.

Example usage:

// create a root instance which represents a namespace and declares the type of
// associated values (Class instances in this example)
static final ClassLoaderValue<Class<?>> proxyClasses = new ClassLoaderValue<>();

// create a compound key composed of a Module and a list of interfaces
Module module = ...;
List<Class<?>> interfaces = ...;
ClassLoaderValue<Class<?>>.Sub<Module>.Sub<List<Class<?>>> key =
    proxyClasses.sub(module).sub(interfaces);

// use the compound key together with ClassLoader to lazily associate
// the value with tuple (loader, module, interfaces) and return it
ClassLoader loader = ...;
Class<?> proxyClass = key.computeIfAbsent(loader, (ld, ky) -> {
    List<Class<?>> intfcs = ky.key();
    Module m = ky.parent().key();
    Class<?> clazz = defineProxyClass(ld, m, intfcs);
    return clazz;
});

classLoaderValue.<operation>(classLoader, ...) represents an operation to get, putIfAbsent, computeIfAbsent or remove a value associated with a (classLoader, classLoaderValue) tuple. ClassLoader instances and root-ClassLoaderValue instances are compared using identity equality while sub-ClassLoaderValue instances define equality in terms of equality of its parent ClassLoaderValue and its key component.

Author
Peter Levart
Since
9

Constructor Summary

AccessConstructor and Description
public
ClassLoaderValue()

Constructs new root-ClassLoaderValue representing its own namespace.

Method Summary

Modifier and TypeMethod and Description
public boolean
isEqualOrDescendantOf(AbstractClassLoaderValue<?, V>
the ClassLoaderValue to test this against
clv
)

Implements abstract jdk.internal.loader.AbstractClassLoaderValue.isEqualOrDescendantOf.

root-ClassLoaderValue can only be equal to itself and has no predecessors.

public ClassLoaderValue<V>

Returns:

the key component of this root-ClassLoaderValue (itself).
key
()

Implements abstract jdk.internal.loader.AbstractClassLoaderValue.key.

Returns the key component of this ClassLoaderValue.

Inherited from jdk.internal.loader.AbstractClassLoaderValue:
computeIfAbsentgetputIfAbsentremoveremoveAllsub

Constructor Detail

ClassLoaderValueback to summary
public ClassLoaderValue()

Constructs new root-ClassLoaderValue representing its own namespace.

Method Detail

isEqualOrDescendantOfback to summary
public boolean isEqualOrDescendantOf(AbstractClassLoaderValue<?, V> clv)

Implements abstract jdk.internal.loader.AbstractClassLoaderValue.isEqualOrDescendantOf.

root-ClassLoaderValue can only be equal to itself and has no predecessors.

Parameters
clv:AbstractClassLoaderValue<?, V>

Doc from jdk.internal.loader.AbstractClassLoaderValue.isEqualOrDescendantOf.

the ClassLoaderValue to test this against

Returns:boolean

Doc from jdk.internal.loader.AbstractClassLoaderValue.isEqualOrDescendantOf.

if this ClassLoaderValue is equal to given clv or its descendant

Annotations
@Override
keyback to summary
public ClassLoaderValue<V> key()

Implements abstract jdk.internal.loader.AbstractClassLoaderValue.key.

Doc from jdk.internal.loader.AbstractClassLoaderValue.key.

Returns the key component of this ClassLoaderValue. The key component of the root-ClassLoaderValue is the ClassLoaderValue itself, while the key component of a sub-ClassLoaderValue is what was given to construct it.

Returns:ClassLoaderValue<V>

the key component of this root-ClassLoaderValue (itself).

Annotations
@Override