Module java.base

Class 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 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
      • 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.