volatile int fields of designated
classes, providing a subset of the functionality of class VarHandle that should be used instead. This class is designed for
use in atomic data structures in which several fields of the same
node are independently subject to atomic updates.
Note that the guarantees of the compareAndSet
method in this class are weaker than in other atomic classes.
Because this class cannot ensure that all uses of the field
are appropriate for purposes of atomic access, it can
guarantee atomicity only with respect to other invocations of
compareAndSet and set on the same updater.
Object arguments for parameters of type T that are not
instances of the class passed to newUpdater will result in
a ClassCastException being thrown.
| Modifier and Type | Class and Description |
|---|---|
| private static class | AtomicIntegerFieldUpdater.
Standard hotspot implementation using intrinsics. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public final int | Returns: the updated valueAn object whose field to get and set obj, int the update value x, IntBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public int | Returns: the updated valueAn object whose field to get and set obj, int the value to add delta)Atomically adds the given value to the current value of the field of the given object managed by this updater. |
| public abstract boolean | Returns: true if successfulAn object whose field to conditionally set obj, int the expected value expect, int the new value update)Atomically sets the field of the given object managed by this updater
to the given updated value if the current value |
| public int | Returns: the updated valueAn object whose field to get and set obj)Atomically decrements by one the current value of the field of the given object managed by this updater. |
| public abstract int | Returns: the current valueAn object whose field to get obj)Returns the current value held in the field of the given object managed by this updater. |
| public final int | Returns: the previous valueAn object whose field to get and set obj, int the update value x, IntBinaryOperator a side-effect-free function of two arguments accumulatorFunction)Atomically updates (with memory effects as specified by |
| public int | Returns: the previous valueAn object whose field to get and set obj, int the value to add delta)Atomically adds the given value to the current value of the field of the given object managed by this updater. |
| public int | Returns: the previous valueAn object whose field to get and set obj)Atomically decrements by one the current value of the field of the given object managed by this updater. |
| public int | Returns: the previous valueAn object whose field to get and set obj)Atomically increments by one the current value of the field of the given object managed by this updater. |
| public int | Returns: the previous valueAn object whose field to get and set obj, int the new value newValue)Atomically sets the field of the given object managed by this updater to the given value and returns the old value. |
| public final int | Returns: the previous valueAn object whose field to get and set obj, IntUnaryOperator a side-effect-free function updateFunction)Atomically updates (with memory effects as specified by |
| public int | Returns: the updated valueAn object whose field to get and set obj)Atomically increments by one the current value of the field of the given object managed by this updater. |
| public abstract void | lazySet(T
An object whose field to set obj, int the new value newValue)Eventually sets the field of the given object managed by this updater to the given updated value. |
| public static < the type of instances of tclass U> AtomicIntegerFieldUpdater | Returns: the updaterthe class of the objects holding the field tclass, String the name of the field to be updated fieldName)Creates and returns an updater for objects with the given field. |
| public abstract void | set(T
An object whose field to set obj, int the new value newValue)Sets the field of the given object managed by this updater to the given updated value. |
| public final int | Returns: the updated valueAn object whose field to get and set obj, IntUnaryOperator a side-effect-free function updateFunction)Atomically updates (with memory effects as specified by |
| public abstract boolean | Returns: true if successfulAn object whose field to conditionally set obj, int the expected value expect, int the new value update)Atomically sets the field of the given object managed by this updater
to the given updated value if the current value |
| AtomicIntegerFieldUpdater | back to summary |
|---|---|
| protected AtomicIntegerFieldUpdater() Protected do-nothing constructor for use by subclasses. | |
| accumulateAndGet | back to summary |
|---|---|
| public final int accumulateAndGet(T obj, int x, IntBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| addAndGet | back to summary |
|---|---|
| public int addAndGet(T obj, int delta) Atomically adds the given value to the current value of the field of the given object managed by this updater.
| |
| compareAndSet | back to summary |
|---|---|
| public abstract boolean compareAndSet(T obj, int expect, int update) Atomically sets the field of the given object managed by this updater
to the given updated value if the current value
| |
| decrementAndGet | back to summary |
|---|---|
| public int decrementAndGet(T obj) Atomically decrements by one the current value of the field of the given object managed by this updater.
| |
| get | back to summary |
|---|---|
| public abstract int get(T obj) Returns the current value held in the field of the given object managed by this updater.
| |
| getAndAccumulate | back to summary |
|---|---|
| public final int getAndAccumulate(T obj, int x, IntBinaryOperator accumulatorFunction) Atomically updates (with memory effects as specified by
| |
| getAndAdd | back to summary |
|---|---|
| public int getAndAdd(T obj, int delta) Atomically adds the given value to the current value of the field of the given object managed by this updater.
| |
| getAndDecrement | back to summary |
|---|---|
| public int getAndDecrement(T obj) Atomically decrements by one the current value of the field of the given object managed by this updater.
| |
| getAndIncrement | back to summary |
|---|---|
| public int getAndIncrement(T obj) Atomically increments by one the current value of the field of the given object managed by this updater.
| |
| getAndSet | back to summary |
|---|---|
| public int getAndSet(T obj, int newValue) Atomically sets the field of the given object managed by this updater to the given value and returns the old value.
| |
| getAndUpdate | back to summary |
|---|---|
| public final int getAndUpdate(T obj, IntUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| incrementAndGet | back to summary |
|---|---|
| public int incrementAndGet(T obj) Atomically increments by one the current value of the field of the given object managed by this updater.
| |
| lazySet | back to summary |
|---|---|
| public abstract void lazySet(T obj, int newValue) Eventually sets the field of the given object managed by this updater to the given updated value.
| |
| newUpdater | back to summary |
|---|---|
| public static <U> AtomicIntegerFieldUpdater Creates and returns an updater for objects with the given field. The Class argument is needed to check that reflective types and generic types match.
| |
| set | back to summary |
|---|---|
| public abstract void set(T obj, int newValue) Sets the field of the given object managed by this updater to the
given updated value. This operation is guaranteed to act as a volatile
store with respect to subsequent invocations of
| |
| updateAndGet | back to summary |
|---|---|
| public final int updateAndGet(T obj, IntUnaryOperator updateFunction) Atomically updates (with memory effects as specified by
| |
| weakCompareAndSet | back to summary |
|---|---|
| public abstract boolean weakCompareAndSet(T obj, int expect, int update) Atomically sets the field of the given object managed by this updater
to the given updated value if the current value This operation may fail spuriously and does not provide
ordering guarantees, so is only rarely an appropriate
alternative to
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Class | cclass
if field is protected, the subclass constructing updater, else the same as tclass |
| private final long | |
| private final Class | tclass
class holding the field |
| private static final Unsafe |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private final void | |
| public final int | addAndGet(T obj, int delta)
Overrides java. Atomically adds the given value to the current value of the field of the given object managed by this updater. |
| public final boolean | compareAndSet(T obj, int expect, int update)
Implements abstract java. Atomically sets the field of the given object managed by this updater
to the given updated value if the current value |
| public final int | decrementAndGet(T obj)
Overrides java. Atomically decrements by one the current value of the field of the given object managed by this updater. |
| public final int | get(T obj)
Implements abstract java. Returns the current value held in the field of the given object managed by this updater. |
| public final int | getAndAdd(T obj, int delta)
Overrides java. Atomically adds the given value to the current value of the field of the given object managed by this updater. |
| public final int | getAndDecrement(T obj)
Overrides java. Atomically decrements by one the current value of the field of the given object managed by this updater. |
| public final int | getAndIncrement(T obj)
Overrides java. Atomically increments by one the current value of the field of the given object managed by this updater. |
| public final int | getAndSet(T obj, int newValue)
Overrides java. Atomically sets the field of the given object managed by this updater to the given value and returns the old value. |
| public final int | incrementAndGet(T obj)
Overrides java. Atomically increments by one the current value of the field of the given object managed by this updater. |
| private static boolean | isAncestor(ClassLoader first, ClassLoader second)
Returns true if the second classloader can be found in the first classloader's delegation chain. |
| private static boolean | isSamePackage(Class<?> class1, Class<?> class2)
Returns true if the two classes have the same class loader and package qualifier |
| public final void | lazySet(T obj, int newValue)
Implements abstract java. Eventually sets the field of the given object managed by this updater to the given updated value. |
| public final void | set(T obj, int newValue)
Implements abstract java. Sets the field of the given object managed by this updater to the given updated value. |
| private final void | throwAccessCheckException(T obj)
Throws access exception if accessCheck failed due to protected access, else ClassCastException. |
| public final boolean | weakCompareAndSet(T obj, int expect, int update)
Implements abstract java. Atomically sets the field of the given object managed by this updater
to the given updated value if the current value |
| cclass | back to summary |
|---|---|
| private final Class<?> cclass if field is protected, the subclass constructing updater, else the same as tclass | |
| offset | back to summary |
|---|---|
| private final long offset | |
| tclass | back to summary |
|---|---|
| private final Class<T> tclass class holding the field | |
| U | back to summary |
|---|---|
| private static final Unsafe U | |
| AtomicIntegerFieldUpdaterImpl | back to summary |
|---|---|
| pack-priv AtomicIntegerFieldUpdaterImpl(final Class<T> tclass, final String fieldName, final Class<?> caller) | |
| accessCheck | back to summary |
|---|---|
| private final void accessCheck(T obj) Checks that target argument is instance of cclass. On failure, throws cause. | |
| addAndGet | back to summary |
|---|---|
| public final int addAndGet(T obj, int delta) Overrides java. Doc from java. Atomically adds the given value to the current value of the field of the given object managed by this updater. | |
| compareAndSet | back to summary |
|---|---|
| public final boolean compareAndSet(T obj, int expect, int update) Implements abstract java. Doc from java. Atomically sets the field of the given object managed by this updater
to the given updated value if the current value | |
| decrementAndGet | back to summary |
|---|---|
| public final int decrementAndGet(T obj) Overrides java. Doc from java. Atomically decrements by one the current value of the field of the given object managed by this updater. | |
| get | back to summary |
|---|---|
| public final int get(T obj) Implements abstract java. Doc from java. Returns the current value held in the field of the given object managed by this updater. | |
| getAndAdd | back to summary |
|---|---|
| public final int getAndAdd(T obj, int delta) Overrides java. Doc from java. Atomically adds the given value to the current value of the field of the given object managed by this updater. | |
| getAndDecrement | back to summary |
|---|---|
| public final int getAndDecrement(T obj) Overrides java. Doc from java. Atomically decrements by one the current value of the field of the given object managed by this updater. | |
| getAndIncrement | back to summary |
|---|---|
| public final int getAndIncrement(T obj) Overrides java. Doc from java. Atomically increments by one the current value of the field of the given object managed by this updater. | |
| getAndSet | back to summary |
|---|---|
| public final int getAndSet(T obj, int newValue) Overrides java. Doc from java. Atomically sets the field of the given object managed by this updater to the given value and returns the old value. | |
| incrementAndGet | back to summary |
|---|---|
| public final int incrementAndGet(T obj) Overrides java. Doc from java. Atomically increments by one the current value of the field of the given object managed by this updater. | |
| isAncestor | back to summary |
|---|---|
| private static boolean isAncestor(ClassLoader first, ClassLoader second) Returns true if the second classloader can be found in the first classloader's delegation chain. Equivalent to the inaccessible: first.isAncestor(second). | |
| isSamePackage | back to summary |
|---|---|
| private static boolean isSamePackage(Class<?> class1, Class<?> class2) Returns true if the two classes have the same class loader and package qualifier | |
| lazySet | back to summary |
|---|---|
| public final void lazySet(T obj, int newValue) Implements abstract java. Doc from java. Eventually sets the field of the given object managed by this updater to the given updated value. | |
| set | back to summary |
|---|---|
| public final void set(T obj, int newValue) Implements abstract java. Doc from java. Sets the field of the given object managed by this updater to the
given updated value. This operation is guaranteed to act as a volatile
store with respect to subsequent invocations of | |
| throwAccessCheckException | back to summary |
|---|---|
| private final void throwAccessCheckException(T obj) Throws access exception if accessCheck failed due to protected access, else ClassCastException. | |
| weakCompareAndSet | back to summary |
|---|---|
| public final boolean weakCompareAndSet(T obj, int expect, int update) Implements abstract java. Doc from java. Atomically sets the field of the given object managed by this updater
to the given updated value if the current value This operation may fail spuriously and does not provide
ordering guarantees, so is only rarely an appropriate
alternative to | |