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
  • 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 - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
      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:
      a string representation of the object