CallSite is a holder for a variable MethodHandle,
which is called its target.
An invokedynamic instruction linked to a CallSite delegates
all calls to the site's current target.
A CallSite may be associated with several invokedynamic
instructions, or it may be "free floating", associated with none.
In any case, it may be invoked through an associated method handle
called its dynamic invoker.
CallSite is an abstract sealed class which does not allow
direct subclassing by users. It has three immediate,
concrete non-sealed subclasses that may be either instantiated or subclassed.
invokedynamic instruction
may be permanently bound by means of a constant call site.
A non-constant call site may be relinked by changing its target. The new target must have the same type as the previous target. Thus, though a call site can be relinked to a series of successive targets, it cannot change its type.
Here is a sample use of call sites and bootstrap methods which links every dynamic call site to print its arguments:
static void test() throws Throwable { // THE FOLLOWING LINE IS PSEUDOCODE FOR A JVM INSTRUCTION InvokeDynamic[#bootstrapDynamic].baz("baz arg", 2, 3.14); } private static void printArgs(Object... args) { System.out.println(java.util.Arrays.deepToString(args)); } private static final MethodHandle printArgs; static { MethodHandles.Lookup lookup = MethodHandles.lookup(); Class thisClass = lookup.lookupClass(); // (who am I?) printArgs = lookup.findStatic(thisClass, "printArgs", MethodType.methodType(void.class, Object[].class)); } private static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) { // ignore caller and name, but match the type: return new ConstantCallSite(printArgs.asType(type)); }
| Modifier and Type | Field and Description |
|---|---|
| private static MethodHandle | |
| pack-priv final MethodHandle | |
| private static long | |
| private static MethodHandle |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | CallSite(MethodHandle
the method handle which will be the initial target of the call site target)Make a call site object equipped with an initial target method handle. |
| pack-priv | CallSite(MethodType
the desired type of the call site targetType, MethodHandle a hook which will bind the call site to the target method handle createTargetHook)Make a call site object equipped with an initial target method handle. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public abstract MethodHandle | Returns: a method handle which always invokes this call site's current targetProduces a method handle equivalent to an invokedynamic instruction which has been linked to this call site. |
| public abstract MethodHandle | Returns: the current linkage state of the call site, its target method handleReturns the target method of the call site, according to the behavior defined by this call site's specific class. |
| private static MethodHandle | |
| private static long | |
| pack-priv final MethodHandle | |
| pack-priv MethodHandle | |
| pack-priv static CallSite | makeSite(MethodHandle bootstrapMethod, String name, MethodType type, Object info, Class<?> callerClass)
|
| private MethodHandle | |
| public abstract void | setTarget(MethodHandle
the new target newTarget)Updates the target method of this call site, according to the behavior defined by this call site's specific class. |
| pack-priv final void | |
| pack-priv final void | |
| public MethodType | Returns: the type of the current target, which is also the type of any future targetReturns the type of this call site's target. |
| private static Object | uninitializedCallSite(Object... ignore)
This guy is rolled into the default target if a MethodType is supplied to the constructor. |
| private static MethodHandle | |
| private static WrongMethodTypeException |
| GET_TARGET | back to summary |
|---|---|
| private static MethodHandle GET_TARGET
| |
| target | back to summary |
|---|---|
| pack-priv final MethodHandle target | |
| TARGET_OFFSET | back to summary |
|---|---|
| private static long TARGET_OFFSET
| |
| THROW_UCS | back to summary |
|---|---|
| private static MethodHandle THROW_UCS
| |
| CallSite | back to summary |
|---|---|
| pack-priv CallSite(MethodType type) Make a blank call site object with the given method type.
An initial target method is supplied which will throw
an
Before this
| |
| CallSite | back to summary |
|---|---|
| pack-priv CallSite(MethodHandle target) Make a call site object equipped with an initial target method handle.
| |
| CallSite | back to summary |
|---|---|
| pack-priv CallSite(MethodType targetType, MethodHandle createTargetHook) throws Throwable Make a call site object equipped with an initial target method handle.
| |
| checkTargetChange | back to summary |
|---|---|
| private void checkTargetChange(MethodHandle newTarget) | |
| dynamicInvoker | back to summary |
|---|---|
| public abstract MethodHandle dynamicInvoker() Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site. This method is equivalent to the following code:
| |
| getTarget | back to summary |
|---|---|
| public abstract MethodHandle getTarget() Returns the target method of the call site, according to the
behavior defined by this call site's specific class.
The immediate subclasses of
| |
| getTargetHandle | back to summary |
|---|---|
| private static MethodHandle getTargetHandle() | |
| getTargetOffset | back to summary |
|---|---|
| private static long getTargetOffset() | |
| getTargetVolatile | back to summary |
|---|---|
| pack-priv final MethodHandle getTargetVolatile() | |
| makeDynamicInvoker | back to summary |
|---|---|
| pack-priv MethodHandle makeDynamicInvoker() | |
| makeSite | back to summary |
|---|---|
| pack-priv static CallSite makeSite(MethodHandle bootstrapMethod, String name, MethodType type, Object info, Class<?> callerClass) | |
| makeUninitializedCallSite | back to summary |
|---|---|
| private MethodHandle makeUninitializedCallSite(MethodType targetType) | |
| setTarget | back to summary |
|---|---|
| public abstract void setTarget(MethodHandle newTarget) Updates the target method of this call site, according to the
behavior defined by this call site's specific class.
The immediate subclasses of The type of the new target must be equal to the type of the old target.
| |
| setTargetNormal | back to summary |
|---|---|
| pack-priv final void setTargetNormal(MethodHandle newTarget) | |
| setTargetVolatile | back to summary |
|---|---|
| pack-priv final void setTargetVolatile(MethodHandle newTarget) | |
| type | back to summary |
|---|---|
| public MethodType type() Returns the type of this call site's target.
Although targets may change, any call site's type is permanent, and can never change to an unequal type.
The
| |
| uninitializedCallSite | back to summary |
|---|---|
| private static Object uninitializedCallSite(Object... ignore) This guy is rolled into the default target if a MethodType is supplied to the constructor. | |
| uninitializedCallSiteHandle | back to summary |
|---|---|
| private static MethodHandle uninitializedCallSiteHandle() | |
| wrongTargetType | back to summary |
|---|---|
| private static WrongMethodTypeException wrongTargetType(MethodHandle target, MethodType type) | |