- java.lang.Object
-
- java.lang.invoke.CallSite
-
- Direct Known Subclasses:
- ConstantCallSite, MutableCallSite, VolatileCallSite
public abstract class CallSite extends Object
ACallSite
is a holder for a variableMethodHandle
, which is called itstarget
. Aninvokedynamic
instruction linked to aCallSite
delegates all calls to the site's current target. ACallSite
may be associated with severalinvokedynamic
instructions, or it may be "free floating", associated with none. In any case, it may be invoked through an associated method handle called its dynamic invoker.CallSite
is an abstract class which does not allow direct subclassing by users. It has three immediate, concrete subclasses that may be either instantiated or subclassed.- If a mutable target is not required, an
invokedynamic
instruction may be permanently bound by means of a constant call site. - If a mutable target is required which has volatile variable semantics, because updates to the target must be immediately and reliably witnessed by other threads, a volatile call site may be used.
- Otherwise, if a mutable target is required, a mutable call site may be used.
A non-constant call site may be relinked by changing its target. The new target must have the same type as the previous target. Thus, though a call site can be relinked to a series of successive targets, it cannot change its type.
Here is a sample use of call sites and bootstrap methods which links every dynamic call site to print its arguments:
static void test() throws Throwable { // THE FOLLOWING LINE IS PSEUDOCODE FOR A JVM INSTRUCTION InvokeDynamic[#bootstrapDynamic].baz("baz arg", 2, 3.14); } private static void printArgs(Object... args) { System.out.println(java.util.Arrays.deepToString(args)); } private static final MethodHandle printArgs; static { MethodHandles.Lookup lookup = MethodHandles.lookup(); Class thisClass = lookup.lookupClass(); // (who am I?) printArgs = lookup.findStatic(thisClass, "printArgs", MethodType.methodType(void.class, Object[].class)); } private static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String name, MethodType type) { // ignore caller and name, but match the type: return new ConstantCallSite(printArgs.asType(type)); }
-
-
Method Summary
Methods Modifier and Type Method and Description abstract MethodHandle
dynamicInvoker()
Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.abstract MethodHandle
getTarget()
Returns the target method of the call site, according to the behavior defined by this call site's specific class.abstract void
setTarget(MethodHandle newTarget)
Updates the target method of this call site, according to the behavior defined by this call site's specific class.MethodType
type()
Returns the type of this call site's target.
-
-
-
Method Detail
-
type
public MethodType type()
Returns the type of this call site's target. Although targets may change, any call site's type is permanent, and can never change to an unequal type. ThesetTarget
method enforces this invariant by refusing any new target that does not have the previous target's type.- Returns:
- the type of the current target, which is also the type of any future target
-
getTarget
public abstract MethodHandle getTarget()
Returns the target method of the call site, according to the behavior defined by this call site's specific class. The immediate subclasses ofCallSite
document the class-specific behaviors of this method.- Returns:
- the current linkage state of the call site, its target method handle
- See Also:
ConstantCallSite
,VolatileCallSite
,setTarget(java.lang.invoke.MethodHandle)
,ConstantCallSite.getTarget()
,MutableCallSite.getTarget()
,VolatileCallSite.getTarget()
-
setTarget
public abstract void setTarget(MethodHandle newTarget)
Updates the target method of this call site, according to the behavior defined by this call site's specific class. The immediate subclasses ofCallSite
document the class-specific behaviors of this method.The type of the new target must be equal to the type of the old target.
- 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()
,ConstantCallSite.setTarget(java.lang.invoke.MethodHandle)
,MutableCallSite.setTarget(java.lang.invoke.MethodHandle)
,VolatileCallSite.setTarget(java.lang.invoke.MethodHandle)
-
dynamicInvoker
public abstract 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)
- Returns:
- a method handle which always invokes this call site's current target
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/lang/invoke/CallSite.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.