- java.lang.Object
- 
- java.lang.invoke.VarHandle
 
- 
 public abstract class VarHandle extends Object A VarHandle is a dynamically strongly typed reference to a variable, or to a parametrically-defined family of variables, including static fields, non-static fields, array elements, or components of an off-heap data structure. Access to such variables is supported under various access modes, including plain read/write access, volatile read/write access, and compare-and-set.VarHandles are immutable and have no visible state. VarHandles cannot be subclassed by the user. A VarHandle has: - a variable typeT, the type of every variable referenced by this VarHandle; and
- a list of coordinate typesCT1, CT2, ..., CTn, the types of coordinate expressions that jointly locate a variable referenced by this VarHandle.
 Classobjects. The list of coordinate types may be empty.Factory methods that produce or lookupVarHandle instances document the supported variable type and the list of coordinate types.Each access mode is associated with one access mode method, a signature polymorphic method named for the access mode. When an access mode method is invoked on a VarHandle instance, the initial arguments to the invocation are coordinate expressions that indicate in precisely which object the variable is to be accessed. Trailing arguments to the invocation represent values of importance to the access mode. For example, the various compare-and-set or compare-and-exchange access modes require two trailing arguments for the variable's expected value and new value. The arity and types of arguments to the invocation of an access mode method are not checked statically. Instead, each access mode method specifies an access mode type, represented as an instance ofMethodType, that serves as a kind of method signature against which the arguments are checked dynamically. An access mode type gives formal parameter types in terms of the coordinate types of a VarHandle instance and the types for values of importance to the access mode. An access mode type also gives a return type, often in terms of the variable type of a VarHandle instance. When an access mode method is invoked on a VarHandle instance, the symbolic type descriptor at the call site, the run time types of arguments to the invocation, and the run time type of the return value, must match the types given in the access mode type. A runtime exception will be thrown if the match fails. For example, the access mode methodcompareAndSet(java.lang.Object...)specifies that if its receiver is a VarHandle instance with coordinate typesCT1, ..., CTnand variable typeT, then its access mode type is(CT1 c1, ..., CTn cn, T expectedValue, T newValue)boolean. Suppose that a VarHandle instance can access array elements, and that its coordinate types areString[]andintwhile its variable type isString. The access mode type forcompareAndSeton this VarHandle instance would be(String[] c1, int c2, String expectedValue, String newValue)boolean. Such a VarHandle instance may be produced by thearray factory methodand access array elements as follows:String[] sa = ... VarHandle avh = MethodHandles.arrayElementVarHandle(String[].class); boolean r = avh.compareAndSet(sa, 10, "expected", "new");Access modes control atomicity and consistency properties. Plain read ( get) and write (set) accesses are guaranteed to be bitwise atomic only for references and for primitive values of at most 32 bits, and impose no observable ordering constraints with respect to threads other than the executing thread. Opaque operations are bitwise atomic and coherently ordered with respect to accesses to the same variable. In addition to obeying Opaque properties, Acquire mode reads and their subsequent accesses are ordered after matching Release mode writes and their previous accesses. In addition to obeying Acquire and Release properties, all Volatile operations are totally ordered with respect to each other.Access modes are grouped into the following categories: - read access modes that get the value of a variable under specified
 memory ordering effects.
 The set of corresponding access mode methods belonging to this group
 consists of the methods
 get,getVolatile,getAcquire,getOpaque.
- write access modes that set the value of a variable under specified
 memory ordering effects.
 The set of corresponding access mode methods belonging to this group
 consists of the methods
 set,setVolatile,setRelease,setOpaque.
- atomic update access modes that, for example, atomically compare and set
 the value of a variable under specified memory ordering effects.
 The set of corresponding access mode methods belonging to this group
 consists of the methods
 compareAndSet,weakCompareAndSetPlain,weakCompareAndSet,weakCompareAndSetAcquire,weakCompareAndSetRelease,compareAndExchangeAcquire,compareAndExchange,compareAndExchangeRelease,getAndSet,getAndSetAcquire,getAndSetRelease.
