59 * compareAndSet for longs. While the intrinsic compareAndSetLong
60 * method works in either case, some constructions should be
61 * handled at Java level to avoid locking user-visible locks.
62 */
63 static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
64
65 /**
66 * Returns whether underlying JVM supports lockless CompareAndSet
67 * for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS.
68 */
69 private static native boolean VMSupportsCS8();
70
71 /*
72 * This class intended to be implemented using VarHandles, but there
73 * are unresolved cyclic startup dependencies.
74 */
75 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
76 private static final long VALUE;
77
78 static {
79 try {
80 VALUE = U.objectFieldOffset
81 (AtomicLong.class.getDeclaredField("value"));
82 } catch (ReflectiveOperationException e) {
83 throw new Error(e);
84 }
85 }
86
87 private volatile long value;
88
89 /**
90 * Creates a new AtomicLong with the given initial value.
91 *
92 * @param initialValue the initial value
93 */
94 public AtomicLong(long initialValue) {
95 value = initialValue;
96 }
97
98 /**
99 * Creates a new AtomicLong with initial value {@code 0}.
100 */
101 public AtomicLong() {
102 }
103
104 /**
|
59 * compareAndSet for longs. While the intrinsic compareAndSetLong
60 * method works in either case, some constructions should be
61 * handled at Java level to avoid locking user-visible locks.
62 */
63 static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
64
65 /**
66 * Returns whether underlying JVM supports lockless CompareAndSet
67 * for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS.
68 */
69 private static native boolean VMSupportsCS8();
70
71 /*
72 * This class intended to be implemented using VarHandles, but there
73 * are unresolved cyclic startup dependencies.
74 */
75 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
76 private static final long VALUE;
77
78 static {
79 VALUE = U.objectFieldOffset(AtomicLong.class, "value");
80 }
81
82 private volatile long value;
83
84 /**
85 * Creates a new AtomicLong with the given initial value.
86 *
87 * @param initialValue the initial value
88 */
89 public AtomicLong(long initialValue) {
90 value = initialValue;
91 }
92
93 /**
94 * Creates a new AtomicLong with initial value {@code 0}.
95 */
96 public AtomicLong() {
97 }
98
99 /**
|