Top Description Inners Fields Constructors Methods
jdk.dynalink.linker.support

public Class CompositeTypeBasedGuardingDynamicLinker

extends Object
implements TypeBasedGuardingDynamicLinker
Class Inheritance
All Implemented Interfaces
jdk.dynalink.linker.TypeBasedGuardingDynamicLinker, jdk.dynalink.linker.GuardingDynamicLinker
Imports
java.util.Collections, .LinkedList, .List, .Objects, jdk.dynalink.linker.GuardedInvocation, .GuardingDynamicLinker, .LinkRequest, .LinkerServices, .TypeBasedGuardingDynamicLinker

A composite type-based guarding dynamic linker. When a receiver of a not yet seen class is encountered, all linkers are queried sequentially on their TypeBasedGuardingDynamicLinker#canLinkType(Class) method. The linkers returning true are then bound to the class, and next time a receiver of same type is encountered, the linking is delegated to those linkers only, speeding up dispatch.
Since
9

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ClassValue<List<TypeBasedGuardingDynamicLinker>>

Constructor Summary

AccessConstructor and Description
public
CompositeTypeBasedGuardingDynamicLinker(final Iterable<? extends TypeBasedGuardingDynamicLinker>
the component linkers
linkers
)

Creates a new composite type-based linker.

Method Summary

Modifier and TypeMethod and Description
private static void
public boolean

Returns:

true true if at least one of the composite linkers returns true from TypeBasedGuardingDynamicLinker#canLinkType(Class), false otherwise.
canLinkType
(final Class<?>
the type to link
type
)

Implements jdk.dynalink.linker.TypeBasedGuardingDynamicLinker.canLinkType.

Returns true if at least one of the composite linkers returns true from TypeBasedGuardingDynamicLinker#canLinkType(Class) for the type.

public GuardedInvocation
getGuardedInvocation(final LinkRequest
the object describing the request for linking a particular invocation
linkRequest
,
final LinkerServices
linker services
linkerServices
)

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

public static List<GuardingDynamicLinker>

Returns:

the optimized list
optimize
(final Iterable<? extends GuardingDynamicLinker>
the list of linkers to optimize
linkers
)

Optimizes a list of type-based linkers.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classToLinkerback to summary
private final ClassValue<List<TypeBasedGuardingDynamicLinker>> classToLinker

Constructor Detail

CompositeTypeBasedGuardingDynamicLinkerback to summary
public CompositeTypeBasedGuardingDynamicLinker(final Iterable<? extends TypeBasedGuardingDynamicLinker> linkers)

Creates a new composite type-based linker.

Parameters
linkers:Iterable<? extends TypeBasedGuardingDynamicLinker>

the component linkers

Exceptions
NullPointerException:
if linkers or any of its elements are null.

Method Detail

addTypeBasedback to summary
private static void addTypeBased(final List<GuardingDynamicLinker> llinkers, final List<TypeBasedGuardingDynamicLinker> tblinkers)
canLinkTypeback to summary
public boolean canLinkType(final Class<?> type)

Implements jdk.dynalink.linker.TypeBasedGuardingDynamicLinker.canLinkType.

Returns true if at least one of the composite linkers returns true from TypeBasedGuardingDynamicLinker#canLinkType(Class) for the type.

Parameters
type:Class<?>

the type to link

Returns:boolean

true true if at least one of the composite linkers returns true from TypeBasedGuardingDynamicLinker#canLinkType(Class), false otherwise.

Annotations
@Override
getGuardedInvocationback to summary
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Doc from jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

Parameters
linkRequest:LinkRequest

the object describing the request for linking a particular invocation

linkerServices:LinkerServices

linker services

Returns:GuardedInvocation

a guarded invocation with a method handle suitable for the arguments, as well as a guard condition that if fails should trigger relinking. Must return null if it can't resolve the invocation. If the returned invocation is unconditional (which is actually quite rare), the guard in the return value can be null. The invocation can also have any number of switch points for asynchronous invalidation of the linkage, as well as a Throwable subclass that describes an expected exception condition that also triggers relinking (often it is faster to rely on an infrequent but expected ClassCastException than on an always evaluated instanceof guard). While the linker must produce an invocation with parameter types matching those in the call site descriptor of the link request, it should not try to match the return type expected at the call site except when it can do it with only the conversions that lose neither precision nor magnitude, see LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType) for further explanation.

Annotations
@Override
Exceptions
Exception:
if the operation fails for whatever reason
optimizeback to summary
public static List<GuardingDynamicLinker> optimize(final Iterable<? extends GuardingDynamicLinker> linkers)

Optimizes a list of type-based linkers. If a group of adjacent linkers in the list all implement TypeBasedGuardingDynamicLinker, they will be replaced with a single instance of CompositeTypeBasedGuardingDynamicLinker that contains them.

Parameters
linkers:Iterable<? extends GuardingDynamicLinker>

the list of linkers to optimize

Returns:List<GuardingDynamicLinker>

the optimized list

Exceptions
NullPointerException:
if linkers or any of its elements are null.
jdk.dynalink.linker.support back to summary

private Class CompositeTypeBasedGuardingDynamicLinker.ClassToLinker

extends ClassValue<List<TypeBasedGuardingDynamicLinker>>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final TypeBasedGuardingDynamicLinker[]
private static final List<TypeBasedGuardingDynamicLinker>
private final List<TypeBasedGuardingDynamicLinker>[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected List<TypeBasedGuardingDynamicLinker>
computeValue(final Class<?>
the type whose class value must be computed
clazz
)

Implements abstract java.lang.ClassValue.computeValue.

Computes the given class's derived value for this ClassValue.

Inherited from java.lang.ClassValue:
getremove

Field Detail

linkersback to summary
private final TypeBasedGuardingDynamicLinker[] linkers
NO_LINKERback to summary
private static final List<TypeBasedGuardingDynamicLinker> NO_LINKER
singletonLinkersback to summary
private final List<TypeBasedGuardingDynamicLinker>[] singletonLinkers

Constructor Detail

ClassToLinkerback to summary
pack-priv ClassToLinker(final TypeBasedGuardingDynamicLinker[] linkers)
Annotations
@SuppressWarnings:unchecked, rawtypes

Method Detail

computeValueback to summary
protected List<TypeBasedGuardingDynamicLinker> computeValue(final Class<?> clazz)

Implements abstract java.lang.ClassValue.computeValue.

Doc from java.lang.ClassValue.computeValue.

Computes the given class's derived value for this ClassValue.

This method will be invoked within the first thread that accesses the value with the get method.

Normally, this method is invoked at most once per class, but it may be invoked again if there has been a call to remove.

If this method throws an exception, the corresponding call to get will terminate abnormally with that exception, and no class value will be recorded.

Parameters
clazz:Class<?>

the type whose class value must be computed

Returns:List<TypeBasedGuardingDynamicLinker>

the newly computed value associated with this ClassValue, for the given class or interface

Annotations
@SuppressWarnings:fallthrough
@Override