< prev index next >

test/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java

Print this page

        

*** 40,54 **** import java.util.List; import static org.testng.Assert.*; public class VarHandleTestAccessLong extends VarHandleBaseTest { ! static final long static_final_v = 1L; static long static_v; ! final long final_v = 1L; long v; VarHandle vhFinalField; --- 40,54 ---- import java.util.List; import static org.testng.Assert.*; public class VarHandleTestAccessLong extends VarHandleBaseTest { ! static final long static_final_v = 0x0123456789ABCDEFL; static long static_v; ! final long final_v = 0x0123456789ABCDEFL; long v; VarHandle vhFinalField;
*** 217,453 **** static void testInstanceFinalField(VarHandleTestAccessLong recv, VarHandle vh) { // Plain { long x = (long) vh.get(recv); ! assertEquals(x, 1L, "get long value"); } // Volatile { long x = (long) vh.getVolatile(recv); ! assertEquals(x, 1L, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(recv); ! assertEquals(x, 1L, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(recv); ! assertEquals(x, 1L, "getOpaque long value"); } } static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) { checkUOE(() -> { ! vh.set(recv, 2L); }); checkUOE(() -> { ! vh.setVolatile(recv, 2L); }); checkUOE(() -> { ! vh.setRelease(recv, 2L); }); checkUOE(() -> { ! vh.setOpaque(recv, 2L); }); } static void testStaticFinalField(VarHandle vh) { // Plain { long x = (long) vh.get(); ! assertEquals(x, 1L, "get long value"); } // Volatile { long x = (long) vh.getVolatile(); ! assertEquals(x, 1L, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(); ! assertEquals(x, 1L, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(); ! assertEquals(x, 1L, "getOpaque long value"); } } static void testStaticFinalFieldUnsupported(VarHandle vh) { checkUOE(() -> { ! vh.set(2L); }); checkUOE(() -> { ! vh.setVolatile(2L); }); checkUOE(() -> { ! vh.setRelease(2L); }); checkUOE(() -> { ! vh.setOpaque(2L); }); } static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) { // Plain { ! vh.set(recv, 1L); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "set long value"); } // Volatile { ! vh.setVolatile(recv, 2L); long x = (long) vh.getVolatile(recv); ! assertEquals(x, 2L, "setVolatile long value"); } // Lazy { ! vh.setRelease(recv, 1L); long x = (long) vh.getAcquire(recv); ! assertEquals(x, 1L, "setRelease long value"); } // Opaque { ! vh.setOpaque(recv, 2L); long x = (long) vh.getOpaque(recv); ! assertEquals(x, 2L, "setOpaque long value"); } ! vh.set(recv, 1L); // Compare { ! boolean r = vh.compareAndSet(recv, 1L, 2L); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(recv, 1L, 3L); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(recv, 2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeVolatile long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(recv, 2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(recv, 1L, 2L); ! assertEquals(r, 1L, "success compareAndExchangeAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(recv, 1L, 3L); ! assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(recv, 2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(recv, 2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(recv, 1L, 2L); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(recv, 2L, 1L); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(recv, 1L, 2L); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 2L, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet(recv, 1L); ! assertEquals(o, 2L, "getAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 1L, "getAndSet long value"); } ! vh.set(recv, 1L); // get and add, add and get { ! long o = (long) vh.getAndAdd(recv, 3L); ! assertEquals(o, 1L, "getAndAdd long"); ! long c = (long) vh.addAndGet(recv, 3L); ! assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); } } static void testInstanceFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) { --- 217,453 ---- static void testInstanceFinalField(VarHandleTestAccessLong recv, VarHandle vh) { // Plain { long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "get long value"); } // Volatile { long x = (long) vh.getVolatile(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value"); } } static void testInstanceFinalFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) { checkUOE(() -> { ! vh.set(recv, 0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setVolatile(recv, 0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setRelease(recv, 0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setOpaque(recv, 0xCAFEBABECAFEBABEL); }); } static void testStaticFinalField(VarHandle vh) { // Plain { long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "get long value"); } // Volatile { long x = (long) vh.getVolatile(); ! assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(); ! assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(); ! assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value"); } } static void testStaticFinalFieldUnsupported(VarHandle vh) { checkUOE(() -> { ! vh.set(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setVolatile(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setRelease(0xCAFEBABECAFEBABEL); }); checkUOE(() -> { ! vh.setOpaque(0xCAFEBABECAFEBABEL); }); } static void testInstanceField(VarHandleTestAccessLong recv, VarHandle vh) { // Plain { ! vh.set(recv, 0x0123456789ABCDEFL); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "set long value"); } // Volatile { ! vh.setVolatile(recv, 0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); } // Lazy { ! vh.setRelease(recv, 0x0123456789ABCDEFL); long x = (long) vh.getAcquire(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); } // Opaque { ! vh.setOpaque(recv, 0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); } ! vh.set(recv, 0x0123456789ABCDEFL); // Compare { ! boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeVolatile long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); ! assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(recv); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet(recv, 0x0123456789ABCDEFL); ! assertEquals(o, 0xCAFEBABECAFEBABEL, "getAndSet long"); long x = (long) vh.get(recv); ! assertEquals(x, 0x0123456789ABCDEFL, "getAndSet long value"); } ! vh.set(recv, 0x0123456789ABCDEFL); // get and add, add and get { ! long o = (long) vh.getAndAdd(recv, 0xDEADBEEFDEADBEEFL); ! assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); ! long c = (long) vh.addAndGet(recv, 0xDEADBEEFDEADBEEFL); ! assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value"); } } static void testInstanceFieldUnsupported(VarHandleTestAccessLong recv, VarHandle vh) {
*** 455,596 **** static void testStaticField(VarHandle vh) { // Plain { ! vh.set(1L); long x = (long) vh.get(); ! assertEquals(x, 1L, "set long value"); } // Volatile { ! vh.setVolatile(2L); long x = (long) vh.getVolatile(); ! assertEquals(x, 2L, "setVolatile long value"); } // Lazy { ! vh.setRelease(1L); long x = (long) vh.getAcquire(); ! assertEquals(x, 1L, "setRelease long value"); } // Opaque { ! vh.setOpaque(2L); long x = (long) vh.getOpaque(); ! assertEquals(x, 2L, "setOpaque long value"); } ! vh.set(1L); // Compare { ! boolean r = vh.compareAndSet(1L, 2L); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(1L, 3L); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeVolatile long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(1L, 2L); ! assertEquals(r, 1L, "success compareAndExchangeAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(1L, 3L); ! assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeRelease long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeRelease long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(1L, 2L); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(2L, 1L); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(1L, 2L); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(); ! assertEquals(x, 2L, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet( 1L); ! assertEquals(o, 2L, "getAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 1L, "getAndSet long value"); } ! vh.set(1L); // get and add, add and get { ! long o = (long) vh.getAndAdd( 3L); ! assertEquals(o, 1L, "getAndAdd long"); ! long c = (long) vh.addAndGet(3L); ! assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); } } static void testStaticFieldUnsupported(VarHandle vh) { --- 455,596 ---- static void testStaticField(VarHandle vh) { // Plain { ! vh.set(0x0123456789ABCDEFL); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "set long value"); } // Volatile { ! vh.setVolatile(0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); } // Lazy { ! vh.setRelease(0x0123456789ABCDEFL); long x = (long) vh.getAcquire(); ! assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); } // Opaque { ! vh.setOpaque(0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); } ! vh.set(0x0123456789ABCDEFL); // Compare { ! boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeVolatile long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); ! assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet( 0x0123456789ABCDEFL); ! assertEquals(o, 0xCAFEBABECAFEBABEL, "getAndSet long"); long x = (long) vh.get(); ! assertEquals(x, 0x0123456789ABCDEFL, "getAndSet long value"); } ! vh.set(0x0123456789ABCDEFL); // get and add, add and get { ! long o = (long) vh.getAndAdd( 0xDEADBEEFDEADBEEFL); ! assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); ! long c = (long) vh.addAndGet(0xDEADBEEFDEADBEEFL); ! assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value"); } } static void testStaticFieldUnsupported(VarHandle vh) {
*** 601,742 **** long[] array = new long[10]; for (int i = 0; i < array.length; i++) { // Plain { ! vh.set(array, i, 1L); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "get long value"); } // Volatile { ! vh.setVolatile(array, i, 2L); long x = (long) vh.getVolatile(array, i); ! assertEquals(x, 2L, "setVolatile long value"); } // Lazy { ! vh.setRelease(array, i, 1L); long x = (long) vh.getAcquire(array, i); ! assertEquals(x, 1L, "setRelease long value"); } // Opaque { ! vh.setOpaque(array, i, 2L); long x = (long) vh.getOpaque(array, i); ! assertEquals(x, 2L, "setOpaque long value"); } ! vh.set(array, i, 1L); // Compare { ! boolean r = vh.compareAndSet(array, i, 1L, 2L); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(array, i, 1L, 3L); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(array, i, 2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeVolatile long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(array, i, 2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(array, i, 1L, 2L); ! assertEquals(r, 1L, "success compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(array, i, 1L, 3L); ! assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(array, i, 2L, 1L); ! assertEquals(r, 2L, "success compareAndExchangeRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(array, i, 2L, 3L); ! assertEquals(r, 1L, "failing compareAndExchangeRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(array, i, 1L, 2L); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(array, i, 2L, 1L); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(array, i, 1L, 2L); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 2L, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet(array, i, 1L); ! assertEquals(o, 2L, "getAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 1L, "getAndSet long value"); } ! vh.set(array, i, 1L); // get and add, add and get { ! long o = (long) vh.getAndAdd(array, i, 3L); ! assertEquals(o, 1L, "getAndAdd long"); ! long c = (long) vh.addAndGet(array, i, 3L); ! assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); } } } static void testArrayUnsupported(VarHandle vh) { --- 601,742 ---- long[] array = new long[10]; for (int i = 0; i < array.length; i++) { // Plain { ! vh.set(array, i, 0x0123456789ABCDEFL); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "get long value"); } // Volatile { ! vh.setVolatile(array, i, 0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); } // Lazy { ! vh.setRelease(array, i, 0x0123456789ABCDEFL); long x = (long) vh.getAcquire(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); } // Opaque { ! vh.setOpaque(array, i, 0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); } ! vh.set(array, i, 0x0123456789ABCDEFL); // Compare { ! boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); } { ! boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeVolatile long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeVolatile(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeVolatile long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); ! assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); } { ! long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); ! assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); } { ! long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); ! assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSet long value"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); } assertEquals(success, true, "weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "weakCompareAndSetAcquire long"); } { boolean success = false; for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = vh.weakCompareAndSetRelease(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); } assertEquals(success, true, "weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0xCAFEBABECAFEBABEL, "weakCompareAndSetRelease long"); } // Compare set and get { ! long o = (long) vh.getAndSet(array, i, 0x0123456789ABCDEFL); ! assertEquals(o, 0xCAFEBABECAFEBABEL, "getAndSet long"); long x = (long) vh.get(array, i); ! assertEquals(x, 0x0123456789ABCDEFL, "getAndSet long value"); } ! vh.set(array, i, 0x0123456789ABCDEFL); // get and add, add and get { ! long o = (long) vh.getAndAdd(array, i, 0xDEADBEEFDEADBEEFL); ! assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); ! long c = (long) vh.addAndGet(array, i, 0xDEADBEEFDEADBEEFL); ! assertEquals(c, (long)(0x0123456789ABCDEFL + 0xDEADBEEFDEADBEEFL + 0xDEADBEEFDEADBEEFL), "getAndAdd long value"); } } } static void testArrayUnsupported(VarHandle vh) {
*** 755,829 **** checkIOOBE(() -> { long x = (long) vh.get(array, ci); }); checkIOOBE(() -> { ! vh.set(array, ci, 1L); }); checkIOOBE(() -> { long x = (long) vh.getVolatile(array, ci); }); checkIOOBE(() -> { ! vh.setVolatile(array, ci, 1L); }); checkIOOBE(() -> { long x = (long) vh.getAcquire(array, ci); }); checkIOOBE(() -> { ! vh.setRelease(array, ci, 1L); }); checkIOOBE(() -> { long x = (long) vh.getOpaque(array, ci); }); checkIOOBE(() -> { ! vh.setOpaque(array, ci, 1L); }); checkIOOBE(() -> { ! boolean r = vh.compareAndSet(array, ci, 1L, 2L); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeVolatile(array, ci, 2L, 1L); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeAcquire(array, ci, 2L, 1L); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeRelease(array, ci, 2L, 1L); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSet(array, ci, 1L, 2L); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSetAcquire(array, ci, 1L, 2L); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSetRelease(array, ci, 1L, 2L); }); checkIOOBE(() -> { ! long o = (long) vh.getAndSet(array, ci, 1L); }); checkIOOBE(() -> { ! long o = (long) vh.getAndAdd(array, ci, 3L); }); checkIOOBE(() -> { ! long o = (long) vh.addAndGet(array, ci, 3L); }); } } } --- 755,829 ---- checkIOOBE(() -> { long x = (long) vh.get(array, ci); }); checkIOOBE(() -> { ! vh.set(array, ci, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { long x = (long) vh.getVolatile(array, ci); }); checkIOOBE(() -> { ! vh.setVolatile(array, ci, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { long x = (long) vh.getAcquire(array, ci); }); checkIOOBE(() -> { ! vh.setRelease(array, ci, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { long x = (long) vh.getOpaque(array, ci); }); checkIOOBE(() -> { ! vh.setOpaque(array, ci, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { ! boolean r = vh.compareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeVolatile(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeAcquire(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { ! long r = (long) vh.compareAndExchangeRelease(array, ci, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSet(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); }); checkIOOBE(() -> { ! boolean r = vh.weakCompareAndSetRelease(array, ci, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); }); checkIOOBE(() -> { ! long o = (long) vh.getAndSet(array, ci, 0x0123456789ABCDEFL); }); checkIOOBE(() -> { ! long o = (long) vh.getAndAdd(array, ci, 0xDEADBEEFDEADBEEFL); }); checkIOOBE(() -> { ! long o = (long) vh.addAndGet(array, ci, 0xDEADBEEFDEADBEEFL); }); } } }
< prev index next >