AtomicIntegerFieldUpdater.java revision 3203
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. Oracle designates this 286N/A * particular file as subject to the "Classpath" exception as provided 286N/A * by Oracle in the LICENSE file that accompanied this code. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A * or visit www.oracle.com if you need additional information or have any 286N/A * This file is available under and governed by the GNU General Public 286N/A * License version 2 only, as published by the Free Software Foundation. 286N/A * However, the following notice accompanied the original version of this 286N/A * Written by Doug Lea with assistance from members of JCP JSR-166 286N/A * Expert Group and released to the public domain, as explained at 286N/A * A reflection-based utility that enables atomic updates to 286N/A * designated {@code volatile int} fields of designated classes. 286N/A * This class is designed for use in atomic data structures in which 286N/A * several fields of the same node are independently subject to atomic 286N/A * <p>Note that the guarantees of the {@code compareAndSet} 286N/A * method in this class are weaker than in other atomic classes. 286N/A * Because this class cannot ensure that all uses of the field 286N/A * are appropriate for purposes of atomic access, it can 286N/A * guarantee atomicity only with respect to other invocations of 286N/A * {@code compareAndSet} and {@code set} on the same updater. 286N/A * @param <T> The type of the object holding the updatable field 286N/A * Creates and returns an updater for objects with the given field. 286N/A * The Class argument is needed to check that reflective types and 286N/A * @param tclass the class of the objects holding the field 286N/A * @param fieldName the name of the field to be updated 286N/A * @throws IllegalArgumentException if the field is not a 286N/A * volatile integer type 286N/A * @throws RuntimeException with a nested reflection-based 286N/A * exception if the class does not hold field or is the wrong type 286N/A * Protected do-nothing constructor for use by subclasses. 286N/A * Atomically sets the field of the given object managed by this updater 286N/A * to the given updated value if the current value {@code ==} the 286N/A * expected value. This method is guaranteed to be atomic with respect to 286N/A * other calls to {@code compareAndSet} and {@code set}, but not 286N/A * necessarily with respect to other changes in the field. 286N/A * @param obj An object whose field to conditionally set 286N/A * @param expect the expected value 286N/A * @param update the new value 286N/A * @return true if successful 286N/A * @throws ClassCastException if {@code obj} is not an instance 286N/A * of the class possessing the field established in the constructor 286N/A * Atomically sets the field of the given object managed by this updater 286N/A * to the given updated value if the current value {@code ==} the 286N/A * expected value. This method is guaranteed to be atomic with respect to 286N/A * other calls to {@code compareAndSet} and {@code set}, but not 286N/A * necessarily with respect to other changes in the field. 286N/A * and does not provide ordering guarantees, so is only rarely an 286N/A * appropriate alternative to {@code compareAndSet}. 286N/A * @param obj An object whose field to conditionally set 286N/A * @param expect the expected value 286N/A * @param update the new value 286N/A * @return true if successful 286N/A * @throws ClassCastException if {@code obj} is not an instance 286N/A * of the class possessing the field established in the constructor 286N/A * Sets the field of the given object managed by this updater to the 286N/A * given updated value. This operation is guaranteed to act as a volatile 286N/A * store with respect to subsequent invocations of {@code compareAndSet}. 286N/A * @param obj An object whose field to set 286N/A * @param newValue the new value 286N/A * Eventually sets the field of the given object managed by this 286N/A * updater to the given updated value. 286N/A * @param obj An object whose field to set 286N/A * @param newValue the new value 286N/A * Gets the current value held in the field of the given object managed 286N/A * @param obj An object whose field to get 286N/A * @return the current value 286N/A * Atomically sets the field of the given object managed by this updater 286N/A * to the given value and returns the old value. 286N/A * @param obj An object whose field to get and set 286N/A * @param newValue the new value 286N/A * @return the previous value 286N/A * Atomically increments by one the current value of the field of the 286N/A * given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @return the previous value 286N/A * Atomically decrements by one the current value of the field of the 286N/A * given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @return the previous value 286N/A * Atomically adds the given value to the current value of the field of 286N/A * the given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @param delta the value to add 286N/A * @return the previous value 286N/A * Atomically increments by one the current value of the field of the 286N/A * given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @return the updated value 286N/A * Atomically decrements by one the current value of the field of the 286N/A * given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @return the updated value 286N/A * Atomically adds the given value to the current value of the field of 286N/A * the given object managed by this updater. 286N/A * @param obj An object whose field to get and set 286N/A * @param delta the value to add 286N/A * @return the updated value 286N/A * Standard hotspot implementation using intrinsics 286N/A " can not access a protected member of class " +
286N/A " using an instance of " +