- java.lang.Object
-
- java.lang.invoke.CallSite
-
- Direct Known Subclasses:
ConstantCallSite,MutableCallSite,VolatileCallSite
public abstract class CallSite extends Object
CallSite is used by the invokedynamic bytecode to hold a reference to the MethodHandle target of the instruction.Although CallSite is an abstract class, it cannot be directly sub-classed. Instead, it is necessary to sub-class one of the three implementation classes:
- ConstantCallSite - if the target will never change
- VolatileCallSite - if the target is expected to frequently change. Changes will be immediately visible in all threads.
- MutableCallSite - if the target is expected to rarely change and threads may see previous values of the target for some time.
CallSites are created with a MethodType and permanently bound to that type. Any changes to the target MethodHandle must be of the identical MethodType or a WrongMethodTypeException will be thrown.
- Since:
- 1.7
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract MethodHandledynamicInvoker()Return a MethodHandle equivalent to the invokedynamic instruction on this CallSite.abstract MethodHandlegetTarget()Return the target MethodHandle of the CallSite.abstract voidsetTarget(MethodHandle nextTarget)Set the CallSite's target to be nextTarget.MethodTypetype()Report the type of CallSite's target MethodHandle.
-
-
-
Method Detail
-
type
public MethodType type()
Report the type of CallSite's target MethodHandle. A CallSite cannot change its type.- Returns:
- The permanent MethodType of this CallSite.
-
getTarget
public abstract MethodHandle getTarget()
Return the target MethodHandle of the CallSite.- Returns:
- the current target MethodHandle
-
setTarget
public abstract void setTarget(MethodHandle nextTarget) throws WrongMethodTypeException, NullPointerException
Set the CallSite's target to be nextTarget. The nextTarget MethodHandle must have the same type as the CallSite.- Parameters:
nextTarget- - the new target value for the CallSite- Throws:
WrongMethodTypeException- - if the type of nextTarget differs from that of the CallSite.NullPointerException- - if nextTarget is null.
-
dynamicInvoker
public abstract MethodHandle dynamicInvoker()
Return a MethodHandle equivalent to the invokedynamic instruction on this CallSite. The MethodHandle is equivalent to getTarget().invokeExact(args).- Returns:
- a MethodHandle that is equivalent to an invokedynamic instruction on this CallSite.
-
-