Class CallSite

java.lang.Object
java.lang.invoke.CallSite
Direct Known Subclasses:
ConstantCallSite,MutableCallSite,VolatileCallSite

public abstract sealed classCallSiteextendsObjectpermitsConstantCallSite,MutableCallSite,VolatileCallSite
ACallSite is a holder for a variableMethodHandle, which is called itstarget. Aninvokedynamic instruction linked to aCallSite delegates all calls to the site's current target. ACallSite may be associated with severalinvokedynamic instructions, or it may be "free floating", associated with none. In any case, it may be invoked through an associated method handle called itsdynamic 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.

  • If a mutable target is not required, aninvokedynamic instruction may be permanently bound by means of aconstant call site.
  • If a mutable target is required which has volatile variable semantics, because updates to the target must be immediately and reliably witnessed by other threads, avolatile call site may be used.
  • Otherwise, if a mutable target is required, amutable call site may be used.

A non-constant call site may berelinked by changing its target. The new target must have the sametype 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));}

Sealed Class Hierarchy Graph:
Sealed class hierarchy graph for CallSiteSealed class hierarchy graph for CallSite
Since:
1.7
  • Method Details