1.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicLong.java Thu Oct 03 15:40:35 2013 +0200
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicLong.java Fri Oct 04 10:52:01 2013 +0200
1.3 @@ -34,7 +34,6 @@
1.4 */
1.5
1.6 package java.util.concurrent.atomic;
1.7 -import sun.misc.Unsafe;
1.8
1.9 /**
1.10 * A {@code long} value that may be updated atomically. See the
1.11 @@ -52,17 +51,6 @@
1.12 public class AtomicLong extends Number implements java.io.Serializable {
1.13 private static final long serialVersionUID = 1927816293512124184L;
1.14
1.15 - // setup to use Unsafe.compareAndSwapLong for updates
1.16 - private static final Unsafe unsafe = Unsafe.getUnsafe();
1.17 - private static final long valueOffset;
1.18 -
1.19 - /**
1.20 - * Records whether the underlying JVM supports lockless
1.21 - * compareAndSwap for longs. While the Unsafe.compareAndSwapLong
1.22 - * method works in either case, some constructions should be
1.23 - * handled at Java level to avoid locking user-visible locks.
1.24 - */
1.25 - static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
1.26
1.27 /**
1.28 * Returns whether underlying JVM supports lockless CompareAndSet
1.29 @@ -70,13 +58,6 @@
1.30 */
1.31 private static native boolean VMSupportsCS8();
1.32
1.33 - static {
1.34 - try {
1.35 - valueOffset = unsafe.objectFieldOffset
1.36 - (AtomicLong.class.getDeclaredField("value"));
1.37 - } catch (Exception ex) { throw new Error(ex); }
1.38 - }
1.39 -
1.40 private volatile long value;
1.41
1.42 /**
1.43 @@ -119,7 +100,7 @@
1.44 * @since 1.6
1.45 */
1.46 public final void lazySet(long newValue) {
1.47 - unsafe.putOrderedLong(this, valueOffset, newValue);
1.48 + value = newValue;
1.49 }
1.50
1.51 /**
1.52 @@ -146,7 +127,12 @@
1.53 * the actual value was not equal to the expected value.
1.54 */
1.55 public final boolean compareAndSet(long expect, long update) {
1.56 - return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
1.57 + if (value == expect) {
1.58 + value = update;
1.59 + return true;
1.60 + } else {
1.61 + return false;
1.62 + }
1.63 }
1.64
1.65 /**
1.66 @@ -162,7 +148,7 @@
1.67 * @return true if successful.
1.68 */
1.69 public final boolean weakCompareAndSet(long expect, long update) {
1.70 - return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
1.71 + return compareAndSet(expect, update);
1.72 }
1.73
1.74 /**