- java.lang.Object
-
- java.lang.invoke.CallSite
-
- java.lang.invoke.VolatileCallSite
-
public class VolatileCallSite extends CallSite
AVolatileCallSite
is aCallSite
whose target acts like a volatile variable. Aninvokedynamic
instruction linked to aVolatileCallSite
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 withMutableCallSite
.- See Also:
MutableCallSite
-
-
Constructor Summary
Constructors Constructor and Description VolatileCallSite(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
Methods Modifier and Type Method and Description MethodHandle
dynamicInvoker()
Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.MethodHandle
getTarget()
Returns the target method of the call site, which behaves like avolatile
field of theVolatileCallSite
.void
setTarget(MethodHandle newTarget)
Updates the target method of this call site, as a volatile variable.-
Methods inherited from class java.lang.invoke.CallSite
type
-
-
-
-
Constructor Detail
-
VolatileCallSite
public VolatileCallSite(MethodType type)
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 anIllegalStateException
if called.- Parameters:
type
- the method type that this call site will have- Throws:
NullPointerException
- if the proposed type is null
-
VolatileCallSite
public VolatileCallSite(MethodHandle target)
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 Detail
-
getTarget
public final MethodHandle getTarget()
Returns the target method of the call site, which behaves like avolatile
field of theVolatileCallSite
.The interactions of
getTarget
with memory are the same as of a read from avolatile
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.
- Specified by:
getTarget
in classCallSite
- Returns:
- the linkage state of this call site, a method handle which can change over time
- See Also:
setTarget(java.lang.invoke.MethodHandle)
-
setTarget
public void setTarget(MethodHandle newTarget)
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:
setTarget
in 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:
getTarget()
-
dynamicInvoker
public final MethodHandle 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:
dynamicInvoker
in classCallSite
- Returns:
- a method handle which always invokes this call site's current target
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
18/11/2024 09:55:46 Cette version de la page est en cache (à la date du 18/11/2024 09:55:46) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/lang/invoke/volatilecallsite.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.