# VolatileCallSite

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#pubctors)\|[Methods](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#inhmethods)  

# VolatileCallSite

`
public


class
VolatileCallSite
`  
`


``

extends `[CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite)`


``


`

|---|---|-----------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.invoke.CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite) ||
|   | ↳ | java.lang.invoke.VolatileCallSite |

<br />

*** ** * ** ***

A`VolatileCallSite`is a[CallSite](https://developer.android.com/reference/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.

In other respects, a`VolatileCallSite`is interchangeable with`MutableCallSite`.  
**See also:**

- [MutableCallSite](https://developer.android.com/reference/java/lang/invoke/MutableCallSite)

## Summary

|                                                                                                                                              ### Public constructors                                                                                                                                              ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[VolatileCallSite](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#VolatileCallSite(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` target) ` Creates a call site with a volatile binding to its target. |
| ` `[VolatileCallSite](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#VolatileCallSite(java.lang.invoke.MethodType))`(`[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type) ` Creates a call site with a volatile binding to its target.         |

|                                                                                                                                                                                              ### Public methods                                                                                                                                                                                               ||
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` final `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[dynamicInvoker](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#dynamicInvoker())`() ` Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.                                                                             |
| ` final `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[getTarget](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#getTarget())`() ` Returns the target method of the call site, which behaves like a`volatile`field of the`VolatileCallSite`.                                                                                          |
| ` void`                                                                                        | ` `[setTarget](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#setTarget(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` newTarget) ` Updates the target method of this call site, as a volatile variable. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.invoke.CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite)` ` |---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[dynamicInvoker](https://developer.android.com/reference/java/lang/invoke/CallSite#dynamicInvoker())`() ` Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.                                                                                                                           | | ` abstract `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[getTarget](https://developer.android.com/reference/java/lang/invoke/CallSite#getTarget())`() ` Returns the target method of the call site, according to the behavior defined by this call site's specific class.                                                                                                                                | | ` abstract void`                                                                                  | ` `[setTarget](https://developer.android.com/reference/java/lang/invoke/CallSite#setTarget(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` newTarget) ` Updates the target method of this call site, according to the behavior defined by this call site's specific class. | | ` `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)              | ` `[type](https://developer.android.com/reference/java/lang/invoke/CallSite#type())`() ` Returns the type of this call site's target.                                                                                                                                                                                                               | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### VolatileCallSite

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VolatileCallSite (MethodHandle target)
```

Creates a call site with a volatile binding to its target. The target is set to the given value.

<br />

|                                             Parameters                                              ||
|----------|-------------------------------------------------------------------------------------------|
| `target` | `MethodHandle`: the method handle that will be the initial target of the call site <br /> |

|                                                             Throws                                                             ||
|------------------------------------------------------------------------------------------------|--------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the proposed target is null |

### VolatileCallSite

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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 an`IllegalStateException`if called.

<br />

|                                 Parameters                                 ||
|--------|--------------------------------------------------------------------|
| `type` | `MethodType`: the method type that this call site will have <br /> |

|                                                            Throws                                                            ||
|------------------------------------------------------------------------------------------------|------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the proposed type is null |

## Public methods

### dynamicInvoker

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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)
>      
<br />

<br />

|                                                                              Returns                                                                               ||
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which always invokes this call site's current target <br /> |

### getTarget

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final MethodHandle getTarget ()
```

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.

<br />

|                                                                                    Returns                                                                                    ||
|---------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the linkage state of this call site, a method handle which can change over time <br /> |

**See also:**

- [setTarget(MethodHandle)](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#setTarget(java.lang.invoke.MethodHandle))  

### setTarget

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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`.

<br />

|                     Parameters                     ||
|-------------|---------------------------------------|
| `newTarget` | `MethodHandle`: the new target <br /> |

|                                                                                              Throws                                                                                               ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)                | if the proposed new target is null                                                 |
| [WrongMethodTypeException](https://developer.android.com/reference/java/lang/invoke/WrongMethodTypeException) | if the proposed new target has a method type that differs from the previous target |

**See also:**

- [getTarget()](https://developer.android.com/reference/java/lang/invoke/VolatileCallSite#getTarget())