Top Description Fields Constructors Methods
jdk.dynalink

public final Class DynamicLinkerFactory

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodType, .MutableCallSite, java.security.AccessControlContext, .AccessController, .PrivilegedAction, java.util.ArrayList, .Arrays, .Collections, .HashSet, .Iterator, .LinkedList, .List, .Objects, .ServiceConfigurationError, .ServiceLoader, .Set, java.util.function.Supplier, jdk.dynalink.beans.BeansLinker, jdk.dynalink.internal.AccessControlContextFactory, jdk.dynalink.linker.GuardedInvocation, .GuardedInvocationTransformer, .GuardingDynamicLinker, .GuardingDynamicLinkerExporter, .GuardingTypeConverterFactory, .LinkRequest, .LinkerServices, .MethodHandleTransformer, .MethodTypeConversionStrategy, jdk.dynalink.linker.support.CompositeGuardingDynamicLinker, .CompositeTypeBasedGuardingDynamicLinker, .DefaultInternalObjectFilter, .TypeUtilities

A factory class for creating DynamicLinker objects. Dynamic linkers are the central objects in Dynalink; these are composed of several GuardingDynamicLinker objects and coordinate linking of call sites with them. The usual dynamic linker is a linker composed of all GuardingDynamicLinker objects explicitly pre-created by the user of the factory and configured with setPrioritizedLinkers(List), as well as any automatically discovered ones, and finally the ones configured with setFallbackLinkers(List); this last category usually includes BeansLinker.
Since
9

Field Summary

Modifier and TypeField and Description
private MethodTypeConversionStrategy
private List<ServiceConfigurationError>
private ClassLoader
private boolean
private List<? extends GuardingDynamicLinker>
private static final AccessControlContext
GET_CLASS_LOADER_CONTEXT

References Deprecated AccessControlContext is deprecated or references (maybe indirectly) at least one deprecated element.
private MethodHandleTransformer
private GuardedInvocationTransformer
private List<? extends GuardingDynamicLinker>
private boolean
private int

Constructor Summary

AccessConstructor and Description
public
DynamicLinkerFactory()

Creates a new dynamic linker factory with default configuration.

Method Summary

Modifier and TypeMethod and Description
private static void
addClasses(final Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses, final List<? extends GuardingDynamicLinker> linkers)

private static <T> List<T>
public DynamicLinker

Returns:

the new dynamic Linker
createLinker
()

Creates a new dynamic linker based on the current configuration.

private List<GuardingDynamicLinker>
public List<ServiceConfigurationError>

Returns:

an immutable list of encountered ServiceConfigurationErrors. Can be empty.
getAutoLoadingErrors
()

Returns a list of ServiceConfigurationErrors that were encountered while loading automatically discovered linkers during the last invocation of createLinker().

private static ClassLoader
private static <T> List<T>
requireNonNullElements(final List<T> list, final Supplier<String> msgSupplier)

public void
setAutoConversionStrategy(final MethodTypeConversionStrategy
the strategy for applying method invocation conversions for the linker created by this factory. Can be null for no custom strategy.
autoConversionStrategy
)

Sets an object representing the conversion strategy for automatic type conversions.

public void
setClassLoader(final ClassLoader
the class loader used for the automatic discovery of available linkers.
classLoader
)

Sets the class loader for automatic discovery of available guarding dynamic linkers.

public void
setFallbackLinkers(final List<? extends GuardingDynamicLinker>
the list of fallback linkers. Can be empty to indicate the caller wishes to set no fallback linkers. Note that if this method is not invoked explicitly or is passed null, then the factory will create an instance of BeansLinker to serve as the default fallback linker.
fallbackLinkers
)

Sets the fallback guarding dynamic linkers.

public void
setFallbackLinkers(final GuardingDynamicLinker...
an array of fallback linkers. Can be empty to indicate the caller wishes to set no fallback linkers. Note that if this method is not invoked explicitly or is passed null, then the factory will create an instance of BeansLinker to serve as the default fallback linker.
fallbackLinkers
)

Sets the fallback guarding dynamic linkers.

public void
setInternalObjectsFilter(final MethodHandleTransformer
a method handle transformer filtering out internal objects, or null.
internalObjectsFilter
)

Sets a method handle transformer that is supposed to act as the implementation of LinkerServices#filterInternalObjects(MethodHandle) for linker services of dynamic linkers created by this factory.

public void
setPrelinkTransformer(final GuardedInvocationTransformer
the pre-link transformer for the dynamic linker. Can be null to have the factory use the default transformer.
prelinkTransformer
)

Set the pre-link transformer.

public void
setPrioritizedLinker(final GuardingDynamicLinker
the single prioritized linker. Must not be null.
prioritizedLinker
)

Sets a single prioritized linker.

public void
setPrioritizedLinkers(final List<? extends GuardingDynamicLinker>
the list of prioritized linkers. Can be null.
prioritizedLinkers
)

Sets the prioritized guarding dynamic linkers.

public void
setPrioritizedLinkers(final GuardingDynamicLinker...
an array of prioritized linkers. Can be null.
prioritizedLinkers
)

Sets the prioritized guarding dynamic linkers.

