java.lang.Object
jdk.dynalink.DynamicLinkerFactory
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.- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new dynamic linker factory with default configuration.
- 
Method SummaryModifier and TypeMethodDescriptionCreates a new dynamic linker based on the current configuration.Returns a list ofServiceConfigurationErrors that were encountered while loading automatically discovered linkers during the last invocation ofcreateLinker().voidsetAutoConversionStrategy(MethodTypeConversionStrategy autoConversionStrategy) Sets an object representing the conversion strategy for automatic type conversions.voidsetClassLoader(ClassLoader classLoader) Sets the class loader for automatic discovery of available guarding dynamic linkers.voidsetFallbackLinkers(List<? extends GuardingDynamicLinker> fallbackLinkers) Sets the fallback guarding dynamic linkers.voidsetFallbackLinkers(GuardingDynamicLinker... fallbackLinkers) Sets the fallback guarding dynamic linkers.voidsetInternalObjectsFilter(MethodHandleTransformer internalObjectsFilter) Sets a method handle transformer that is supposed to act as the implementation ofLinkerServices.filterInternalObjects(MethodHandle)for linker services of dynamic linkers created by this factory.voidsetPrelinkTransformer(GuardedInvocationTransformer prelinkTransformer) Set the pre-link transformer.voidsetPrioritizedLinker(GuardingDynamicLinker prioritizedLinker) Sets a single prioritized linker.voidsetPrioritizedLinkers(List<? extends GuardingDynamicLinker> prioritizedLinkers) Sets the prioritized guarding dynamic linkers.voidsetPrioritizedLinkers(GuardingDynamicLinker... prioritizedLinkers) Sets the prioritized guarding dynamic linkers.voidsetSyncOnRelink(boolean syncOnRelink) Sets whether the dynamic linker created by this factory will invokeMutableCallSite.syncAll(MutableCallSite[])after a call site is relinked.voidsetUnstableRelinkThreshold(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.
- 
Constructor Details- 
DynamicLinkerFactorypublic DynamicLinkerFactory()Creates a new dynamic linker factory with default configuration. Upon creation, the factory can be configured using varioussetXxx()methods and used to create one or more dynamic linkers according to its current configuration usingcreateLinker().
 
- 
- 
Method Details- 
setClassLoaderSets the class loader for automatic discovery of available guarding dynamic linkers.GuardingDynamicLinkerExporterimplementations available through this class loader will be automatically instantiated using theServiceLoadermechanism and the linkers they provide will be incorporated intoDynamicLinkers 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 invokingcreateLinker()will be used. If this method is invoked explicitly with null thenServiceLoader.loadInstalled(Class)will be used to load the linkers.- Parameters:
- classLoader- the class loader used for the automatic discovery of available linkers.
 
- 
setPrioritizedLinkersSets 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- the list of prioritized linkers. Can be null.
- Throws:
- NullPointerException- if any of the list elements are null.
 
- 
setPrioritizedLinkersSets the prioritized guarding dynamic linkers. Identical to callingsetPrioritizedLinkers(List)withArrays.asList(prioritizedLinkers).- Parameters:
- prioritizedLinkers- an array of prioritized linkers. Can be null.
- Throws:
- NullPointerException- if any of the array elements are null.
 
- 
setPrioritizedLinkerSets a single prioritized linker. Identical to callingsetPrioritizedLinkers(List)with a single-element list.- Parameters:
- prioritizedLinker- the single prioritized linker. Must not be null.
- Throws:
- NullPointerException- if null is passed.
 
- 
setFallbackLinkersSets 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- 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- BeansLinkerto serve as the default fallback linker.
- Throws:
- NullPointerException- if any of the list elements are null.
 
- 
setFallbackLinkersSets the fallback guarding dynamic linkers. Identical to callingsetFallbackLinkers(List)withArrays.asList(fallbackLinkers).- Parameters:
- fallbackLinkers- 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- BeansLinkerto serve as the default fallback linker.
- Throws:
- NullPointerException- if any of the array elements are null.
 
- 
setSyncOnRelinkpublic void setSyncOnRelink(boolean syncOnRelink) Sets whether the dynamic linker created by this factory will invokeMutableCallSite.syncAll(MutableCallSite[])after a call site is relinked. Defaults to false. You probably want to set it to true if your runtime supports multithreaded execution of dynamically linked code.- Parameters:
- syncOnRelink- true for invoking sync on relink, false otherwise.
 
- 
setUnstableRelinkThresholdpublic void setUnstableRelinkThreshold(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- the new threshold. Must not be less than zero. The value of zero means that call sites will never be considered unstable.
- See Also:
 
- 
setPrelinkTransformerSet the pre-link transformer. This is aGuardedInvocationTransformerthat 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 callsGuardedInvocation.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- the pre-link transformer for the dynamic linker. Can be null to have the factory use the default transformer.
 
- 
setAutoConversionStrategySets an object representing the conversion strategy for automatic type conversions. AfterLinkerServices.asType(MethodHandle, MethodType)has applied all custom conversions to a method handle, it still needs to effectmethod invocation conversionsthat can usually be automatically applied as perMethodHandle.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 ordinaryMethodHandles.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'sMethodTypeConversionStrategy.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 finalMethodHandle.asType()as that will be done internally as the final step.- Parameters:
- autoConversionStrategy- the strategy for applying method invocation conversions for the linker created by this factory. Can be null for no custom strategy.
 
- 
setInternalObjectsFilterSets a method handle transformer that is supposed to act as the implementation ofLinkerServices.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.DefaultInternalObjectFilteris provided as a convenience class for easily creating such filtering transformers.- Parameters:
- internalObjectsFilter- a method handle transformer filtering out internal objects, or null.
 
- 
createLinkerCreates 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 invokegetAutoLoadingErrors()to retrieve a list ofServiceConfigurationErrors 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:
- the new dynamic Linker
 
- 
getAutoLoadingErrorsReturns a list ofServiceConfigurationErrors that were encountered while loading automatically discovered linkers during the last invocation ofcreateLinker(). 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:- did not have the runtime permission named
 GuardingDynamicLinkerExporter.AUTOLOAD_PERMISSION_NAMEin a system with a security manager, or
- returned null from Supplier.get(), or
- the list returned from Supplier.get()had a null element.
 - Returns:
- an immutable list of encountered
 ServiceConfigurationErrors. Can be empty.
 
- did not have the runtime permission named
 
 
-