1.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicInteger.java Thu Oct 03 15:40:35 2013 +0200
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicInteger.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 * An {@code int} value that may be updated atomically. See the
1.11 @@ -52,17 +51,6 @@
1.12 public class AtomicInteger extends Number implements java.io.Serializable {
1.13 private static final long serialVersionUID = 6214790243416807050L;
1.14
1.15 - // setup to use Unsafe.compareAndSwapInt for updates
1.16 - private static final Unsafe unsafe = Unsafe.getUnsafe();
1.17 - private static final long valueOffset;
1.18 -
1.19 - static {
1.20 - try {
1.21 - valueOffset = unsafe.objectFieldOffset
1.22 - (AtomicInteger.class.getDeclaredField("value"));
1.23 - } catch (Exception ex) { throw new Error(ex); }
1.24 - }
1.25 -
1.26 private volatile int value;
1.27
1.28 /**
1.29 @@ -105,7 +93,7 @@
1.30 * @since 1.6
1.31 */
1.32 public final void lazySet(int newValue) {
1.33 - unsafe.putOrderedInt(this, valueOffset, newValue);
1.34 + value = newValue;
1.35 }
1.36
1.37 /**
1.38 @@ -132,7 +120,12 @@
1.39 * the actual value was not equal to the expected value.
1.40 */
1.41 public final boolean compareAndSet(int expect, int update) {
1.42 - return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
1.43 + if (value == expect) {
1.44 + value = update;
1.45 + return true;
1.46 + } else {
1.47 + return false;
1.48 + }
1.49 }
1.50
1.51 /**
1.52 @@ -148,7 +141,7 @@
1.53 * @return true if successful.
1.54 */
1.55 public final boolean weakCompareAndSet(int expect, int update) {
1.56 - return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
1.57 + return compareAndSet(expect, update);
1.58 }
1.59
1.60 /**