--- jsr166/src/test/tck/AtomicLongArrayTest.java 2016/06/16 23:35:25 1.33 +++ jsr166/src/test/tck/AtomicLongArrayTest.java 2016/09/15 01:18:01 1.36 @@ -85,54 +85,6 @@ public class AtomicLongArrayTest extends aa.addAndGet(index, 1); shouldThrow(); } catch (IndexOutOfBoundsException success) {} - try { - aa.getPlain(index); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.getOpaque(index); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.getAcquire(index); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.setPlain(index, 1); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.setOpaque(index, 1); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.setRelease(index, 1); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.compareAndExchange(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.compareAndExchangeAcquire(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.compareAndExchangeRelease(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.weakCompareAndSetVolatile(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.weakCompareAndSetAcquire(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} - try { - aa.weakCompareAndSetRelease(index, 1, 2); - shouldThrow(); - } catch (IndexOutOfBoundsException success) {} } } @@ -323,7 +275,7 @@ public class AtomicLongArrayTest extends class Counter extends CheckedRunnable { final AtomicLongArray aa; - volatile long counts; + int decs; Counter(AtomicLongArray a) { aa = a; } public void realRun() { for (;;) { @@ -334,7 +286,7 @@ public class AtomicLongArrayTest extends if (v != 0) { done = false; if (aa.compareAndSet(i, v, v - 1)) - ++counts; + decs++; } } if (done) @@ -354,13 +306,11 @@ public class AtomicLongArrayTest extends aa.set(i, countdown); Counter c1 = new Counter(aa); Counter c2 = new Counter(aa); - Thread t1 = new Thread(c1); - Thread t2 = new Thread(c2); - t1.start(); - t2.start(); + Thread t1 = newStartedThread(c1); + Thread t2 = newStartedThread(c2); t1.join(); t2.join(); - assertEquals(c1.counts+c2.counts, SIZE * countdown); + assertEquals(c1.decs + c2.decs, SIZE * countdown); } /** @@ -387,198 +337,4 @@ public class AtomicLongArrayTest extends assertEquals(Arrays.toString(a), aa.toString()); } - // jdk9 - - /** - * getPlain returns the last value set - */ - public void testGetPlainSet() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.getPlain(i)); - aa.set(i, 2); - assertEquals(2, aa.getPlain(i)); - aa.set(i, -3); - assertEquals(-3, aa.getPlain(i)); - } - } - - /** - * getOpaque returns the last value set - */ - public void testGetOpaqueSet() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.getOpaque(i)); - aa.set(i, 2); - assertEquals(2, aa.getOpaque(i)); - aa.set(i, -3); - assertEquals(-3, aa.getOpaque(i)); - } - } - - /** - * getAcquire returns the last value set - */ - public void testGetAcquireSet() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.getAcquire(i)); - aa.set(i, 2); - assertEquals(2, aa.getAcquire(i)); - aa.set(i, -3); - assertEquals(-3, aa.getAcquire(i)); - } - } - - /** - * get returns the last value setPlain - */ - public void testGetSetPlain() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.setPlain(i, 1); - assertEquals(1, aa.get(i)); - aa.setPlain(i, 2); - assertEquals(2, aa.get(i)); - aa.setPlain(i, -3); - assertEquals(-3, aa.get(i)); - } - } - - /** - * get returns the last value setOpaque - */ - public void testGetSetOpaque() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.setOpaque(i, 1); - assertEquals(1, aa.get(i)); - aa.setOpaque(i, 2); - assertEquals(2, aa.get(i)); - aa.setOpaque(i, -3); - assertEquals(-3, aa.get(i)); - } - } - - /** - * get returns the last value setRelease - */ - public void testGetSetRelease() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.setRelease(i, 1); - assertEquals(1, aa.get(i)); - aa.setRelease(i, 2); - assertEquals(2, aa.get(i)); - aa.setRelease(i, -3); - assertEquals(-3, aa.get(i)); - } - } - - /** - * compareAndExchange succeeds in changing value if equal to - * expected else fails - */ - public void testCompareAndExchange() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.compareAndExchange(i, 1, 2)); - assertEquals(2, aa.compareAndExchange(i, 2, -4)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchange(i,-5, 7)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchange(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - - /** - * compareAndExchangeAcquire succeeds in changing value if equal to - * expected else fails - */ - public void testCompareAndExchangeAcquire() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.compareAndExchangeAcquire(i, 1, 2)); - assertEquals(2, aa.compareAndExchangeAcquire(i, 2, -4)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchangeAcquire(i,-5, 7)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchangeAcquire(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - - /** - * compareAndExchangeRelease succeeds in changing value if equal to - * expected else fails - */ - public void testCompareAndExchangeRelease() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - assertEquals(1, aa.compareAndExchangeRelease(i, 1, 2)); - assertEquals(2, aa.compareAndExchangeRelease(i, 2, -4)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchangeRelease(i,-5, 7)); - assertEquals(-4, aa.get(i)); - assertEquals(-4, aa.compareAndExchangeRelease(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - - /** - * repeated weakCompareAndSetVolatile succeeds in changing value when equal - * to expected - */ - public void testWeakCompareAndSetVolatile() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - do {} while (!aa.weakCompareAndSetVolatile(i, 1, 2)); - do {} while (!aa.weakCompareAndSetVolatile(i, 2, -4)); - assertEquals(-4, aa.get(i)); - do {} while (!aa.weakCompareAndSetVolatile(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - - /** - * repeated weakCompareAndSetAcquire succeeds in changing value when equal - * to expected - */ - public void testWeakCompareAndSetAcquire() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - do {} while (!aa.weakCompareAndSetAcquire(i, 1, 2)); - do {} while (!aa.weakCompareAndSetAcquire(i, 2, -4)); - assertEquals(-4, aa.get(i)); - do {} while (!aa.weakCompareAndSetAcquire(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - - /** - * repeated weakCompareAndSetRelease succeeds in changing value when equal - * to expected - */ - public void testWeakCompareAndSetRelease() { - AtomicLongArray aa = new AtomicLongArray(SIZE); - for (int i = 0; i < SIZE; i++) { - aa.set(i, 1); - do {} while (!aa.weakCompareAndSetRelease(i, 1, 2)); - do {} while (!aa.weakCompareAndSetRelease(i, 2, -4)); - assertEquals(-4, aa.get(i)); - do {} while (!aa.weakCompareAndSetRelease(i, -4, 7)); - assertEquals(7, aa.get(i)); - } - } - }