APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.dynalink.linker

public Class GuardedInvocation

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, .SwitchPoint, java.util.List, .Objects, java.util.function.Supplier, jdk.dynalink.CallSiteDescriptor, jdk.dynalink.linker.support.Guards

Represents a conditionally valid method handle. Usually produced as a return value of GuardingDynamicLinker#getGuardedInvocation(LinkRequest, LinkerServices) and GuardingTypeConverterFactory#convertToType(Class, Class, Supplier). It is an immutable tuple of an invocation method handle, a guard method handle that defines the applicability of the invocation handle, zero or more switch points that can be used for external invalidation of the invocation handle, and an exception type that if thrown during an invocation of the method handle also invalidates it. The invocation handle is suitable for invocation if the guard handle returns true for its arguments, and as long as any of the switch points are not invalidated, and as long as it does not throw an exception of the designated type. The guard, the switch points, and the exception type are all optional (a guarded invocation having none of them is unconditionally valid).
Since
9

Field Summary

Modifier and TypeField and Description
private final Class<? extends Throwable>
private final MethodHandle
private final MethodHandle
private final SwitchPoint[]

Constructor Summary

AccessConstructor and Description
public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
)

Creates a new unconditional guarded invocation.

public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
,
final MethodHandle
the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null to represent an unconditional invocation.
guard
)

Creates a new guarded invocation, with a guard method handle.

public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
,
final SwitchPoint
the optional switch point that can be used to invalidate this linkage. It can be null. If it is null, this represents an unconditional invocation.
switchPoint
)

Creates a new guarded invocation that can be invalidated by a switch point.

public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
,
final MethodHandle
the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If both it and the switch point are null, this represents an unconditional invocation.
guard
,
final SwitchPoint
the optional switch point that can be used to invalidate this linkage.
switchPoint
)

Creates a new guarded invocation, with both a guard method handle and a switch point that can be used to invalidate it.

public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
,
final MethodHandle
the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If it and the switch point and the exception are all null, this represents an unconditional invocation.
guard
,
final SwitchPoint
the optional switch point that can be used to invalidate this linkage.
switchPoint
,
final Class<? extends Throwable>
the optional exception type that is when thrown by the invocation also invalidates it.
exception
)

Creates a new guarded invocation, with a guard method handle, a switch point that can be used to invalidate it, and an exception that if thrown when invoked also invalidates it.

public
GuardedInvocation(final MethodHandle
the method handle representing the invocation. Must not be null.
invocation
,
final MethodHandle
the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If it and the exception are both null, and no switch points were specified, this represents an unconditional invocation.
guard
,
final SwitchPoint[]
optional switch points that can be used to invalidate this linkage.
switchPoints
,
final Class<? extends Throwable>
the optional exception type that is when thrown by the invocation also invalidates it.
exception
)

Creates a new guarded invocation, with a guard method handle, any number of switch points that can be used to invalidate it, and an exception that if thrown when invoked also invalidates it.

Method Summary

Modifier and TypeMethod and Description
public GuardedInvocation

Returns:

a guarded invocation with the added switch point.
addSwitchPoint
(final SwitchPoint
new switch point. Can be null in which case this method return the current guarded invocation with no changes.
newSwitchPoint
)

Create a new guarded invocation with an added switch point.

public GuardedInvocation

Returns:

a guarded invocation with the new type applied to it.
asType
(final MethodType
the new type of the invocation.
newType
)

Changes the type of the invocation, as if MethodHandle#asType(MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard).

public GuardedInvocation

Returns:

a guarded invocation with the new type applied to it.
asType
(final LinkerServices
the linker services to use for the conversion
linkerServices
,
final MethodType
the new type of the invocation.
newType
)

Changes the type of the invocation, as if LinkerServices#asType(MethodHandle, MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard).

public GuardedInvocation

Returns:

a guarded invocation with the new type applied to it.
asType
(final CallSiteDescriptor
a call descriptor whose method type is adapted.
desc
)

Changes the type of the invocation, as if MethodHandle#asType(MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean for guard).

public GuardedInvocation

Returns:

