Stay organized with collections
Save and categorize content based on your preferences.
VolatileCallSite
open class VolatileCallSite : CallSite
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.
In other respects, a VolatileCallSite
is interchangeable with MutableCallSite
.
Summary
Public constructors |
Creates a call site with a volatile binding to its target.
|
Creates a call site with a volatile binding to its target.
|
Public methods |
MethodHandle! |
Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.
|
MethodHandle! |
Returns the target method of the call site, which behaves like a volatile field of the VolatileCallSite .
|
open Unit |
Updates the target method of this call site, as a volatile variable.
|
Inherited functions |
From class CallSite
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. The setTarget method enforces this invariant by refusing any new target that does not have the previous target's type.
|
|
Public constructors
VolatileCallSite
VolatileCallSite(target: MethodHandle!)
Creates a call site with a volatile binding to its target. The target is set to the given value.
Parameters |
target |
MethodHandle!: the method handle that will be the initial target of the call site |
Exceptions |
java.lang.NullPointerException |
if the proposed target is null |
VolatileCallSite
VolatileCallSite(type: MethodType!)
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 an IllegalStateException
if called.
Parameters |
type |
MethodType!: the method type that this call site will have |
Exceptions |
java.lang.NullPointerException |
if the proposed type is null |
Public methods
dynamicInvoker
fun dynamicInvoker(): MethodHandle!
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:
<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)
</code>
Return |
MethodHandle! |
a method handle which always invokes this call site's current target |
getTarget
fun getTarget(): MethodHandle!
Returns the target method of the call site, which behaves like a 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.
Return |
MethodHandle! |
the linkage state of this call site, a method handle which can change over time |
setTarget
open fun setTarget(newTarget: MethodHandle!): Unit
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
.
Exceptions |
java.lang.NullPointerException |
if the proposed new target is null |
java.lang.invoke.WrongMethodTypeException |
if the proposed new target has a method type that differs from the previous target |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# VolatileCallSite\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nVolatileCallSite\n================\n\n```\nopen class VolatileCallSite : CallSite\n```\n\n|---|---|----------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||\n| ↳ | [java.lang.invoke.CallSite](/reference/kotlin/java/lang/invoke/CallSite) ||\n| | ↳ | [java.lang.invoke.VolatileCallSite](#) |\n\nA `VolatileCallSite` is a [CallSite](/reference/kotlin/java/lang/invoke/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.\n\nIn other respects, a `VolatileCallSite` is interchangeable with `MutableCallSite`.\n\nSummary\n-------\n\n| Public constructors ||\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [VolatileCallSite](#VolatileCallSite(java.lang.invoke.MethodHandle))`(`target:` `[MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)!`)` Creates a call site with a volatile binding to its target. |\n| [VolatileCallSite](#VolatileCallSite(java.lang.invoke.MethodType))`(`type:` `[MethodType](/reference/kotlin/java/lang/invoke/MethodType)!`)` Creates a call site with a volatile binding to its target. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)! | [dynamicInvoker](#dynamicInvoker())`()` Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site. |\n| [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)! | [getTarget](#getTarget())`()` Returns the target method of the call site, which behaves like a `volatile` field of the `VolatileCallSite`. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setTarget](#setTarget(java.lang.invoke.MethodHandle))`(`newTarget:` `[MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)!`)` Updates the target method of this call site, as a volatile variable. |\n\n| Inherited functions ||\n|---|---|\n| From class [CallSite](/reference/kotlin/java/lang/invoke/CallSite) |--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [MethodType](/reference/kotlin/java/lang/invoke/MethodType)! | [type](/reference/kotlin/java/lang/invoke/CallSite#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. The `setTarget` method enforces this invariant by refusing any new target that does not have the previous target's type. \u003cbr /\u003e | ||\n\nPublic constructors\n-------------------\n\n### VolatileCallSite\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nVolatileCallSite(target: MethodHandle!)\n```\n\nCreates a call site with a volatile binding to its target. The target is set to the given value.\n\n| Parameters ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------|\n| `target` | [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)!: the method handle that will be the initial target of the call site |\n\n| Exceptions ||\n|----------------------------------|--------------------------------|\n| `java.lang.NullPointerException` | if the proposed target is null |\n\n### VolatileCallSite\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nVolatileCallSite(type: MethodType!)\n```\n\nCreates 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 an `IllegalStateException` if called.\n\n| Parameters ||\n|--------|-------------------------------------------------------------------------------------------------------------|\n| `type` | [MethodType](/reference/kotlin/java/lang/invoke/MethodType)!: the method type that this call site will have |\n\n| Exceptions ||\n|----------------------------------|------------------------------|\n| `java.lang.NullPointerException` | if the proposed type is null |\n\nPublic methods\n--------------\n\n### dynamicInvoker\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun dynamicInvoker(): MethodHandle!\n```\n\nProduces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.\n\nThis method is equivalent to the following code: \n\n```kotlin\n\u003ccode\u003eMethodHandle getTarget, invoker, result;\n getTarget = MethodHandles.publicLookup().bind(this, \"getTarget\", MethodType.methodType(MethodHandle.class));\n invoker = MethodHandles.exactInvoker(this.type());\n result = MethodHandles.foldArguments(invoker, getTarget)\n \u003c/code\u003e\n```\n\n| Return ||\n|------------------------------------------------------------------|----------------------------------------------------------------------|\n| [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)! | a method handle which always invokes this call site's current target |\n\n### getTarget\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nfun getTarget(): MethodHandle!\n```\n\nReturns the target method of the call site, which behaves like a `volatile` field of the `VolatileCallSite`.\n\nThe interactions of `getTarget` with memory are the same as of a read from a `volatile` field.\n\nIn 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.\n\n| Return ||\n|------------------------------------------------------------------|---------------------------------------------------------------------------------|\n| [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)! | the linkage state of this call site, a method handle which can change over time |\n\n**See Also**\n\n- [#setTarget](#setTarget(java.lang.invoke.MethodHandle)) \n\n### setTarget\n\nAdded in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setTarget(newTarget: MethodHandle!): Unit\n```\n\nUpdates 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.\n\nThe 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`.\n\n| Parameters ||\n|-------------|----------------------------------------------------------------------------------|\n| `newTarget` | [MethodHandle](/reference/kotlin/java/lang/invoke/MethodHandle)!: the new target |\n\n| Exceptions ||\n|---------------------------------------------|------------------------------------------------------------------------------------|\n| `java.lang.NullPointerException` | if the proposed new target is null |\n| `java.lang.invoke.WrongMethodTypeException` | if the proposed new target has a method type that differs from the previous target |\n\n**See Also**\n\n- [#getTarget](#getTarget())"]]