- 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 theMethodHandles.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 theDynamicLinker
.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
for security-checked access to theMethodHandles.Lookup
object it carries. This lookup should be used to find method handles to set as targets of the call site described by this descriptor.
-
-
Field Summary
-
Fields declared in class jdk.dynalink.SecureLookupSupplier
GET_LOOKUP_PERMISSION_NAME
-
-
Constructor Summary
Constructors Constructor Description CallSiteDescriptor(MethodHandles.Lookup lookup, Operation operation, MethodType methodType)
Creates a new call site descriptor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CallSiteDescriptor
changeMethodType(MethodType newMethodType)
Finds or creates a call site descriptor that only differs in its method type from this descriptor.protected CallSiteDescriptor
changeMethodTypeInternal(MethodType newMethodType)
Finds or creates a call site descriptor that only differs in its method type from this descriptor.CallSiteDescriptor
changeOperation(Operation newOperation)
Finds or creates a call site descriptor that only differs in its operation from this descriptor.protected CallSiteDescriptor
changeOperationInternal(Operation newOperation)
Finds or creates a call site descriptor that only differs in its operation from this descriptor.boolean
equals(Object obj)
Returns true if this call site descriptor is equal to the passed object.MethodType
getMethodType()
The type of the method at the call site.Operation
getOperation()
Returns the operation at the call site.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.String
toString()
Returns the string representation of this call site descriptor, of the formatname(parameterTypes)returnType@lookup
.-
Methods declared in class jdk.dynalink.SecureLookupSupplier
getLookup, getLookupPrivileged
-
-
-
-
Constructor Detail
-
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 ajava.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 ajava.lang.invoke
bootstrap method, it should be the method type passed to the bootstrap.
-
-
Method Detail
-
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. InvokeschangeMethodTypeInternal(MethodType)
.- Parameters:
newMethodType
- the new method type- Returns:
- a call site descriptor with changed method type.
- Throws:
NullPointerException
- ifnewMethodType
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, anAssertionError
will be thrown fromchangeMethodType(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. InvokeschangeOperationInternal(Operation)
.- Parameters:
newOperation
- the new operation- Returns:
- a call site descriptor with the changed operation.
- Throws:
NullPointerException
- ifnewOperation
is null.SecurityException
- if the descriptor's lookup isn't theMethodHandles.publicLookup()
, and a security manager is present, and a check forRuntimePermission("dynalink.getLookup")
fails. This is necessary as changing the operation in the call site descriptor allows fabrication of descriptors for arbitrary operations with the lookup.
-
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, anAssertionError
will be thrown fromchangeOperation(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 sameMethodHandles.Lookup.lookupClass()
andMethodHandles.Lookup.lookupModes()
.- Overrides:
equals
in classObject
- 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:
Object.hashCode()
,HashMap
-
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 classObject
- Returns:
- value-based hash code for this call site descriptor.
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
-