- numeric atomic update access modes that, for example, atomically get and
 set with addition the value of a variable under specified memory ordering
 effects.
 The set of corresponding access mode methods belonging to this group
 consists of the methods
 getAndAdd,getAndAddAcquire,getAndAddRelease,
- bitwise atomic update access modes that, for example, atomically get and
 bitwise OR the value of a variable under specified memory ordering
 effects.
 The set of corresponding access mode methods belonging to this group
 consists of the methods
 getAndBitwiseOr,getAndBitwiseOrAcquire,getAndBitwiseOrRelease,getAndBitwiseAnd,getAndBitwiseAndAcquire,getAndBitwiseAndRelease,getAndBitwiseXor,getAndBitwiseXorAcquire,getAndBitwiseXorRelease.
 Factory methods that produce or lookupVarHandle instances document the set of access modes that are supported, which may also include documenting restrictions based on the variable type and whether a variable is read-only. If an access mode is not supported then the corresponding access mode method will on invocation throw anUnsupportedOperationException. Factory methods should document any additional undeclared exceptions that may be thrown by access mode methods. Thegetaccess mode is supported for all VarHandle instances and the corresponding method never throwsUnsupportedOperationException. If a VarHandle references a read-only variable (for example afinalfield) then write, atomic update, numeric atomic update, and bitwise atomic update access modes are not supported and corresponding methods throwUnsupportedOperationException. Read/write access modes (if supported), with the exception ofgetandset, provide atomic access for reference types and all primitive types. Unless stated otherwise in the documentation of a factory method, the access modesgetandset(if supported) provide atomic access for reference types and all primitives types, with the exception oflonganddoubleon 32-bit platforms.Access modes will override any memory ordering effects specified at the declaration site of a variable. For example, a VarHandle accessing a field using the getaccess mode will access the field as specified by its access mode even if that field is declaredvolatile. When mixed access is performed extreme care should be taken since the Java Memory Model may permit surprising results.In addition to supporting access to variables under various access modes, a set of static methods, referred to as memory fence methods, is also provided for fine-grained control of memory ordering. The Java Language Specification permits other threads to observe operations as if they were executed in orders different than are apparent in program source code, subject to constraints arising, for example, from the use of locks, volatilefields or VarHandles. The static methods,fullFence,acquireFence,releaseFence,loadLoadFenceandstoreStoreFence, can also be used to impose constraints. Their specifications, as is the case for certain access modes, are phrased in terms of the lack of "reorderings" -- observable ordering effects that might otherwise occur if the fence was not present. More precise phrasing of the specification of access mode methods and memory fence methods may accompany future updates of the Java Language Specification.Compiling invocation of access mode methodsA Java method call expression naming an access mode method can invoke a VarHandle from Java source code. From the viewpoint of source code, these methods can take any arguments and their polymorphic result (if expressed) can be cast to any return type. Formally this is accomplished by giving the access mode methods variable arityObjectarguments andObjectreturn types (if the return type is polymorphic), but they have an additional quality called signature polymorphism which connects this freedom of invocation directly to the JVM execution stack.As is usual with virtual methods, source-level calls to access mode methods compile to an invokevirtualinstruction. More unusually, the compiler must record the actual argument types, and may not perform method invocation conversions on the arguments. Instead, it must generate instructions to push them on the stack according to their own unconverted types. The VarHandle object itself will be pushed on the stack before the arguments. The compiler then generates aninvokevirtualinstruction that invokes the access mode method with a symbolic type descriptor which describes the argument and return types.To issue a complete symbolic type descriptor, the compiler must also determine the return type (if polymorphic). This is based on a cast on the method invocation expression, if there is one, or else Objectif the invocation is an expression, or elsevoidif the invocation is a statement. The cast may be to a primitive type (but notvoid).As a corner case, an uncasted nullargument is given a symbolic type descriptor ofjava.lang.Void. The ambiguity with the typeVoidis harmless, since there are no references of typeVoidexcept the null reference.Performing invocation of access mode methodsThe first time aninvokevirtualinstruction is executed it is linked by symbolically resolving the names in the instruction and verifying that the method call is statically legal. This also holds for calls to access mode methods. In this case, the symbolic type descriptor emitted by the compiler is checked for correct syntax, and names it contains are resolved. Thus, aninvokevirtualinstruction which invokes an access mode method will always link, as long as the symbolic type descriptor is syntactically well-formed and the types exist.When the invokevirtualis executed after linking, the receiving VarHandle's access mode type is first checked by the JVM to ensure that it matches the symbolic type descriptor. If the type match fails, it means that the access mode method which the caller is invoking is not present on the individual VarHandle being invoked.Invocation of an access mode method behaves as if an invocation of MethodHandle.invoke(java.lang.Object...), where the receiving method handle accepts the VarHandle instance as the leading argument. More specifically, the following, where{access-mode}corresponds to the access mode method name:
 behaves as if:VarHandle vh = .. R r = (R) vh.{access-mode}(p1, p2, ..., pN);
 (modulo access mode methods do not declare throwing ofVarHandle vh = .. VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}"); MethodHandle mh = MethodHandles.varHandleExactInvoker( am, vh.accessModeType(am)); R r = (R) mh.invoke(vh, p1, p2, ..., pN)Throwable). This is equivalent to:
 where the desired method type is the symbolic type descriptor and aMethodHandle mh = MethodHandles.lookup().findVirtual( VarHandle.class, "{access-mode}", MethodType.methodType(R, p1, p2, ..., pN)); R r = (R) mh.invokeExact(vh, p1, p2, ..., pN)MethodHandle.invokeExact(java.lang.Object...)is performed, since before invocation of the target, the handle will apply reference casts as necessary and box, unbox, or widen primitive values, as if byasType(see alsoMethodHandles.varHandleInvoker(java.lang.invoke.VarHandle.AccessMode, java.lang.invoke.MethodType)). More concisely, such behaviour is equivalent to:
 Where, in this case, the method handle is bound to the VarHandle instance.VarHandle vh = .. VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}"); MethodHandle mh = vh.toMethodHandle(am); R r = (R) mh.invoke(p1, p2, ..., pN)Invocation checkingIn typical programs, VarHandle access mode type matching will usually succeed. But if a match fails, the JVM will throw aWrongMethodTypeException.Thus, an access mode type mismatch which might show up as a linkage error in a statically typed program can show up as a dynamic WrongMethodTypeExceptionin a program which uses VarHandles.Because access mode types contain "live" Classobjects, method type matching takes into account both type names and class loaders. Thus, even if a VarHandleVHis created in one class loaderL1and used in anotherL2, VarHandle access mode method calls are type-safe, because the caller's symbolic type descriptor, as resolved inL2, is matched against the original callee method's symbolic type descriptor, as resolved inL1. The resolution inL1happens whenVHis created and its access mode types are assigned, while the resolution inL2happens when theinvokevirtualinstruction is linked.Apart from type descriptor checks, a VarHandles's capability to access it's variables is unrestricted. If a VarHandle is formed on a non-public variable by a class that has access to that variable, the resulting VarHandle can be used in any place by any caller who receives a reference to it. Unlike with the Core Reflection API, where access is checked every time a reflective method is invoked, VarHandle access checking is performed when the VarHandle is created. Thus, VarHandles to non-public variables, or to variables in non-public classes, should generally be kept secret. They should not be passed to untrusted code unless their use from the untrusted code would be harmless. VarHandle creationJava code can create a VarHandle that directly accesses any field that is accessible to that code. This is done via a reflective, capability-based API calledMethodHandles.Lookup. For example, a VarHandle for a non-static field can be obtained fromLookup.findVarHandle. There is also a conversion method from Core Reflection API objects,Lookup.unreflectVarHandle.Access to protected field members is restricted to receivers only of the accessing class, or one of its subclasses, and the accessing class must in turn be a subclass (or package sibling) of the protected member's defining class. If a VarHandle refers to a protected non-static field of a declaring class outside the current package, the receiver argument will be narrowed to the type of the accessing class. Interoperation between VarHandles and the Core Reflection APIUsing factory methods in theLookupAPI, any field represented by a Core Reflection API object can be converted to a behaviorally equivalent VarHandle. For example, a reflectiveFieldcan be converted to a VarHandle usingLookup.unreflectVarHandle. The resulting VarHandles generally provide more direct and efficient access to the underlying fields.As a special case, when the Core Reflection API is used to view the signature polymorphic access mode methods in this class, they appear as ordinary non-polymorphic methods. Their reflective appearance, as viewed by Class.getDeclaredMethod, is unaffected by their special status in this API. For example,Method.getModifierswill report exactly those modifier bits required for any similarly declared method, including in this casenativeandvarargsbits.As with any reflected method, these methods (when reflected) may be invoked directly via java.lang.reflect.Method.invoke, via JNI, or indirectly viaLookup.unreflect. However, such reflective calls do not result in access mode method invocations. Such a call, if passed the required argument (a single one, of typeObject[]), will ignore the argument and will throw anUnsupportedOperationException.Since invokevirtualinstructions can natively invoke VarHandle access mode methods under any symbolic type descriptor, this reflective view conflicts with the normal presentation of these methods via bytecodes. Thus, these native methods, when reflectively viewed byClass.getDeclaredMethod, may be regarded as placeholders only.In order to obtain an invoker method for a particular access mode type, use MethodHandles.varHandleExactInvoker(java.lang.invoke.VarHandle.AccessMode, java.lang.invoke.MethodType)orMethodHandles.varHandleInvoker(java.lang.invoke.VarHandle.AccessMode, java.lang.invoke.MethodType). TheLookup.findVirtualAPI is also able to return a method handle to call an access mode method for any specified access mode type and is equivalent in behaviour toMethodHandles.varHandleInvoker(java.lang.invoke.VarHandle.AccessMode, java.lang.invoke.MethodType).Interoperation between VarHandles and Java genericsA VarHandle can be obtained for a variable, such as a field, which is declared with Java generic types. As with the Core Reflection API, the VarHandle's variable type will be constructed from the erasure of the source-level type. When a VarHandle access mode method is invoked, the types of its arguments or the return value cast type may be generic types or type instances. If this occurs, the compiler will replace those types by their erasures when it constructs the symbolic type descriptor for theinvokevirtualinstruction.- Since:
- 9
- See Also:
- MethodHandle,- MethodHandles,- MethodType
 
- a 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classVarHandle.AccessModeThe set of access modes that specify how a variable, referenced by a VarHandle, is accessed.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodTypeaccessModeType(VarHandle.AccessMode accessMode)Obtains the access mode type for this VarHandle and a given access mode.static voidacquireFence()Ensures that loads before the fence will not be reordered with loads and stores after the fence.ObjectcompareAndExchange(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectcompareAndExchangeAcquire(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectcompareAndExchangeRelease(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetRelease(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).booleancompareAndSet(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).List<Class<?>>coordinateTypes()Returns the coordinate types for this VarHandle.static voidfullFence()Ensures that loads and stores before the fence will not be reordered with loads and stores after the fence.Objectget(Object... args)Returns the value of a variable, with memory semantics of reading as if the variable was declared non-volatile.ObjectgetAcquire(Object... args)Returns the value of a variable, and ensures that subsequent loads and stores are not reordered before this access.ObjectgetAndAdd(Object... args)Atomically adds thevalueto the current value of a variable with the memory semantics ofsetVolatile(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectgetAndAddAcquire(Object... args)Atomically adds thevalueto the current value of a variable with the memory semantics ofset(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectgetAndAddRelease(Object... args)Atomically adds thevalueto the current value of a variable with the memory semantics ofsetRelease(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).ObjectgetAndBitwiseAnd(Object... args)Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectgetAndBitwiseAndAcquire(Object... args)Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectgetAndBitwiseAndRelease(Object... args)Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).ObjectgetAndBitwiseOr(Object... args)Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectgetAndBitwiseOrAcquire(Object... args)Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectgetAndBitwiseOrRelease(Object... args)Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).ObjectgetAndBitwiseXor(Object... args)Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectgetAndBitwiseXorAcquire(Object... args)Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectgetAndBitwiseXorRelease(Object... args)Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).ObjectgetAndSet(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).ObjectgetAndSetAcquire(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).ObjectgetAndSetRelease(Object... args)Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).ObjectgetOpaque(Object... args)Returns the value of a variable, accessed in program order, but with no assurance of memory ordering effects with respect to other threads.ObjectgetVolatile(Object... args)Returns the value of a variable, with memory semantics of reading as if the variable was declaredvolatile.booleanisAccessModeSupported(VarHandle.AccessMode accessMode)Returnstrueif the given access mode is supported, otherwisefalse.static voidloadLoadFence()Ensures that loads before the fence will not be reordered with loads after the fence.static voidreleaseFence()Ensures that loads and stores before the fence will not be reordered with stores after the fence.voidset(Object... args)Sets the value of a variable to thenewValue, with memory semantics of setting as if the variable was declared non-volatileand non-final.voidsetOpaque(Object... args)Sets the value of a variable to thenewValue, in program order, but with no assurance of memory ordering effects with respect to other threads.voidsetRelease(Object... args)Sets the value of a variable to thenewValue, and ensures that prior loads and stores are not reordered after this access.voidsetVolatile(Object... args)Sets the value of a variable to thenewValue, with memory semantics of setting as if the variable was declaredvolatile.static voidstoreStoreFence()Ensures that stores before the fence will not be reordered with stores after the fence.MethodHandletoMethodHandle(VarHandle.AccessMode accessMode)Obtains a method handle bound to this VarHandle and the given access mode.Class<?>varType()Returns the variable type of variables referenced by this VarHandle.booleanweakCompareAndSet(Object... args)Possibly atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).booleanweakCompareAndSetAcquire(Object... args)Possibly atomically sets the value of a variable to thenewValuewith the semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).booleanweakCompareAndSetPlain(Object... args)Possibly atomically sets the value of a variable to thenewValuewith the semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).booleanweakCompareAndSetRelease(Object... args)Possibly atomically sets the value of a variable to thenewValuewith the semantics ofsetRelease(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).
 