a guarded invocation with the new type applied to it.
asTypeSafeReturn
(final LinkerServices
the linker services to use for the conversion
linkerServices
,
final MethodType
the new type of the invocation.
newType
)

Changes the type of the invocation, as if LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType) was applied to its invocation and LinkerServices#asType(MethodHandle, MethodType) applied to its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard).

public MethodHandle

Returns:

a composite method handle.
compose
(final MethodHandle
the fallback method handle for when a switch point is invalidated, a guard returns false, or invalidating exception is thrown.
fallback
)

Composes the invocation, guard, switch points, and the exception into a composite method handle that knows how to fall back when the guard fails or the invocation is invalidated.

public MethodHandle

Returns:

a composite method handle.
compose
(final MethodHandle
the fallback method handle in case guard returns false.
guardFallback
,
final MethodHandle
the fallback method handle in case a switch point is invalidated.
switchpointFallback
,
final MethodHandle
the fallback method in case the exception handler triggers.
catchFallback
)

Composes the invocation, guard, switch points, and the exception into a composite method handle that knows how to fall back when the guard fails or the invocation is invalidated.

public GuardedInvocation

Returns:

an invocation that drops arguments
dropArguments
(final int
the position of the first argument being dropped
pos
,
final List<Class<?>>
the types of the values being dropped
valueTypes
)

Makes an invocation that drops arguments in both the invocation and the guard (if it exists and has at least pos parameters) with MethodHandles#dropArguments(MethodHandle, int, List).

public GuardedInvocation

Returns:

an invocation that drops arguments
dropArguments
(final int
the position of the first argument being dropped
pos
,
final Class<?>...
the types of the values being dropped
valueTypes
)

Makes an invocation that drops arguments in both the invocation and the guard (if it exists and has at least pos parameters) with MethodHandles#dropArguments(MethodHandle, int, Class...).

public GuardedInvocation

Returns:

a filtered invocation
filterArguments
(final int
the position of the first argument being filtered
pos
,
final MethodHandle...
the argument filters
filters
)

Applies argument filters to both the invocation and the guard (if it exists and has at least pos + 1 parameters) with MethodHandles#filterArguments(MethodHandle, int, MethodHandle...).

public Class<? extends Throwable>

Returns:

the exception type that if thrown should be used to invalidate the linkage. Can be null.
getException
()

Returns the exception type that if thrown by the invocation should invalidate the linkage of this guarded invocation.

public MethodHandle

Returns:

the guard method handle. Can be null.
getGuard
()

Returns the guard method handle.

public MethodHandle

Returns:

the invocation method handle. It will never be null.
getInvocation
()

Returns the invocation method handle.

public SwitchPoint[]

Returns:

the switch points that can be used to invalidate the linkage of this invocation handle. Can be null.
getSwitchPoints
()

Returns the switch points that can be used to invalidate the linkage of this invocation handle.

public boolean

Returns:

true if and only if this guarded invocation has at least one invalidated switch point.
hasBeenInvalidated
()

Returns true if and only if this guarded invocation has at least one invalidated switch point.

public GuardedInvocation

Returns:

a new guarded invocation with the replaced methods and the same switch point as this invocation.
replaceMethods
(final MethodHandle
the new invocation
newInvocation
,
final MethodHandle
the new guard
newGuard
)

Creates a new guarded invocation with different methods, preserving the switch point.

private GuardedInvocation
replaceMethodsOrThis(final MethodHandle newInvocation, final MethodHandle newGuard)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exceptionback to summary
private final Class<? extends Throwable> exception
guardback to summary
private final MethodHandle guard
invocationback to summary
private final MethodHandle invocation
switchPointsback to summary
private final SwitchPoint[] switchPoints

Constructor Detail

GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation)

Creates a new unconditional guarded invocation. It is unconditional as it has no invalidations.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

Exceptions
NullPointerException:
if invocation is null.
GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard)

Creates a new guarded invocation, with a guard method handle.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

guard:MethodHandle

the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null to represent an unconditional invocation.

Exceptions
NullPointerException:
if invocation is null.
GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation, final SwitchPoint switchPoint)