public void
setUnstableRelinkThreshold(final int
the new threshold. Must not be less than zero. The value of zero means that call sites will never be considered unstable.
unstableRelinkThreshold
)

Sets the unstable relink threshold; the number of times a call site is relinked after which it will be considered unstable, and subsequent link requests for it will indicate this.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoConversionStrategyback to summary
private MethodTypeConversionStrategy autoConversionStrategy
autoLoadingErrorsback to summary
private List<ServiceConfigurationError> autoLoadingErrors
classLoaderback to summary
private ClassLoader classLoader
classLoaderExplicitlySetback to summary
private boolean classLoaderExplicitlySet
fallbackLinkersback to summary
private List<? extends GuardingDynamicLinker> fallbackLinkers
GET_CLASS_LOADER_CONTEXTback to summary
private static final AccessControlContext GET_CLASS_LOADER_CONTEXT

References Deprecated

AccessControlContext is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
internalObjectsFilterback to summary
private MethodHandleTransformer internalObjectsFilter
prelinkTransformerback to summary
private GuardedInvocationTransformer prelinkTransformer
prioritizedLinkersback to summary
private List<? extends GuardingDynamicLinker> prioritizedLinkers
unstableRelinkThresholdback to summary
private int unstableRelinkThreshold

Constructor Detail

DynamicLinkerFactoryback to summary
public DynamicLinkerFactory()

Creates a new dynamic linker factory with default configuration. Upon creation, the factory can be configured using various setXxx() methods and used to create one or more dynamic linkers according to its current configuration using createLinker().

Method Detail

addClassesback to summary
private static void addClasses(final Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses, final List<? extends GuardingDynamicLinker> linkers)
copyListRequireNonNullElementsback to summary
private static <T> List<T> copyListRequireNonNullElements(final List<T> list)
createLinkerback to summary
public DynamicLinker createLinker()

Creates a new dynamic linker based on the current configuration. This method can be invoked more than once to create multiple dynamic linkers. Automatically discovered linkers are newly instantiated on every invocation of this method. It is allowed to change the factory's configuration between invocations. The method is not thread safe. After invocation, callers can invoke getAutoLoadingErrors() to retrieve a list of ServiceConfigurationErrors that occurred while trying to load automatically discovered linkers. These are never thrown from the call to this method as it makes every effort to recover from them and ignore the failing linkers.

Returns:DynamicLinker

the new dynamic Linker

discoverAutoLoadLinkersback to summary
private List<GuardingDynamicLinker> discoverAutoLoadLinkers()
getAutoLoadingErrorsback to summary
public List<ServiceConfigurationError> getAutoLoadingErrors()

Returns a list of ServiceConfigurationErrors that were encountered while loading automatically discovered linkers during the last invocation of createLinker(). They can be any non-Dynalink specific service configuration issues, as well as some Dynalink-specific errors when an exporter that the factory tried to automatically load:

Returns:List<ServiceConfigurationError>

an immutable list of encountered ServiceConfigurationErrors. Can be empty.

getThreadContextClassLoaderback to summary
private static ClassLoader getThreadContextClassLoader()
Annotations
@SuppressWarnings:removal
requireNonNullElementsback to summary
private static <T> List<T> requireNonNullElements(final List<T> list, final Supplier<String> msgSupplier)
setAutoConversionStrategyback to summary
public void setAutoConversionStrategy(final MethodTypeConversionStrategy autoConversionStrategy)

Sets an object representing the conversion strategy for automatic type conversions. After LinkerServices#asType(MethodHandle, MethodType) has applied all custom conversions to a method handle, it still needs to effect method invocation conversions that can usually be automatically applied as per MethodHandle#asType(MethodType). However, sometimes language runtimes will want to customize even those conversions for their own call sites. A typical example is allowing unboxing of null return values, which is by default prohibited by ordinary MethodHandles.asType(). In this case, a language runtime can install its own custom automatic conversion strategy, that can deal with null values. Note that when the strategy's MethodTypeConversionStrategy#asType(MethodHandle, MethodType) is invoked, the custom language conversions will already have been applied to the method handle, so by design the difference between the handle's current method type and the desired final type will always only be ones that can be subjected to method invocation conversions. The strategy also doesn't need to invoke a final MethodHandle.asType() as that will be done internally as the final step.

Parameters
autoConversionStrategy:MethodTypeConversionStrategy

the strategy for applying method invocation conversions for the linker created by this factory. Can be null for no custom strategy.

setClassLoaderback to summary
public void setClassLoader(final ClassLoader classLoader)

Sets the class loader for automatic discovery of available guarding dynamic linkers. GuardingDynamicLinkerExporter implementations available through this class loader will be automatically instantiated using the ServiceLoader mechanism and the linkers they provide will be incorporated into DynamicLinkers that this factory creates. This allows for cross-language interoperability where call sites belonging to this language runtime can be linked by linkers from these automatically discovered runtimes if their native objects are passed to this runtime. If class loader is not set explicitly by invoking this method, then the thread context class loader of the thread invoking createLinker() will be used. If this method is invoked explicitly with null then ServiceLoader#loadInstalled(Class) will be used to load the linkers.

