GuardedInvocation (Java SE 11 & JDK 11 ) (original) (raw)
Constructor Summary
Constructors
Constructor Description GuardedInvocation(MethodHandle invocation) Creates a new unconditional guarded invocation. GuardedInvocation(MethodHandle invocation,MethodHandle guard) Creates a new guarded invocation, with a guard method handle. GuardedInvocation(MethodHandle invocation,MethodHandle guard,SwitchPoint switchPoint) Creates a new guarded invocation, with both a guard method handle and a switch point that can be used to invalidate it. GuardedInvocation(MethodHandle invocation,MethodHandle guard,SwitchPoint[] switchPoints,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. GuardedInvocation(MethodHandle invocation,MethodHandle guard,SwitchPoint switchPoint,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. GuardedInvocation(MethodHandle invocation,SwitchPoint switchPoint) Creates a new guarded invocation that can be invalidated by a switch point. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description GuardedInvocation addSwitchPoint(SwitchPoint newSwitchPoint) Create a new guarded invocation with an added switch point. GuardedInvocation asType(MethodType newType) Changes the type of the invocation, as ifMethodHandle.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). GuardedInvocation asType(CallSiteDescriptor desc) Changes the type of the invocation, as ifMethodHandle.asType(MethodType) was applied to its invocation and its guard, if it has one (with return type changed to boolean for guard). GuardedInvocation asType(LinkerServices linkerServices,MethodType newType) Changes the type of the invocation, as ifLinkerServices.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). GuardedInvocation asTypeSafeReturn(LinkerServices linkerServices,MethodType newType) Changes the type of the invocation, as ifLinkerServices.asTypeLosslessReturn(MethodHandle, MethodType) was applied to its invocation andLinkerServices.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). MethodHandle compose(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. MethodHandle compose(MethodHandle guardFallback,MethodHandle switchpointFallback,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. GuardedInvocation dropArguments(int pos,Class<?>... valueTypes) Makes an invocation that drops arguments in both the invocation and the guard (if it exists and has at least pos parameters) withMethodHandles.dropArguments(MethodHandle, int, Class...). GuardedInvocation dropArguments(int pos,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) withMethodHandles.dropArguments(MethodHandle, int, List). GuardedInvocation filterArguments(int pos,MethodHandle... filters) Applies argument filters to both the invocation and the guard (if it exists and has at least pos + 1 parameters) withMethodHandles.filterArguments(MethodHandle, int, MethodHandle...). Class<? extends Throwable> getException() Returns the exception type that if thrown by the invocation should invalidate the linkage of this guarded invocation. MethodHandle getGuard() Returns the guard method handle. MethodHandle getInvocation() Returns the invocation method handle. SwitchPoint[] getSwitchPoints() Returns the switch points that can be used to invalidate the linkage of this invocation handle. boolean hasBeenInvalidated() Returns true if and only if this guarded invocation has at least one invalidated switch point. GuardedInvocation replaceMethods(MethodHandle newInvocation,MethodHandle newGuard) Creates a new guarded invocation with different methods, preserving the switch point. * ### Methods declared in class java.lang.[Object](../../../../java.base/java/lang/Object.html "class in java.lang") `[clone](../../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long,int%29)`
Constructor Detail
* #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation) Creates a new unconditional guarded invocation. It is unconditional as it has no invalidations. Parameters: `invocation` \- the method handle representing the invocation. Must not be null. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null. * #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") guard) Creates a new guarded invocation, with a guard method handle. Parameters: `invocation` \- the method handle representing the invocation. Must not be null. `guard` \- the method handle representing the guard. Must have be compatible with the `invocation` handle as per[MethodHandles.guardWithTest(MethodHandle, MethodHandle, MethodHandle)](../../../../java.base/java/lang/invoke/MethodHandles.html#guardWithTest%28java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle%29). For some useful guards, check out the [Guards](support/Guards.html "class in jdk.dynalink.linker.support") class. It can be null to represent an unconditional invocation. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null. * #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation, [SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke") switchPoint) Creates a new guarded invocation that can be invalidated by a switch point. Parameters: `invocation` \- the method handle representing the invocation. Must not be null. `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. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null. * #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") guard, [SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke") 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` \- the method handle representing the invocation. Must not be null. `guard` \- the method handle representing the guard. Must have be compatible with the `invocation` handle as per[MethodHandles.guardWithTest(MethodHandle, MethodHandle, MethodHandle)](../../../../java.base/java/lang/invoke/MethodHandles.html#guardWithTest%28java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle%29). For some useful guards, check out the [Guards](support/Guards.html "class in jdk.dynalink.linker.support") class. It can be null. If both it and the switch point are null, this represents an unconditional invocation. `switchPoint` \- the optional switch point that can be used to invalidate this linkage. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null. * #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") guard, [SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke") switchPoint, [Class](../../../../java.base/java/lang/Class.html "class in java.lang")<? extends [Throwable](../../../../java.base/java/lang/Throwable.html "class in java.lang")> 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` \- the method handle representing the invocation. Must not be null. `guard` \- the method handle representing the guard. Must have be compatible with the `invocation` handle as per[MethodHandles.guardWithTest(MethodHandle, MethodHandle, MethodHandle)](../../../../java.base/java/lang/invoke/MethodHandles.html#guardWithTest%28java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle%29). For some useful guards, check out the [Guards](support/Guards.html "class in jdk.dynalink.linker.support") class. It can be null. If it and the switch point and the exception are all null, this represents an unconditional invocation. `switchPoint` \- the optional switch point that can be used to invalidate this linkage. `exception` \- the optional exception type that is when thrown by the invocation also invalidates it. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null. * #### GuardedInvocation public GuardedInvocation([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") invocation, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") guard, [SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke")[] switchPoints, [Class](../../../../java.base/java/lang/Class.html "class in java.lang")<? extends [Throwable](../../../../java.base/java/lang/Throwable.html "class in java.lang")> 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` \- the method handle representing the invocation. Must not be null. `guard` \- the method handle representing the guard. Must have be compatible with the `invocation` handle as per[MethodHandles.guardWithTest(MethodHandle, MethodHandle, MethodHandle)](../../../../java.base/java/lang/invoke/MethodHandles.html#guardWithTest%28java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle,java.lang.invoke.MethodHandle%29). For some useful guards, check out the [Guards](support/Guards.html "class in jdk.dynalink.linker.support") 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` \- optional switch points that can be used to invalidate this linkage. `exception` \- the optional exception type that is when thrown by the invocation also invalidates it. Throws: `[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")` \- if invocation is null.
Method Detail
* #### getInvocation public [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") getInvocation() Returns the invocation method handle. Returns: the invocation method handle. It will never be null. * #### getGuard public [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") getGuard() Returns the guard method handle. Returns: the guard method handle. Can be null. * #### getSwitchPoints public [SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke")[] getSwitchPoints() Returns the switch points that can be used to invalidate the linkage of this invocation handle. Returns: the switch points that can be used to invalidate the linkage of this invocation handle. Can be null. * #### getException public [Class](../../../../java.base/java/lang/Class.html "class in java.lang")<? extends [Throwable](../../../../java.base/java/lang/Throwable.html "class in java.lang")> getException() Returns the exception type that if thrown by the invocation should invalidate the linkage of this guarded invocation. Returns: the exception type that if thrown should be used to invalidate the linkage. Can be null. * #### hasBeenInvalidated public boolean hasBeenInvalidated() Returns true if and only if this guarded invocation has at least one invalidated switch point. Returns: true if and only if this guarded invocation has at least one invalidated switch point. * #### replaceMethods public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") replaceMethods([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") newInvocation, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") newGuard) Creates a new guarded invocation with different methods, preserving the switch point. Parameters: `newInvocation` \- the new invocation `newGuard` \- the new guard Returns: a new guarded invocation with the replaced methods and the same switch point as this invocation. * #### addSwitchPoint public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") addSwitchPoint([SwitchPoint](../../../../java.base/java/lang/invoke/SwitchPoint.html "class in java.lang.invoke") newSwitchPoint) Create a new guarded invocation with an added switch point. Parameters: `newSwitchPoint` \- new switch point. Can be null in which case this method return the current guarded invocation with no changes. Returns: a guarded invocation with the added switch point. * #### asType public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") asType([MethodType](../../../../java.base/java/lang/invoke/MethodType.html "class in java.lang.invoke") newType) Changes the type of the invocation, as if[MethodHandle.asType(MethodType)](../../../../java.base/java/lang/invoke/MethodHandle.html#asType%28java.lang.invoke.MethodType%29) 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` \- the new type of the invocation. Returns: a guarded invocation with the new type applied to it. * #### asType public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") asType([LinkerServices](LinkerServices.html "interface in jdk.dynalink.linker") linkerServices, [MethodType](../../../../java.base/java/lang/invoke/MethodType.html "class in java.lang.invoke") newType) Changes the type of the invocation, as if[LinkerServices.asType(MethodHandle, MethodType)](LinkerServices.html#asType%28java.lang.invoke.MethodHandle,java.lang.invoke.MethodType%29) 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` \- the linker services to use for the conversion `newType` \- the new type of the invocation. Returns: a guarded invocation with the new type applied to it. * #### asTypeSafeReturn public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") asTypeSafeReturn([LinkerServices](LinkerServices.html "interface in jdk.dynalink.linker") linkerServices, [MethodType](../../../../java.base/java/lang/invoke/MethodType.html "class in java.lang.invoke") newType) Parameters: `linkerServices` \- the linker services to use for the conversion `newType` \- the new type of the invocation. Returns: a guarded invocation with the new type applied to it. * #### asType public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") asType([CallSiteDescriptor](../CallSiteDescriptor.html "class in jdk.dynalink") desc) Changes the type of the invocation, as if[MethodHandle.asType(MethodType)](../../../../java.base/java/lang/invoke/MethodHandle.html#asType%28java.lang.invoke.MethodType%29) 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` \- a call descriptor whose method type is adapted. Returns: a guarded invocation with the new type applied to it. * #### filterArguments public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") filterArguments(int pos, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke")... filters) Parameters: `pos` \- the position of the first argument being filtered `filters` \- the argument filters Returns: a filtered invocation * #### dropArguments public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") dropArguments(int pos, [List](../../../../java.base/java/util/List.html "interface in java.util")<[Class](../../../../java.base/java/lang/Class.html "class in java.lang")<?>> valueTypes) Parameters: `pos` \- the position of the first argument being dropped `valueTypes` \- the types of the values being dropped Returns: an invocation that drops arguments * #### dropArguments public [GuardedInvocation](GuardedInvocation.html "class in jdk.dynalink.linker") dropArguments(int pos, [Class](../../../../java.base/java/lang/Class.html "class in java.lang")<?>... valueTypes) Parameters: `pos` \- the position of the first argument being dropped `valueTypes` \- the types of the values being dropped Returns: an invocation that drops arguments * #### compose public [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") compose([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") 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` \- the fallback method handle for when a switch point is invalidated, a guard returns false, or invalidating exception is thrown. Returns: a composite method handle. * #### compose public [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") compose([MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") guardFallback, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") switchpointFallback, [MethodHandle](../../../../java.base/java/lang/invoke/MethodHandle.html "class in java.lang.invoke") 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: `switchpointFallback` \- the fallback method handle in case a switch point is invalidated. `guardFallback` \- the fallback method handle in case guard returns false. `catchFallback` \- the fallback method in case the exception handler triggers. Returns: a composite method handle.