Class ChainedCallSite
java.lang.Object
java.lang.invoke.CallSite
java.lang.invoke.MutableCallSite
jdk.dynalink.support.AbstractRelinkableCallSite
jdk.dynalink.support.ChainedCallSite
- All Implemented Interfaces:
RelinkableCallSite
A relinkable call site that implements a polymorphic inline caching strategy.
It remembers up to 8
GuardedInvocations it was linked with, and on
each relink request builds a cascading chain of method handles of one
invocation falling back to the next one. The number of remembered invocations
can be customized by overriding getMaxChainLength() in a subclass.
When this call site is relinked with a new invocation and the length of the
chain is already at the maximum, it will throw away the oldest invocation.
Invocations with invalidated switch points and ones for which their
invalidating exception triggered are removed eagerly from the chain. The
invocations are never reordered; the most recently linked method handle is
always at the start of the chain and the least recently linked at its end.
The call site can be safely relinked on more than one thread concurrently.
Race conditions in linking are resolved by throwing away the
GuardedInvocation produced on the losing thread without incorporating
it into the chain, so it can lead to repeated linking for the same arguments.- Since:
- 9
-
Constructor Summary
ConstructorsConstructorDescriptionChainedCallSite(CallSiteDescriptor descriptor) Creates a new chained call site. -
Method Summary
Modifier and TypeMethodDescriptionprotected intThe maximum number of method handles in the chain.voidrelink(GuardedInvocation guardedInvocation, MethodHandle relinkAndInvoke) This method will be called by the dynamic linker every time the call site is relinked (but seeRelinkableCallSite.resetAndRelink(GuardedInvocation, MethodHandle)for an exception).voidresetAndRelink(GuardedInvocation guardedInvocation, MethodHandle relinkAndInvoke) This method will be called by the dynamic linker every time the call site is relinked and the linker wishes the call site to throw away any prior linkage state (that is how it differs fromRelinkableCallSite.relink(GuardedInvocation, MethodHandle)).Methods declared in class AbstractRelinkableCallSite
getDescriptor, initializeModifier and TypeMethodDescriptionReturns the descriptor for this call site.voidinitialize(MethodHandle relinkAndInvoke) Invoked by dynamic linker to initialize the relinkable call site by setting a relink-and-invoke method handle.Methods declared in class MutableCallSite
dynamicInvoker, getTarget, setTarget, syncAllModifier and TypeMethodDescriptionfinal MethodHandleProduces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.final MethodHandleReturns the target method of the call site, which behaves like a normal field of theMutableCallSite.voidsetTarget(MethodHandle newTarget) Updates the target method of this call site, as a normal variable.static voidsyncAll(MutableCallSite[] sites) Performs a synchronization operation on each call site in the given array, forcing all other threads to throw away any cached values previously loaded from the target of any of the call sites.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()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.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(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 bynotifyornotifyAll) or the expiration of the timeout.final voidwait(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 bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
ChainedCallSite
Creates a new chained call site.- Parameters:
descriptor- the descriptor for the call site.
-
-
Method Details
-
getMaxChainLength
protected int getMaxChainLength()The maximum number of method handles in the chain. Defaults to 8. You can override it in a subclass if you need to change the value.- Returns:
- the maximum number of method handles in the chain. The return
value is checked, and if your override returns a value less than 1, a
RuntimeExceptionwill be thrown.
-
relink
Description copied from interface:RelinkableCallSiteThis method will be called by the dynamic linker every time the call site is relinked (but seeRelinkableCallSite.resetAndRelink(GuardedInvocation, MethodHandle)for an exception). It will be passed aGuardedInvocationthat the call site should incorporate into its target method handle. When this method is called, the call site is allowed to keep other non-invalidated invocations around for implementation of polymorphic inline caches and compose them with this invocation to form its final target.- Parameters:
guardedInvocation- the guarded invocation that the call site should incorporate into its target method handle.relinkAndInvoke- a relink-and-invoke method handle. This is a method handle matching the method type of the call site that is supplied by theDynamicLinkeras a callback. It should be used by this call site as the ultimate fallback when it can't invoke its target with the passed arguments. The fallback method is such that when it's invoked, it'll try to obtain an adequate targetGuardedInvocationfor the invocation, and subsequently invokeRelinkableCallSite.relink(GuardedInvocation, MethodHandle)orRelinkableCallSite.resetAndRelink(GuardedInvocation, MethodHandle), and finally invoke the target.
-
resetAndRelink
Description copied from interface:RelinkableCallSiteThis method will be called by the dynamic linker every time the call site is relinked and the linker wishes the call site to throw away any prior linkage state (that is how it differs fromRelinkableCallSite.relink(GuardedInvocation, MethodHandle)). It will be passed aGuardedInvocationthat the call site should use to build its new target method handle. When this method is called, the call site is discouraged from keeping any previous state, and is supposed to only link the current invocation.- Parameters:
guardedInvocation- the guarded invocation that the call site should use to build its target method handle.relinkAndInvoke- a relink-and-invoke method handle. This is a method handle matching the method type of the call site that is supplied by theDynamicLinkeras a callback. It should be used by this call site as the ultimate fallback when it can't invoke its target with the passed arguments. The fallback method is such that when it's invoked, it'll try to obtain an adequate targetGuardedInvocationfor the invocation, and subsequently invokeRelinkableCallSite.relink(GuardedInvocation, MethodHandle)orRelinkableCallSite.resetAndRelink(GuardedInvocation, MethodHandle), and finally invoke the target.
-