- 
- 
- 
Method Detail- 
getpublic final Object get(Object... args) Returns the value of a variable, with memory semantics of reading as if the variable was declared non-volatile. Commonly referred to as plain read access.The method signature is of the form (CT1 ct1, ..., CTn ctn)T.The symbolic type descriptor at the call site of getmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET)on this VarHandle.This access mode is supported by all VarHandle instances and never throws UnsupportedOperationException.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the value of the
 variable
 , statically represented using Object.
- Throws:
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
setpublic final void set(Object... args) Sets the value of a variable to thenewValue, with memory semantics of setting as if the variable was declared non-volatileand non-final. Commonly referred to as plain write access.The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)voidThe symbolic type descriptor at the call site of setmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.SET)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
getVolatilepublic final Object getVolatile(Object... args) Returns the value of a variable, with memory semantics of reading as if the variable was declaredvolatile.The method signature is of the form (CT1 ct1, ..., CTn ctn)T.The symbolic type descriptor at the call site of getVolatilemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_VOLATILE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the value of the
 variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
setVolatilepublic final void setVolatile(Object... args) Sets the value of a variable to thenewValue, with memory semantics of setting as if the variable was declaredvolatile.The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)void.The symbolic type descriptor at the call site of setVolatilemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.SET_VOLATILE)on this VarHandle.- API Note:
- Ignoring the many semantic differences from C and C++, this method has
 memory ordering effects compatible with memory_order_seq_cst.
- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
getOpaquepublic final Object getOpaque(Object... args) Returns the value of a variable, accessed in program order, but with no assurance of memory ordering effects with respect to other threads.The method signature is of the form (CT1 ct1, ..., CTn ctn)T.The symbolic type descriptor at the call site of getOpaquemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_OPAQUE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the value of the
 variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
setOpaquepublic final void setOpaque(Object... args) Sets the value of a variable to thenewValue, in program order, but with no assurance of memory ordering effects with respect to other threads.The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)void.The symbolic type descriptor at the call site of setOpaquemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.SET_OPAQUE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
getAcquirepublic final Object getAcquire(Object... args) Returns the value of a variable, and ensures that subsequent loads and stores are not reordered before this access.The method signature is of the form (CT1 ct1, ..., CTn ctn)T.The symbolic type descriptor at the call site of getAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_ACQUIRE)on this VarHandle.- API Note:
- Ignoring the many semantic differences from C and C++, this method has
 memory ordering effects compatible with memory_order_acquireordering.
- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the value of the
 variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
setReleasepublic final void setRelease(Object... args) Sets the value of a variable to thenewValue, and ensures that prior loads and stores are not reordered after this access.The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)void.The symbolic type descriptor at the call site of setReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.SET_RELEASE)on this VarHandle.- API Note:
- Ignoring the many semantic differences from C and C++, this method has
 memory ordering effects compatible with memory_order_releaseordering.
- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
 
 - 
compareAndSetpublic final boolean compareAndSet(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean.The symbolic type descriptor at the call site of compareAndSetmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.COMPARE_AND_SET)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- trueif successful, otherwise- falseif the witness value was not the same as the- expectedValue.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
compareAndExchangepublic final Object compareAndExchange(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)T.The symbolic type descriptor at the call site of compareAndExchangemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the witness value, which
 will be the same as the expectedValueif successful , statically represented usingObject.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type is not compatible with the caller's symbolic type descriptor.
- ClassCastException- if the access mode type is compatible with the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
compareAndExchangeAcquirepublic final Object compareAndExchangeAcquire(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)T.The symbolic type descriptor at the call site of compareAndExchangeAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the witness value, which
 will be the same as the expectedValueif successful , statically represented usingObject.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- getAcquire(Object...)
 
 - 
compareAndExchangeReleasepublic final Object compareAndExchangeRelease(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetRelease(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)T.The symbolic type descriptor at the call site of compareAndExchangeReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the witness value, which
 will be the same as the expectedValueif successful , statically represented usingObject.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setRelease(Object...),- get(Object...)
 
 - 
weakCompareAndSetPlainpublic final boolean weakCompareAndSetPlain(Object... args) Possibly atomically sets the value of a variable to thenewValuewith the semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).This operation may fail spuriously (typically, due to memory contention) even if the witness value does match the expected value. The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean.The symbolic type descriptor at the call site of weakCompareAndSetPlainmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- trueif successful, otherwise- falseif the witness value was not the same as the- expectedValueor if this operation spuriously failed.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- get(Object...)
 
 - 
weakCompareAndSetpublic final boolean weakCompareAndSet(Object... args) Possibly atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).This operation may fail spuriously (typically, due to memory contention) even if the witness value does match the expected value. The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean.The symbolic type descriptor at the call site of weakCompareAndSetmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- trueif successful, otherwise- falseif the witness value was not the same as the- expectedValueor if this operation spuriously failed.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
weakCompareAndSetAcquirepublic final boolean weakCompareAndSetAcquire(Object... args) Possibly atomically sets the value of a variable to thenewValuewith the semantics ofset(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).This operation may fail spuriously (typically, due to memory contention) even if the witness value does match the expected value. The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean.The symbolic type descriptor at the call site of weakCompareAndSetAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- trueif successful, otherwise- falseif the witness value was not the same as the- expectedValueor if this operation spuriously failed.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- getAcquire(Object...)
 
 - 
weakCompareAndSetReleasepublic final boolean weakCompareAndSetRelease(Object... args) Possibly atomically sets the value of a variable to thenewValuewith the semantics ofsetRelease(java.lang.Object...)if the variable's current value, referred to as the witness value,==theexpectedValue, as accessed with the memory semantics ofget(java.lang.Object...).This operation may fail spuriously (typically, due to memory contention) even if the witness value does match the expected value. The method signature is of the form (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean.The symbolic type descriptor at the call site of weakCompareAndSetReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.
- Returns:
- trueif successful, otherwise- falseif the witness value was not the same as the- expectedValueor if this operation spuriously failed.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setRelease(Object...),- get(Object...)
 
 - 
