Module java.base

Class ConstantCallSite


  • public class ConstantCallSite
    extends CallSite
    A ConstantCallSite is permanently bound to its initial target MethodHandle. Any call to setTarget(MethodHandle) will result in an UnsupportedOperationException.
    Since:
    1.7
    • Constructor Detail

      • ConstantCallSite

        public ConstantCallSite​(MethodHandle permanentTarget)
        Create a ConstantCallSite with a target MethodHandle that cannot change.
        Parameters:
        permanentTarget - - the target MethodHandle to permanently associate with this CallSite.
      • ConstantCallSite

        protected ConstantCallSite​(MethodType targetType,
                                   MethodHandle hook)
                            throws Throwable,
                                   WrongMethodTypeException,
                                   NullPointerException,
                                   ClassCastException
        Create a ConstantCallSite and assign the hook MethodHandle's result to its permanent target. The hook MethodHandle is invoked as though by (@link MethodHandle#invoke(this)) and must return a MethodHandle that will be installed as the ConstantCallSite's target.

        The hook MethodHandle is required if the ConstantCallSite's target needs to have access to the ConstantCallSite instance. This is an action that user code cannot perform on its own.

        The hook must return a MethodHandle that is exactly of type targetType.

        Until the result of the hook has been installed in the ConstantCallSite, any call to getTarget() or dynamicInvoker() will throw an IllegalStateException. It is always valid to call type().

        Parameters:
        targetType - - the type of the ConstantCallSite's target
        hook - - the hook handle, with signature (ConstantCallSite)MethodHandle
        Throws:
        Throwable - anything thrown by the hook.
        WrongMethodTypeException - if the hook has the wrong signature or returns a MethodHandle with the wrong signature
        NullPointerException - if the hook is null or returns null
        ClassCastException - if the result of the hook is not a MethodHandle
    • Method Detail

      • dynamicInvoker

        public final MethodHandle dynamicInvoker()
                                          throws IllegalStateException
        Return the target MethodHandle of this CallSite.
        Specified by:
        dynamicInvoker in class CallSite
        Returns:
        a MethodHandle that is equivalent to an invokedynamic instruction on this CallSite.
        Throws:
        IllegalStateException - - if the target has not yet been assigned in the ConstantCallSite constructor
      • getTarget

        public final MethodHandle getTarget()
                                     throws IllegalStateException
        Return the target MethodHandle of this CallSite. The target is defined as though it where a final field.
        Specified by:
        getTarget in class CallSite
        Returns:
        the current target MethodHandle
        Throws:
        IllegalStateException - - if the target has not yet been assigned in the ConstantCallSite constructor
      • setTarget

        public final void setTarget​(MethodHandle newTarget)
        Throws UnsupportedOperationException as a ConstantCallSite is permanently bound to its initial target MethodHandle.
        Specified by:
        setTarget in class CallSite
        Parameters:
        newTarget - - the new target value for the CallSite