public non-sealed class VolatileCallSite extends CallSite
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
.
Constructor | Description |
---|---|
VolatileCallSite |
Creates a call site with a volatile binding to its target. |
VolatileCallSite |
Creates a call site with a volatile binding to its target. |
Modifier and Type | Method | Description |
---|---|---|
final MethodHandle |
dynamicInvoker() |
Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site. |
final MethodHandle |
getTarget() |
Returns the target method of the call site, which behaves like a volatile field of the VolatileCallSite . |
void |
setTarget |
Updates the target method of this call site, as a volatile variable. |
public VolatileCallSite(MethodType type)
IllegalStateException
if called.type
- the method type that this call site will haveNullPointerException
- if the proposed type is nullpublic VolatileCallSite(MethodHandle target)
target
- the method handle that will be the initial target of the call siteNullPointerException
- if the proposed target is nullpublic final MethodHandle getTarget()
volatile
field of the VolatileCallSite
. The interactions of getTarget
with memory are the same as of a read from a volatile
field.
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.
public void setTarget(MethodHandle newTarget)
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
.
setTarget
in class CallSite
newTarget
- the new targetNullPointerException
- if the proposed new target is nullWrongMethodTypeException
- if the proposed new target has a method type that differs from the previous targetpublic final MethodHandle dynamicInvoker()
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)
dynamicInvoker
in class CallSite
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/invoke/VolatileCallSite.html