getAndSetpublic final Object getAndSet(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)T.The symbolic type descriptor at the call site of getAndSetmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_SET)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndSetAcquirepublic final Object getAndSetAcquire(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)T.The symbolic type descriptor at the call site of getAndSetAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_SET_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndSetReleasepublic final Object getAndSetRelease(Object... args) Atomically sets the value of a variable to thenewValuewith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T newValue)T.The symbolic type descriptor at the call site of getAndSetReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_SET_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T newValue), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndAddpublic final Object getAndAdd(Object... args) Atomically adds thevalueto the current value of a variable with the memory semantics ofsetVolatile(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T value)T.The symbolic type descriptor at the call site of getAndAddmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_ADD)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T value), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndAddAcquirepublic final Object getAndAddAcquire(Object... args) Atomically adds thevalueto the current value of a variable with the memory semantics ofset(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T value)T.The symbolic type descriptor at the call site of getAndAddAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T value), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndAddReleasepublic final Object getAndAddRelease(Object... args) Atomically adds thevalueto the current value of a variable with the memory semantics ofsetRelease(java.lang.Object...), and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).The method signature is of the form (CT1 ct1, ..., CTn ctn, T value)T.The symbolic type descriptor at the call site of getAndAddReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_ADD_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T value), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndBitwiseOrpublic final Object getAndBitwiseOr(Object... args) Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).If the variable type is the non-integral booleantype then a logical OR is performed instead of a bitwise OR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseOrmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndBitwiseOrAcquirepublic final Object getAndBitwiseOrAcquire(Object... args) Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).If the variable type is the non-integral booleantype then a logical OR is performed instead of a bitwise OR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseOrAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- getAcquire(Object...)
 
 - 
getAndBitwiseOrReleasepublic final Object getAndBitwiseOrRelease(Object... args) Atomically sets the value of a variable to the result of bitwise OR between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).If the variable type is the non-integral booleantype then a logical OR is performed instead of a bitwise OR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseOrReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setRelease(Object...),- get(Object...)
 
 - 
getAndBitwiseAndpublic final Object getAndBitwiseAnd(Object... args) Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).If the variable type is the non-integral booleantype then a logical AND is performed instead of a bitwise AND.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseAndmust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndBitwiseAndAcquirepublic final Object getAndBitwiseAndAcquire(Object... args) Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).If the variable type is the non-integral booleantype then a logical AND is performed instead of a bitwise AND.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseAndAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- getAcquire(Object...)
 
 - 
getAndBitwiseAndReleasepublic final Object getAndBitwiseAndRelease(Object... args) Atomically sets the value of a variable to the result of bitwise AND between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).If the variable type is the non-integral booleantype then a logical AND is performed instead of a bitwise AND.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseAndReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setRelease(Object...),- get(Object...)
 
 - 
