类介绍
VarHandle 是一种动态强类型的对变量的引用,或者对一组参数化定义的变量的引用,包括静态字段、非静态字段、数组元素或离堆数据结构的组件。对这些变量的访问支持多种 访问模式(access modes),包括普通的读/写访问、volatile 读/写访问以及比较并设置(compare-and-set)。
VarHandle 是不可变的,没有可见的状态。用户不能对 VarHandle 进行子类化。
public abstract class VarHandle implements Constable {final VarForm vform;final boolean exact;/*** 判断 VarHandle 是否有 invoke-exact behavior*/public boolean hasInvokeExactBehavior() {return exact;}// 普通访问/*** 1. 获取一个变量的值*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject get(Object... args);/*** 1. 设置当前变量的值为一个新的值(按照代码的顺序),变量不能被final和volatile修饰,参考普通的写操作* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn, T newValue)void* 3. 调用set方法传入的参数类型必须和access mode type保持一致** @param args 参数列表 (CT1 ct1, ..., CTn ctn, T newValue),静态使用varargs* @throws UnsupportedOperationException 针对当前的VarHandle 如果 the access mode 不支持* @throws WrongMethodTypeException 如果access mode type 不匹配调用者传入参数的类型* @throws ClassCastException 如果the access mode type匹配调用者传入参数的类型,但是引用转化失败*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidatevoid set(Object... args);// Volatile 属性访问/*** 1. 返回Volatile 修饰的变量的值* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn)T* 3. 调用set方法传入的参数类型必须和access mode type( accessModeType(VarHandle.AccessMode.GET_VOLATILE))保持一致**/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getVolatile(Object... args);/*** 1. 设置Volatile 修饰的变量的值* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn, T newValue)void* 3. 调用set方法传入的参数类型必须和access mode type( accessModeType(VarHandle.AccessMode.SET_VOLATILE))保持一致*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidatevoid setVolatile(Object... args);/*** 1. 返回变量的值* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn)T* 3. 调用set方法传入的参数类型必须和access mode type( accessModeType(VarHandle.AccessMode.GET_OPAQUE))保持一致*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getOpaque(Object... args);/*** 1. 设置变量的值* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn, T newValue)void* 3. 调用set方法传入的参数类型必须和access mode type( accessModeType(VarHandle.AccessMode.SET_OPAQUE))保持一致*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidatevoid setOpaque(Object... args);// Lazy accessors 懒访问/*** 1. 返回变量的值,确保后来的loads和stores操作不会重排序到这个操作前* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn)T* 3. 调用set方法传入的参数类型必须和access mode type( accessModeType(VarHandle.AccessMode.GET_ACQUIRE))保持一致*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAcquire(Object... args);/*** 1. 设置变量的值,确保后来的loads和stores操作不会重排序到这个操作前*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidatevoid setRelease(Object... args);// CAS accessors/*** 1. 如果变量的当前值(current value)和expectedValue(内存语义操作做为 getVolatile)相等, * 原子操作来设置变量的值(内存语义操作做为 setVolatile)* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateboolean compareAndSet(Object... args);/*** 同 compareAndSet* 1. 如果变量的当前值(current value)和expectedValue(内存语义操作做为 getVolatile)相等, * 原子操作来设置变量的值(内存语义操作做为 setVolatile)* 2. 该方法的签名为:(CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean** 返回值:如果设置成功,返回witness value*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject compareAndExchange(Object... args);/*** Atomically sets the value of a variable to the {@code newValue} with the* memory semantics of {@link #set} if the variable's current value,* referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #getAcquire}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)T}.** <p>The symbolic type descriptor at the call site of {@code* compareAndExchangeAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)} on* this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return the signature-polymorphic result that is the witness value, which* will be the same as the {@code expectedValue} if successful* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #getAcquire(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject compareAndExchangeAcquire(Object... args);/*** Atomically sets the value of a variable to the {@code newValue} with the* memory semantics of {@link #setRelease} if the variable's current value,* referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #get}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)T}.** <p>The symbolic type descriptor at the call site of {@code* compareAndExchangeRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)}* on this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return the signature-polymorphic result that is the witness value, which* will be the same as the {@code expectedValue} if successful* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setRelease(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject compareAndExchangeRelease(Object... args);// Weak (spurious failures allowed)/*** Possibly atomically sets the value of a variable to the {@code newValue}* with the semantics of {@link #set} if the variable's current value,* referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #get}.** <p>This operation may fail spuriously (typically, due to memory* contention) even if the witness value does match the expected value.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean}.** <p>The symbolic type descriptor at the call site of {@code* weakCompareAndSetPlain} must match the access mode type that is the result of* calling {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN)}* on this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return {@code true} if successful, otherwise {@code false} if the* witness value was not the same as the {@code expectedValue} or if this* operation spuriously failed.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateboolean weakCompareAndSetPlain(Object... args);/*** Possibly atomically sets the value of a variable to the {@code newValue}* with the memory semantics of {@link #setVolatile} if the variable's* current value, referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #getVolatile}.** <p>This operation may fail spuriously (typically, due to memory* contention) even if the witness value does match the expected value.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean}.** <p>The symbolic type descriptor at the call site of {@code* weakCompareAndSet} must match the access mode type that is the* result of calling {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)}* on this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return {@code true} if successful, otherwise {@code false} if the* witness value was not the same as the {@code expectedValue} or if this* operation spuriously failed.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateboolean weakCompareAndSet(Object... args);/*** Possibly atomically sets the value of a variable to the {@code newValue}* with the semantics of {@link #set} if the variable's current value,* referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #getAcquire}.** <p>This operation may fail spuriously (typically, due to memory* contention) even if the witness value does match the expected value.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean}.** <p>The symbolic type descriptor at the call site of {@code* weakCompareAndSetAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)}* on this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return {@code true} if successful, otherwise {@code false} if the* witness value was not the same as the {@code expectedValue} or if this* operation spuriously failed.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #getAcquire(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateboolean weakCompareAndSetAcquire(Object... args);/*** Possibly atomically sets the value of a variable to the {@code newValue}* with the semantics of {@link #setRelease} if the variable's current* value, referred to as the <em>witness value</em>, {@code ==} the* {@code expectedValue}, as accessed with the memory semantics of* {@link #get}.** <p>This operation may fail spuriously (typically, due to memory* contention) even if the witness value does match the expected value.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)boolean}.** <p>The symbolic type descriptor at the call site of {@code* weakCompareAndSetRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)}* on this VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T expectedValue, T newValue)}* , statically represented using varargs.* @return {@code true} if successful, otherwise {@code false} if the* witness value was not the same as the {@code expectedValue} or if this* operation spuriously failed.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setRelease(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateboolean weakCompareAndSetRelease(Object... args);/*** Atomically sets the value of a variable to the {@code newValue} with the* memory semantics of {@link #setVolatile} and returns the variable's* previous value, as accessed with the memory semantics of* {@link #getVolatile}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T newValue)T}.** <p>The symbolic type descriptor at the call site of {@code getAndSet}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_SET)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T newValue)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndSet(Object... args);/*** Atomically sets the value of a variable to the {@code newValue} with the* memory semantics of {@link #set} and returns the variable's* previous value, as accessed with the memory semantics of* {@link #getAcquire}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T newValue)T}.** <p>The symbolic type descriptor at the call site of {@code getAndSetAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_SET_ACQUIRE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T newValue)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndSetAcquire(Object... args);/*** Atomically sets the value of a variable to the {@code newValue} with the* memory semantics of {@link #setRelease} and returns the variable's* previous value, as accessed with the memory semantics of* {@link #get}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T newValue)T}.** <p>The symbolic type descriptor at the call site of {@code getAndSetRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_SET_RELEASE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T newValue)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndSetRelease(Object... args);// Primitive adders// Throw UnsupportedOperationException for refs/*** Atomically adds the {@code value} to the current value of a variable with* the memory semantics of {@link #setVolatile}, and returns the variable's* previous value, as accessed with the memory semantics of* {@link #getVolatile}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T value)T}.** <p>The symbolic type descriptor at the call site of {@code getAndAdd}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_ADD)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T value)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndAdd(Object... args);/*** Atomically adds the {@code value} to the current value of a variable with* the memory semantics of {@link #set}, and returns the variable's* previous value, as accessed with the memory semantics of* {@link #getAcquire}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T value)T}.** <p>The symbolic type descriptor at the call site of {@code getAndAddAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T value)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndAddAcquire(Object... args);/*** Atomically adds the {@code value} to the current value of a variable with* the memory semantics of {@link #setRelease}, and returns the variable's* previous value, as accessed with the memory semantics of* {@link #get}.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T value)T}.** <p>The symbolic type descriptor at the call site of {@code getAndAddRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_ADD_RELEASE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T value)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndAddRelease(Object... args);// Bitwise operations// Throw UnsupportedOperationException for refs/*** Atomically sets the value of a variable to the result of* bitwise OR between the variable's current value and the {@code mask}* with the memory semantics of {@link #setVolatile} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getVolatile}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical OR is performed instead of a bitwise OR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseOr}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseOr(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise OR between the variable's current value and the {@code mask}* with the memory semantics of {@link #set} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getAcquire}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical OR is performed instead of a bitwise OR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseOrAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #getAcquire(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseOrAcquire(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise OR between the variable's current value and the {@code mask}* with the memory semantics of {@link #setRelease} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #get}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical OR is performed instead of a bitwise OR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseOrRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setRelease(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseOrRelease(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise AND between the variable's current value and the {@code mask}* with the memory semantics of {@link #setVolatile} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getVolatile}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical AND is performed instead of a bitwise AND.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseAnd}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseAnd(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise AND between the variable's current value and the {@code mask}* with the memory semantics of {@link #set} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getAcquire}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical AND is performed instead of a bitwise AND.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseAndAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #getAcquire(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseAndAcquire(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise AND between the variable's current value and the {@code mask}* with the memory semantics of {@link #setRelease} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #get}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical AND is performed instead of a bitwise AND.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseAndRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setRelease(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseAndRelease(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise XOR between the variable's current value and the {@code mask}* with the memory semantics of {@link #setVolatile} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getVolatile}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical XOR is performed instead of a bitwise XOR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseXor}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setVolatile(Object...)* @see #getVolatile(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseXor(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise XOR between the variable's current value and the {@code mask}* with the memory semantics of {@link #set} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #getAcquire}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical XOR is performed instead of a bitwise XOR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseXorAcquire}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #set(Object...)* @see #getAcquire(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseXorAcquire(Object... args);/*** Atomically sets the value of a variable to the result of* bitwise XOR between the variable's current value and the {@code mask}* with the memory semantics of {@link #setRelease} and returns the* variable's previous value, as accessed with the memory semantics of* {@link #get}.** <p>If the variable type is the non-integral {@code boolean} type then a* logical XOR is performed instead of a bitwise XOR.** <p>The method signature is of the form {@code (CT1 ct1, ..., CTn ctn, T mask)T}.** <p>The symbolic type descriptor at the call site of {@code getAndBitwiseXorRelease}* must match the access mode type that is the result of calling* {@code accessModeType(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)} on this* VarHandle.** @param args the signature-polymorphic parameter list of the form* {@code (CT1 ct1, ..., CTn ctn, T mask)}* , statically represented using varargs.* @return the signature-polymorphic result that is the previous value of* the variable* , statically represented using {@code Object}.* @throws UnsupportedOperationException if the access mode is unsupported* for this VarHandle.* @throws WrongMethodTypeException if the access mode type does not* match the caller's symbolic type descriptor.* @throws ClassCastException if the access mode type matches the caller's* symbolic type descriptor, but a reference cast fails.* @see #setRelease(Object...)* @see #get(Object...)*/public final native@MethodHandle.PolymorphicSignature@IntrinsicCandidateObject getAndBitwiseXorRelease(Object... args);/*** 返回当前VarHandle对应的coordinate types*/public List<Class<?>> coordinateTypes() {MethodType typeGet = accessModeType(AccessMode.GET);return typeGet.parameterList();}/*** 根据给定的access mode来获取当前VarHandle的MethodType*/public final MethodType accessModeType(AccessMode accessMode) {return accessModeType(accessMode.at.ordinal());}/*** 判断给定的AccessMode 是否支持*/public final boolean isAccessModeSupported(AccessMode accessMode) {return vform.getMemberNameOrNull(accessMode.ordinal()) != null;}/*** 获取和当前VarHandle 绑定的MethodHandle * 下面的代码更加高效:* MethodHandle mh = MethodHandles.varHandleExactInvoker(vh.accessModeType(VarHandle.AccessMode.{access-mode}));* MethodHandle bmh = mh.bindTo(vh);*/public MethodHandle toMethodHandle(AccessMode accessMode) {。。。}/*** 当前实例的名义操作符*/@Overridepublic Optional<VarHandleDesc> describeConstable() {return Optional.empty();}// Fence methods/*** 确保在栅栏(fence)之前的load and stores操作不会与栅栏之后的 loads andstores 操作重新排序。*/@ForceInlinepublic static void fullFence() {UNSAFE.fullFence();}/*** 确保在栅栏(fence)之前的load 操作不会与栅栏之后的 loads and stores 操作重新排序。*/@ForceInlinepublic static void acquireFence() {UNSAFE.loadFence();}/*** 确保在栅栏(fence)之前的load 和 stores 操作不会与栅栏之后的stores 操作重新排序。*/@ForceInlinepublic static void releaseFence() {UNSAFE.storeFence();}/*** 确保在栅栏(fence)之前的加载操作不会与栅栏之后的加载操作重新排序。*/@ForceInlinepublic static void loadLoadFence() {UNSAFE.loadLoadFence();}/*** 确保在栅栏(fence)之前的存储操作不会与栅栏之后的存储操作重新排序。*/@ForceInlinepublic static void storeStoreFence() {UNSAFE.storeStoreFence();}}