src/java.base/share/classes/java/util/concurrent/atomic/AtomicLong.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


  37 
  38 import java.util.function.LongBinaryOperator;
  39 import java.util.function.LongUnaryOperator;
  40 
  41 /**
  42  * A {@code long} value that may be updated atomically.  See the
  43  * {@link java.util.concurrent.atomic} package specification for
  44  * description of the properties of atomic variables. An
  45  * {@code AtomicLong} is used in applications such as atomically
  46  * incremented sequence numbers, and cannot be used as a replacement
  47  * for a {@link java.lang.Long}. However, this class does extend
  48  * {@code Number} to allow uniform access by tools and utilities that
  49  * deal with numerically-based classes.
  50  *
  51  * @since 1.5
  52  * @author Doug Lea
  53  */
  54 public class AtomicLong extends Number implements java.io.Serializable {
  55     private static final long serialVersionUID = 1927816293512124184L;
  56 
  57     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
  58     private static final long VALUE;
  59 
  60     /**
  61      * Records whether the underlying JVM supports lockless
  62      * compareAndSwap for longs. While the Unsafe.compareAndSwapLong
  63      * method works in either case, some constructions should be
  64      * handled at Java level to avoid locking user-visible locks.
  65      */
  66     static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
  67 
  68     /**
  69      * Returns whether underlying JVM supports lockless CompareAndSet
  70      * for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS.
  71      */
  72     private static native boolean VMSupportsCS8();
  73 
  74     static {
  75         try {
  76             VALUE = U.objectFieldOffset
  77                 (AtomicLong.class.getDeclaredField("value"));




  37 
  38 import java.util.function.LongBinaryOperator;
  39 import java.util.function.LongUnaryOperator;
  40 
  41 /**
  42  * A {@code long} value that may be updated atomically.  See the
  43  * {@link java.util.concurrent.atomic} package specification for
  44  * description of the properties of atomic variables. An
  45  * {@code AtomicLong} is used in applications such as atomically
  46  * incremented sequence numbers, and cannot be used as a replacement
  47  * for a {@link java.lang.Long}. However, this class does extend
  48  * {@code Number} to allow uniform access by tools and utilities that
  49  * deal with numerically-based classes.
  50  *
  51  * @since 1.5
  52  * @author Doug Lea
  53  */
  54 public class AtomicLong extends Number implements java.io.Serializable {
  55     private static final long serialVersionUID = 1927816293512124184L;
  56 
  57     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
  58     private static final long VALUE;
  59 
  60     /**
  61      * Records whether the underlying JVM supports lockless
  62      * compareAndSwap for longs. While the Unsafe.compareAndSwapLong
  63      * method works in either case, some constructions should be
  64      * handled at Java level to avoid locking user-visible locks.
  65      */
  66     static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
  67 
  68     /**
  69      * Returns whether underlying JVM supports lockless CompareAndSet
  70      * for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS.
  71      */
  72     private static native boolean VMSupportsCS8();
  73 
  74     static {
  75         try {
  76             VALUE = U.objectFieldOffset
  77                 (AtomicLong.class.getDeclaredField("value"));