diff -r 588d5bf7a560 -r aa70afac4eca rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java --- a/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java Thu Oct 03 15:40:35 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.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 array of object references in which elements may be updated @@ -49,29 +47,8 @@ public class AtomicReferenceArray implements java.io.Serializable { private static final long serialVersionUID = -6209656149925076980L; - private static final Unsafe unsafe = Unsafe.getUnsafe(); - private static final int base = unsafe.arrayBaseOffset(Object[].class); - private static final int shift; private final Object[] array; - static { - int scale = unsafe.arrayIndexScale(Object[].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 AtomicReferenceArray of the given length, with all * elements initially null. @@ -110,11 +87,7 @@ * @return the current value */ public final E get(int i) { - return getRaw(checkedByteOffset(i)); - } - - private E getRaw(long offset) { - return (E) unsafe.getObjectVolatile(array, offset); + return (E)array[i]; } /** @@ -124,7 +97,7 @@ * @param newValue the new value */ public final void set(int i, E newValue) { - unsafe.putObjectVolatile(array, checkedByteOffset(i), newValue); + array[i] = newValue; } /** @@ -135,7 +108,7 @@ * @since 1.6 */ public final void lazySet(int i, E newValue) { - unsafe.putOrderedObject(array, checkedByteOffset(i), newValue); + array[i] = newValue; } @@ -148,12 +121,9 @@ * @return the previous value */ public final E getAndSet(int i, E newValue) { - long offset = checkedByteOffset(i); - while (true) { - E current = (E) getRaw(offset); - if (compareAndSetRaw(offset, current, newValue)) - return current; - } + E v = (E)array[i]; + array[i] = newValue; + return v; } /** @@ -167,11 +137,12 @@ * the actual value was not equal to the expected value. */ public final boolean compareAndSet(int i, E expect, E update) { - return compareAndSetRaw(checkedByteOffset(i), expect, update); - } - - private boolean compareAndSetRaw(long offset, E expect, E update) { - return unsafe.compareAndSwapObject(array, offset, expect, update); + if (array[i] == expect) { + array[i] = update; + return true; + } else { + return false; + } } /** @@ -203,7 +174,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(' ');