Class VolatileCallSite
java.lang.Object
java.lang.invoke.CallSite
java.lang.invoke.VolatileCallSite
A
VolatileCallSite is a CallSite whose target acts like a volatile variable.
An invokedynamic instruction linked to a VolatileCallSite sees updates
to its call site target immediately, even if the update occurs in another thread.
There may be a performance penalty for such tight coupling between threads.
Unlike MutableCallSite, there is no
syncAll operation on volatile
call sites, since every write to a volatile variable is implicitly
synchronized with reader threads.
In other respects, a VolatileCallSite is interchangeable
with MutableCallSite.
- Since:
- 1.7
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVolatileCallSite(MethodHandle target) Creates a call site with a volatile binding to its target.VolatileCallSite(MethodType type) Creates a call site with a volatile binding to its target. -
Method Summary
Modifier 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 avolatilefield of theVolatileCallSite.voidsetTarget(MethodHandle newTarget) Updates the target method of this call site, as a volatile variable.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
-
VolatileCallSite
Creates a call site with a volatile binding to its target. The initial target is set to a method handle of the given type which will throw anIllegalStateExceptionif called.- Parameters:
type- the method type that this call site will have- Throws:
NullPointerException- if the proposed type is null
-
VolatileCallSite
Creates a call site with a volatile binding to its target. The target is set to the given value.- Parameters:
target- the method handle that will be the initial target of the call site- Throws:
NullPointerException- if the proposed target is null
-
-
Method Details
-
getTarget
Returns the target method of the call site, which behaves like avolatilefield of theVolatileCallSite.The interactions of
getTargetwith memory are the same as of a read from avolatilefield.In particular, the current thread is required to issue a fresh read of the target from memory, and must not fail to see a recent update to the target by another thread.
-
setTarget
Updates the target method of this call site, as a volatile variable. The type of the new target must agree with the type of the old target.The interactions with memory are the same as of a write to a volatile field. In particular, any threads is guaranteed to see the updated target the next time it calls
getTarget.- Specified by:
setTargetin classCallSite- Parameters:
newTarget- the new target- Throws:
NullPointerException- if the proposed new target is nullWrongMethodTypeException- if the proposed new target has a method type that differs from the previous target- See Also:
-
dynamicInvoker
Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.This method is equivalent to the following code:
MethodHandle getTarget, invoker, result; getTarget = MethodHandles.publicLookup().bind(this, "getTarget", MethodType.methodType(MethodHandle.class)); invoker = MethodHandles.exactInvoker(this.type()); result = MethodHandles.foldArguments(invoker, getTarget)- Specified by:
dynamicInvokerin classCallSite- Returns:
- a method handle which always invokes this call site's current target
-