diff -r 588d5bf7a560 -r aa70afac4eca rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java --- a/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java Thu Oct 03 15:40:35 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java Fri Oct 04 10:52:01 2013 +0200 @@ -34,8 +34,6 @@ */ package java.util.concurrent.atomic; -import sun.misc.Unsafe; -import java.util.*; /** * An {@code int} array in which elements may be updated atomically. @@ -48,29 +46,8 @@ public class AtomicIntegerArray implements java.io.Serializable { private static final long serialVersionUID = 2862133569453604235L; - private static final Unsafe unsafe = Unsafe.getUnsafe(); - private static final int base = unsafe.arrayBaseOffset(int[].class); - private static final int shift; private final int[] array; - static { - int scale = unsafe.arrayIndexScale(int[].class); - if ((scale & (scale - 1)) != 0) - throw new Error("data type scale not a power of two"); - shift = 31 - Integer.numberOfLeadingZeros(scale); - } - - private long checkedByteOffset(int i) { - if (i < 0 || i >= array.length) - throw new IndexOutOfBoundsException("index " + i); - - return byteOffset(i); - } - - private static long byteOffset(int i) { - return ((long) i << shift) + base; - } - /** * Creates a new AtomicIntegerArray of the given length, with all * elements initially zero. @@ -109,11 +86,7 @@ * @return the current value */ public final int get(int i) { - return getRaw(checkedByteOffset(i)); - } - - private int getRaw(long offset) { - return unsafe.getIntVolatile(array, offset); + return array[i]; } /** @@ -123,7 +96,7 @@ * @param newValue the new value */ public final void set(int i, int newValue) { - unsafe.putIntVolatile(array, checkedByteOffset(i), newValue); + array[i] = newValue; } /** @@ -134,7 +107,7 @@ * @since 1.6 */ public final void lazySet(int i, int newValue) { - unsafe.putOrderedInt(array, checkedByteOffset(i), newValue); + array[i] = newValue; } /** @@ -146,12 +119,9 @@ * @return the previous value */ public final int getAndSet(int i, int newValue) { - long offset = checkedByteOffset(i); - while (true) { - int current = getRaw(offset); - if (compareAndSetRaw(offset, current, newValue)) - return current; - } + int current = array[i]; + array[i] = newValue; + return current; } /** @@ -165,11 +135,12 @@ * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, int expect, int update) { - return compareAndSetRaw(checkedByteOffset(i), expect, update); - } - - private boolean compareAndSetRaw(long offset, int expect, int update) { - return unsafe.compareAndSwapInt(array, offset, expect, update); + if (array[i] == expect) { + array[i] = update; + return true; + } else { + return false; + } } /** @@ -217,12 +188,9 @@ * @return the previous value */ public final int getAndAdd(int i, int delta) { - long offset = checkedByteOffset(i); - while (true) { - int current = getRaw(offset); - if (compareAndSetRaw(offset, current, current + delta)) - return current; - } + int v = array[i]; + array[i] += delta; + return v; } /** @@ -253,13 +221,8 @@ * @return the updated value */ public final int addAndGet(int i, int delta) { - long offset = checkedByteOffset(i); - while (true) { - int current = getRaw(offset); - int next = current + delta; - if (compareAndSetRaw(offset, current, next)) - return next; - } + array[i] += delta; + return array[i]; } /** @@ -274,7 +237,7 @@ StringBuilder b = new StringBuilder(); b.append('['); for (int i = 0; ; i++) { - b.append(getRaw(byteOffset(i))); + b.append(get(i)); if (i == iMax) return b.append(']').toString(); b.append(',').append(' ');