Class CallSiteDescriptor

java.lang.Object
jdk.dynalink.SecureLookupSupplier
jdk.dynalink.CallSiteDescriptor

public class CallSiteDescriptor extends SecureLookupSupplier
Call site descriptors contain all the information necessary for linking a call site. This information is normally passed as parameters to bootstrap methods and consists of the MethodHandles.Lookup object on the caller class in which the call site occurs, the dynamic operation at the call site, and the method type of the call site. CallSiteDescriptor objects are used in Dynalink to capture and store these parameters for subsequent use by the DynamicLinker.

The constructors of built-in RelinkableCallSite implementations all take a call site descriptor.

Call site descriptors must be immutable. You can use this class as-is or you can subclass it, especially if you need to add further information to the descriptors (typically, values passed in additional parameters to the bootstrap method. Since the descriptors must be immutable, you can set up a cache for equivalent descriptors to have the call sites share them.

The class extends SecureLookupSupplier to encapsulate the MethodHandles.Lookup object. This lookup should be used to find method handles to set as targets of the call site described by this descriptor.

Since:
9
  • Field Summary

    Fields declared in class SecureLookupSupplier

    GET_LOOKUP_PERMISSION_NAME
    Modifier and Type
    Field
    Description
    static final String
    The name of a runtime permission required to successfully invoke the SecureLookupSupplier.getLookup() method.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new call site descriptor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Finds or creates a call site descriptor that only differs in its method type from this descriptor.
    Finds or creates a call site descriptor that only differs in its method type from this descriptor.
    changeOperation(Operation newOperation)
    Finds or creates a call site descriptor that only differs in its operation from this descriptor.
    Finds or creates a call site descriptor that only differs in its operation from this descriptor.
    boolean
    Returns true if this call site descriptor is equal to the passed object.
    The type of the method at the call site.
    final Operation
    Returns the operation at the call site.
    int
    Returns a value-based hash code of this call site descriptor computed from its operation, method type, and lookup object's lookup class and lookup modes.
    Returns the string representation of this call site descriptor, of the format name(parameterTypes)returnType@lookup.

    Methods declared in class SecureLookupSupplier

    getLookup, getLookupPrivileged
    Modifier and Type
    Method
    Description
    Returns the lookup secured by this SecureLookupSupplier.
    protected final MethodHandles.Lookup
    Returns the lookup secured by this SecureLookupSupplier.

    Methods declared in class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
  • Constructor Details

    • CallSiteDescriptor

      public CallSiteDescriptor(MethodHandles.Lookup lookup, Operation operation, MethodType methodType)
      Creates a new call site descriptor.
      Parameters:
      lookup - the lookup object describing the class the call site belongs to. When creating descriptors from a java.lang.invoke bootstrap method, it should be the lookup passed to the bootstrap.
      operation - the dynamic operation at the call site.
      methodType - the method type of the call site. When creating descriptors from a java.lang.invoke bootstrap method, it should be the method type passed to the bootstrap.
  • Method Details

    • getOperation

      public final Operation getOperation()
      Returns the operation at the call site.
      Returns:
      the operation at the call site.
    • getMethodType

      public final MethodType getMethodType()
      The type of the method at the call site.
      Returns:
      type of the method at the call site.
    • changeMethodType

      public final CallSiteDescriptor changeMethodType(MethodType newMethodType)
      Finds or creates a call site descriptor that only differs in its method type from this descriptor. Invokes changeMethodTypeInternal(MethodType).
      Parameters:
      newMethodType - the new method type
      Returns:
      a call site descriptor with changed method type.
      Throws:
      NullPointerException - if newMethodType is null.
    • changeMethodTypeInternal

      protected CallSiteDescriptor changeMethodTypeInternal(MethodType newMethodType)
      Finds or creates a call site descriptor that only differs in its method type from this descriptor. Subclasses must override this method to return an object of their exact class. If an overridden method changes something other than the method type in the descriptor (its class, lookup, or operation), or returns null, an AssertionError will be thrown from changeMethodType(MethodType).
      Parameters:
      newMethodType - the new method type
      Returns:
      a call site descriptor with the changed method type.
    • changeOperation

      public final CallSiteDescriptor changeOperation(Operation newOperation)
      Finds or creates a call site descriptor that only differs in its operation from this descriptor. Invokes changeOperationInternal(Operation).
      Parameters:
      newOperation - the new operation
      Returns:
      a call site descriptor with the changed operation.
      Throws:
      NullPointerException - if newOperation is null.
    • changeOperationInternal

      protected CallSiteDescriptor changeOperationInternal(Operation newOperation)
      Finds or creates a call site descriptor that only differs in its operation from this descriptor. Subclasses must override this method to return an object of their exact class. If an overridden method changes something other than the operation in the descriptor (its class, lookup, or method type), or returns null, an AssertionError will be thrown from changeOperation(Operation).
      Parameters:
      newOperation - the new operation
      Returns:
      a call site descriptor with the changed operation.
    • equals

      public boolean equals(Object obj)
      Returns true if this call site descriptor is equal to the passed object. It is considered equal if the other object is of the exact same class, their operations and method types are equal, and their lookups have the same MethodHandles.Lookup.lookupClass() and MethodHandles.Lookup.lookupModes().
      Overrides:
      equals in class Object
      Parameters:
      obj - Object the object to compare with this object.
      Returns:
      boolean true if the object is the same as this object false if it is different from this object.
      See Also:
    • hashCode

      public int hashCode()
      Returns a value-based hash code of this call site descriptor computed from its operation, method type, and lookup object's lookup class and lookup modes.
      Overrides:
      hashCode in class Object
      Returns:
      value-based hash code for this call site descriptor.
      See Also:
    • toString

      public String toString()
      Returns the string representation of this call site descriptor, of the format name(parameterTypes)returnType@lookup.
      Overrides:
      toString in class Object
      Returns:
      String a printable representation for the receiver.