Creates a new guarded invocation that can be invalidated by a switch point.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

switchPoint:SwitchPoint

the optional switch point that can be used to invalidate this linkage. It can be null. If it is null, this represents an unconditional invocation.

Exceptions
NullPointerException:
if invocation is null.
GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint switchPoint)

Creates a new guarded invocation, with both a guard method handle and a switch point that can be used to invalidate it.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

guard:MethodHandle

the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If both it and the switch point are null, this represents an unconditional invocation.

switchPoint:SwitchPoint

the optional switch point that can be used to invalidate this linkage.

Exceptions
NullPointerException:
if invocation is null.
GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint switchPoint, final Class<? extends Throwable> exception)

Creates a new guarded invocation, with a guard method handle, a switch point that can be used to invalidate it, and an exception that if thrown when invoked also invalidates it.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

guard:MethodHandle

the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If it and the switch point and the exception are all null, this represents an unconditional invocation.

switchPoint:SwitchPoint

the optional switch point that can be used to invalidate this linkage.

exception:Class<? extends Throwable>

the optional exception type that is when thrown by the invocation also invalidates it.

Exceptions
NullPointerException:
if invocation is null.
GuardedInvocationback to summary
public GuardedInvocation(final MethodHandle invocation, final MethodHandle guard, final SwitchPoint[] switchPoints, final Class<? extends Throwable> exception)

Creates a new guarded invocation, with a guard method handle, any number of switch points that can be used to invalidate it, and an exception that if thrown when invoked also invalidates it.

Parameters
invocation:MethodHandle

the method handle representing the invocation. Must not be null.

guard:MethodHandle

the method handle representing the guard. Must have be compatible with the invocation handle as per MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle). For some useful guards, check out the Guards class. It can be null. If it and the exception are both null, and no switch points were specified, this represents an unconditional invocation.

switchPoints:SwitchPoint[]

optional switch points that can be used to invalidate this linkage.

exception:Class<? extends Throwable>

the optional exception type that is when thrown by the invocation also invalidates it.

Exceptions
NullPointerException:
if invocation is null.

Method Detail

addSwitchPointback to summary
public GuardedInvocation addSwitchPoint(final SwitchPoint newSwitchPoint)

Create a new guarded invocation with an added switch point.

Parameters
newSwitchPoint:SwitchPoint

new switch point. Can be null in which case this method return the current guarded invocation with no changes.

Returns:GuardedInvocation

a guarded invocation with the added switch point.

asTypeback to summary
public GuardedInvocation asType(final MethodType newType)

Changes the type of the invocation, as if MethodHandle#asType(MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard). If the invocation already is of the required type, returns this object.

Parameters
newType:MethodType

the new type of the invocation.

Returns:GuardedInvocation

a guarded invocation with the new type applied to it.

asTypeback to summary
public GuardedInvocation asType(final LinkerServices linkerServices, final MethodType newType)

Changes the type of the invocation, as if LinkerServices#asType(MethodHandle, MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard). If the invocation already is of the required type, returns this object.

Parameters
linkerServices:LinkerServices

the linker services to use for the conversion

newType:MethodType

the new type of the invocation.

Returns:GuardedInvocation

a guarded invocation with the new type applied to it.

asTypeback to summary
public GuardedInvocation asType(final CallSiteDescriptor desc)

Changes the type of the invocation, as if MethodHandle#asType(MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean for guard). If the invocation already is of the required type, returns this object.

Parameters
desc:CallSiteDescriptor

a call descriptor whose method type is adapted.

Returns:GuardedInvocation

a guarded invocation with the new type applied to it.

asTypeSafeReturnback to summary
public GuardedInvocation asTypeSafeReturn(final LinkerServices linkerServices, final MethodType newType)

Changes the type of the invocation, as if LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType) was applied to its invocation and LinkerServices#asType(MethodHandle, MethodType) applied to its guard, if it has one (with return type changed to boolean, and parameter count potentially truncated for the guard). If the invocation doesn't change its type, returns this object.

Parameters
linkerServices:LinkerServices

the linker services to use for the conversion

