- java.lang.Object
-
- java.lang.invoke.CallSite
-
- java.lang.invoke.MutableCallSite
-
- Direct Known Subclasses:
AbstractRelinkableCallSite
public class MutableCallSite extends CallSite
A MutableCallSite acts as though its target MethodHandle were a normal variable.Because it is an ordinary variable, other threads may not immediately observe the value of a
CallSite.setTarget(MethodHandle)
unless external synchronization is used. If the result of aCallSite.setTarget(MethodHandle)
call must be observed by other threads, thesyncAll(MutableCallSite[])
method may be used to force it to be synchronized.The
syncAll(MutableCallSite[])
call is likely to be expensive and should be used sparingly. Calls tosyncAll(MutableCallSite[])
should be batched whenever possible.- Since:
- 1.7
-
-
Constructor Summary
Constructors Constructor Description MutableCallSite(MethodHandle mutableTarget)
Create a MutableCallSite permanently set to the same type as the mutableTarget and using the mutableTarget as the initial target value.MutableCallSite(MethodType type)
Create a MutableCallSite with the MethodType type and an initial target that throws IllegalStateException.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
syncAll(MutableCallSite[] sites)
Forces the current target MethodHandle of each of the MutableCallSites in the sites array to be seen by all threads.-
Methods declared in class java.lang.invoke.CallSite
dynamicInvoker, getTarget, setTarget, type
-
-
-
-
Constructor Detail
-
MutableCallSite
public MutableCallSite(MethodHandle mutableTarget) throws NullPointerException
Create a MutableCallSite permanently set to the same type as the mutableTarget and using the mutableTarget as the initial target value.- Parameters:
mutableTarget
- - the initial target of the CallSite- Throws:
NullPointerException
- - if the mutableTarget is null.
-
MutableCallSite
public MutableCallSite(MethodType type) throws NullPointerException
Create a MutableCallSite with the MethodType type and an initial target that throws IllegalStateException.- Parameters:
type
- - the permanent type of this CallSite.- Throws:
NullPointerException
- - if the type is null.
-
-
Method Detail
-
syncAll
public static void syncAll(MutableCallSite[] sites) throws NullPointerException
Forces the current target MethodHandle of each of the MutableCallSites in the sites array to be seen by all threads. Loads of the target from any of the CallSites that has already begun will continue to use the old value.If any of the elements in the sites array is null, a NullPointerException will be raised. It is undefined whether any of the sites may have been synchronized.
Note: it is valid for an implementation to use a volatile variable for the target value of MutableCallSite. In that case, the
syncAll(MutableCallSite[])
call becomes a no-op.- Parameters:
sites
- - the array of MutableCallSites to force to be synchronized.- Throws:
NullPointerException
- - if sites or any of its elements are null.
-
-