Parameters
classLoader:ClassLoader

the class loader used for the automatic discovery of available linkers.

setFallbackLinkersback to summary
public void setFallbackLinkers(final List<? extends GuardingDynamicLinker> fallbackLinkers)

Sets the fallback guarding dynamic linkers. These linkers will be consulted last by the resulting dynamic linker when it is linking call sites, after any autodiscovered and prioritized linkers. If the factory also autodiscovers a linker class matching one of the fallback linkers, the autodiscovered class will be ignored and the explicit fallback instance will be used.

Parameters
fallbackLinkers:List<? extends GuardingDynamicLinker>

the list of fallback linkers. Can be empty to indicate the caller wishes to set no fallback linkers. Note that if this method is not invoked explicitly or is passed null, then the factory will create an instance of BeansLinker to serve as the default fallback linker.

Exceptions
NullPointerException:
if any of the list elements are null.
setFallbackLinkersback to summary
public void setFallbackLinkers(final GuardingDynamicLinker... fallbackLinkers)

Sets the fallback guarding dynamic linkers. Identical to calling setFallbackLinkers(List) with Arrays.asList(fallbackLinkers).

Parameters
fallbackLinkers:GuardingDynamicLinker[]

an array of fallback linkers. Can be empty to indicate the caller wishes to set no fallback linkers. Note that if this method is not invoked explicitly or is passed null, then the factory will create an instance of BeansLinker to serve as the default fallback linker.

Exceptions
NullPointerException:
if any of the array elements are null.
setInternalObjectsFilterback to summary
public void setInternalObjectsFilter(final MethodHandleTransformer internalObjectsFilter)

Sets a method handle transformer that is supposed to act as the implementation of LinkerServices#filterInternalObjects(MethodHandle) for linker services of dynamic linkers created by this factory. Some language runtimes can have internal objects that should not escape their scope. They can add a transformer here that will modify the method handle so that any parameters that can receive potentially internal language runtime objects will have a filter added on them to prevent them from escaping, potentially by wrapping them. The transformer can also potentially add an unwrapping filter to the return value. DefaultInternalObjectFilter is provided as a convenience class for easily creating such filtering transformers.

Parameters
internalObjectsFilter:MethodHandleTransformer

a method handle transformer filtering out internal objects, or null.

setPrelinkTransformerback to summary
public void setPrelinkTransformer(final GuardedInvocationTransformer prelinkTransformer)

Set the pre-link transformer. This is a GuardedInvocationTransformer that will get the final chance to modify the guarded invocation after it has been created by a component linker and before the dynamic linker links it into the call site. It is normally used to adapt the return value type of the invocation to the type of the call site. When not set explicitly, a default pre-link transformer will be used that simply calls GuardedInvocation#asType(LinkerServices, MethodType). Customized pre-link transformers are rarely needed; they are mostly used as a building block for implementing advanced techniques such as code deoptimization strategies.

Parameters
prelinkTransformer:GuardedInvocationTransformer

the pre-link transformer for the dynamic linker. Can be null to have the factory use the default transformer.

setPrioritizedLinkerback to summary
public void setPrioritizedLinker(final GuardingDynamicLinker prioritizedLinker)

Sets a single prioritized linker. Identical to calling setPrioritizedLinkers(List) with a single-element list.

Parameters
prioritizedLinker:GuardingDynamicLinker

the single prioritized linker. Must not be null.

Exceptions
NullPointerException:
if null is passed.
setPrioritizedLinkersback to summary
public void setPrioritizedLinkers(final List<? extends GuardingDynamicLinker> prioritizedLinkers)

Sets the prioritized guarding dynamic linkers. Language runtimes using Dynalink will usually have at least one linker for their own language. These linkers will be consulted first by the resulting dynamic linker when it is linking call sites, before any autodiscovered and fallback linkers. If the factory also autodiscovers a linker class matching one of the prioritized linkers, the autodiscovered class will be ignored and the explicit prioritized instance will be used.

Parameters
prioritizedLinkers:List<? extends GuardingDynamicLinker>

the list of prioritized linkers. Can be null.

Exceptions
NullPointerException:
if any of the list elements are null.
setPrioritizedLinkersback to summary
public void setPrioritizedLinkers(final GuardingDynamicLinker... prioritizedLinkers)

Sets the prioritized guarding dynamic linkers. Identical to calling setPrioritizedLinkers(List) with Arrays.asList(prioritizedLinkers).

Parameters
prioritizedLinkers:GuardingDynamicLinker[]

an array of prioritized linkers. Can be null.

Exceptions
NullPointerException:
if any of the array elements are null.
setUnstableRelinkThresholdback to summary
public void setUnstableRelinkThreshold(final int unstableRelinkThreshold)

Sets the unstable relink threshold; the number of times a call site is relinked after which it will be considered unstable, and subsequent link requests for it will indicate this. Defaults to 8 when not set explicitly.

Parameters
unstableRelinkThreshold:int

the new threshold. Must not be less than zero. The value of zero means that call sites will never be considered unstable.

See Also
LinkRequest#isCallSiteUnstable()