newType:MethodType

the new type of the invocation.

Returns:GuardedInvocation

a guarded invocation with the new type applied to it.

composeback to summary
public MethodHandle compose(final MethodHandle fallback)

Composes the invocation, guard, switch points, and the exception into a composite method handle that knows how to fall back when the guard fails or the invocation is invalidated.

Parameters
fallback:MethodHandle

the fallback method handle for when a switch point is invalidated, a guard returns false, or invalidating exception is thrown.

Returns:MethodHandle

a composite method handle.

composeback to summary
public MethodHandle compose(final MethodHandle guardFallback, final MethodHandle switchpointFallback, final MethodHandle catchFallback)

Composes the invocation, guard, switch points, and the exception into a composite method handle that knows how to fall back when the guard fails or the invocation is invalidated.

Parameters
guardFallback:MethodHandle

the fallback method handle in case guard returns false.

switchpointFallback:MethodHandle

the fallback method handle in case a switch point is invalidated.

catchFallback:MethodHandle

the fallback method in case the exception handler triggers.

Returns:MethodHandle

a composite method handle.

dropArgumentsback to summary
public GuardedInvocation dropArguments(final int pos, final List<Class<?>> valueTypes)

Makes an invocation that drops arguments in both the invocation and the guard (if it exists and has at least pos parameters) with MethodHandles#dropArguments(MethodHandle, int, List).

Parameters
pos:int

the position of the first argument being dropped

valueTypes:List<Class<?>>

the types of the values being dropped

Returns:GuardedInvocation

an invocation that drops arguments

dropArgumentsback to summary
public GuardedInvocation dropArguments(final int pos, final Class<?>... valueTypes)

Makes an invocation that drops arguments in both the invocation and the guard (if it exists and has at least pos parameters) with MethodHandles#dropArguments(MethodHandle, int, Class...).

Parameters
pos:int

the position of the first argument being dropped

valueTypes:Class<?>[]

the types of the values being dropped

Returns:GuardedInvocation

an invocation that drops arguments

filterArgumentsback to summary
public GuardedInvocation filterArguments(final int pos, final MethodHandle... filters)

Applies argument filters to both the invocation and the guard (if it exists and has at least pos + 1 parameters) with MethodHandles#filterArguments(MethodHandle, int, MethodHandle...).

Parameters
pos:int

the position of the first argument being filtered

filters:MethodHandle[]

the argument filters

Returns:GuardedInvocation

a filtered invocation

getExceptionback to summary
public Class<? extends Throwable> getException()

Returns the exception type that if thrown by the invocation should invalidate the linkage of this guarded invocation.

Returns:Class<? extends Throwable>

the exception type that if thrown should be used to invalidate the linkage. Can be null.

getGuardback to summary
public MethodHandle getGuard()

Returns the guard method handle.

Returns:MethodHandle

the guard method handle. Can be null.

getInvocationback to summary
public MethodHandle getInvocation()

Returns the invocation method handle.

Returns:MethodHandle

the invocation method handle. It will never be null.

getSwitchPointsback to summary
public SwitchPoint[] getSwitchPoints()

Returns the switch points that can be used to invalidate the linkage of this invocation handle.

Returns:SwitchPoint[]

the switch points that can be used to invalidate the linkage of this invocation handle. Can be null.

hasBeenInvalidatedback to summary
public boolean hasBeenInvalidated()

Returns true if and only if this guarded invocation has at least one invalidated switch point.

Returns:boolean

true if and only if this guarded invocation has at least one invalidated switch point.

replaceMethodsback to summary
public GuardedInvocation replaceMethods(final MethodHandle newInvocation, final MethodHandle newGuard)

Creates a new guarded invocation with different methods, preserving the switch point.

Parameters
newInvocation:MethodHandle

the new invocation

newGuard:MethodHandle

the new guard

Returns:GuardedInvocation

a new guarded invocation with the replaced methods and the same switch point as this invocation.

replaceMethodsOrThisback to summary
private GuardedInvocation replaceMethodsOrThis(final MethodHandle newInvocation, final MethodHandle newGuard)