getAndBitwiseXorpublic final Object getAndBitwiseXor(Object... args) Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofsetVolatile(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetVolatile(java.lang.Object...).If the variable type is the non-integral booleantype then a logical XOR is performed instead of a bitwise XOR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseXormust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setVolatile(Object...),- getVolatile(Object...)
 
 - 
getAndBitwiseXorAcquirepublic final Object getAndBitwiseXorAcquire(Object... args) Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofset(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofgetAcquire(java.lang.Object...).If the variable type is the non-integral booleantype then a logical XOR is performed instead of a bitwise XOR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseXorAcquiremust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- set(Object...),- getAcquire(Object...)
 
 - 
getAndBitwiseXorReleasepublic final Object getAndBitwiseXorRelease(Object... args) Atomically sets the value of a variable to the result of bitwise XOR between the variable's current value and themaskwith the memory semantics ofsetRelease(java.lang.Object...)and returns the variable's previous value, as accessed with the memory semantics ofget(java.lang.Object...).If the variable type is the non-integral booleantype then a logical XOR is performed instead of a bitwise XOR.The method signature is of the form (CT1 ct1, ..., CTn ctn, T mask)T.The symbolic type descriptor at the call site of getAndBitwiseXorReleasemust match the access mode type that is the result of callingaccessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)on this VarHandle.- Parameters:
- args- the signature-polymorphic parameter list of the form- (CT1 ct1, ..., CTn ctn, T mask), statically represented using varargs.
- Returns:
- the signature-polymorphic result that is the previous value of
 the variable
 , statically represented using Object.
- Throws:
- UnsupportedOperationException- if the access mode is unsupported for this VarHandle.
- WrongMethodTypeException- if the access mode type does not match the caller's symbolic type descriptor.
- ClassCastException- if the access mode type matches the caller's symbolic type descriptor, but a reference cast fails.
- See Also:
- setRelease(Object...),- get(Object...)
 
 - 
varTypepublic final Class<?> varType() Returns the variable type of variables referenced by this VarHandle.- Returns:
- the variable type of variables referenced by this VarHandle
 
 - 
coordinateTypespublic final List<Class<?>> coordinateTypes() Returns the coordinate types for this VarHandle.- Returns:
- the coordinate types for this VarHandle. The returned list is unmodifiable
 
 - 
accessModeTypepublic final MethodType accessModeType(VarHandle.AccessMode accessMode) Obtains the access mode type for this VarHandle and a given access mode.The access mode type's parameter types will consist of a prefix that is the coordinate types of this VarHandle followed by further types as defined by the access mode method. The access mode type's return type is defined by the return type of the access mode method. - Parameters:
- accessMode- the access mode, corresponding to the signature-polymorphic method of the same name
- Returns:
- the access mode type for the given access mode
 
 - 
isAccessModeSupportedpublic final boolean isAccessModeSupported(VarHandle.AccessMode accessMode) Returnstrueif the given access mode is supported, otherwisefalse.The return of a falsevalue for a given access mode indicates that anUnsupportedOperationExceptionis thrown on invocation of the corresponding access mode method.- Parameters:
- accessMode- the access mode, corresponding to the signature-polymorphic method of the same name
- Returns:
- trueif the given access mode is supported, otherwise- false.
 
 - 
toMethodHandlepublic final MethodHandle toMethodHandle(VarHandle.AccessMode accessMode) Obtains a method handle bound to this VarHandle and the given access mode.- API Note:
- This method, for a VarHandle vhand access mode{access-mode}, returns a method handle that is equivalent to method handlebmhin the following code (though it may be more efficient):MethodHandle mh = MethodHandles.varHandleExactInvoker( vh.accessModeType(VarHandle.AccessMode.{access-mode})); MethodHandle bmh = mh.bindTo(vh);
- Parameters:
- accessMode- the access mode, corresponding to the signature-polymorphic method of the same name
- Returns:
- a method handle bound to this VarHandle and the given access mode
 
 - 
fullFencepublic static void fullFence() Ensures that loads and stores before the fence will not be reordered with loads and stores after the fence.- API Note:
- Ignoring the many semantic differences from C and C++, this
 method has memory ordering effects compatible with
 atomic_thread_fence(memory_order_seq_cst)
 
 - 
acquireFencepublic static void acquireFence() Ensures that loads before the fence will not be reordered with loads and stores after the fence.- API Note:
- Ignoring the many semantic differences from C and C++, this
 method has memory ordering effects compatible with
 atomic_thread_fence(memory_order_acquire)
 
 - 
releaseFencepublic static void releaseFence() Ensures that loads and stores before the fence will not be reordered with stores after the fence.- API Note:
- Ignoring the many semantic differences from C and C++, this
 method has memory ordering effects compatible with
 atomic_thread_fence(memory_order_release)
 
 - 
loadLoadFencepublic static void loadLoadFence() Ensures that loads before the fence will not be reordered with loads after the fence.
 - 
storeStoreFencepublic static void storeStoreFence() Ensures that stores before the fence will not be reordered with stores after the fence.
 
- 
 
-