< prev index next >

test/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java

Print this page

        

*** 37,51 **** import java.util.List; import static org.testng.Assert.*; public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { ! static final char static_final_v = 'a'; static char static_v; ! final char final_v = 'a'; char v; VarHandle vhFinalField; --- 37,51 ---- import java.util.List; import static org.testng.Assert.*; public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { ! static final char static_final_v = '\u0123'; static char static_v; ! final char final_v = '\u0123'; char v; VarHandle vhFinalField;
*** 119,309 **** static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { // Plain { ! hs.get(TestAccessMode.SET).invokeExact(recv, 'a'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, 'a', "set char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 'b'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); ! assertEquals(x, 'b', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 'a'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); ! assertEquals(x, 'a', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 'b'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); ! assertEquals(x, 'b', "setOpaque char value"); } } ! static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { ! checkUOE(am, () -> { ! boolean r = (boolean) hs.get(am).invokeExact(recv, 'a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact(recv, 'a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact(recv, 'a'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact(recv, 'a'); ! }); } } static void testStaticField(Handles hs) throws Throwable { // Plain { ! hs.get(TestAccessMode.SET).invokeExact('a'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, 'a', "set char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact('b'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); ! assertEquals(x, 'b', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact('a'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); ! assertEquals(x, 'a', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact('b'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); ! assertEquals(x, 'b', "setOpaque char value"); } } ! static void testStaticFieldUnsupported(Handles hs) throws Throwable { ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { ! checkUOE(am, () -> { ! boolean r = (boolean) hs.get(am).invokeExact('a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact('a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact('a'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact('a'); ! }); } } static void testArray(Handles hs) throws Throwable { char[] array = new char[10]; for (int i = 0; i < array.length; i++) { // Plain { ! hs.get(TestAccessMode.SET).invokeExact(array, i, 'a'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, 'a', "get char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 'b'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); ! assertEquals(x, 'b', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 'a'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); ! assertEquals(x, 'a', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 'b'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); ! assertEquals(x, 'b', "setOpaque char value"); } } } ! static void testArrayUnsupported(Handles hs) throws Throwable { ! char[] array = new char[10]; ! final int i = 0; ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { ! checkUOE(am, () -> { ! boolean r = (boolean) hs.get(am).invokeExact(array, i, 'a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact(array, i, 'a', 'b'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { ! checkUOE(am, () -> { ! char r = (char) hs.get(am).invokeExact(array, i, 'a'); ! }); } ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { ! checkUOE(am, () -> { ! char o = (char) hs.get(am).invokeExact(array, i, 'a'); ! }); } } static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { char[] array = new char[10]; --- 119,558 ---- static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { // Plain { ! hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "set char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); ! assertEquals(x, '\u4567', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, '\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); ! assertEquals(x, '\u0123', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); ! assertEquals(x, '\u4567', "setOpaque char value"); } + hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); + // Compare + { + boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567'); + assertEquals(r, true, "success compareAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); + assertEquals(x, '\u4567', "success compareAndSet char value"); } ! { ! boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u89AB'); ! assertEquals(r, false, "failing compareAndSet char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u4567', "failing compareAndSet char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, '\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, '\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u4567'); ! assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u89AB'); ! assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); ! } ! ! { ! boolean success = false; ! for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567'); ! } ! assertEquals(success, true, "weakCompareAndSet char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u4567', "weakCompareAndSet char value"); ! } ! ! { ! boolean success = false; ! for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, '\u4567', '\u0123'); ! } ! assertEquals(success, true, "weakCompareAndSetAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "weakCompareAndSetAcquire char"); ! } ! ! { ! boolean success = false; ! for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, '\u0123', '\u4567'); ! } ! assertEquals(success, true, "weakCompareAndSetRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u4567', "weakCompareAndSetRelease char"); ! } ! ! // Compare set and get ! { ! char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, '\u0123'); ! assertEquals(o, '\u4567', "getAndSet char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); ! assertEquals(x, '\u0123', "getAndSet char value"); ! } ! ! hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); ! ! // get and add, add and get ! { ! char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, '\u89AB'); ! assertEquals(o, '\u0123', "getAndAdd char"); ! char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, '\u89AB'); ! assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value"); } } + static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { + + } + static void testStaticField(Handles hs) throws Throwable { // Plain { ! hs.get(TestAccessMode.SET).invokeExact('\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "set char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact('\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); ! assertEquals(x, '\u4567', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact('\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); ! assertEquals(x, '\u0123', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact('\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); ! assertEquals(x, '\u4567', "setOpaque char value"); } + hs.get(TestAccessMode.SET).invokeExact('\u0123'); + // Compare + { + boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u4567'); + assertEquals(r, true, "success compareAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(); + assertEquals(x, '\u4567', "success compareAndSet char value"); } ! { ! boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u89AB'); ! assertEquals(r, false, "failing compareAndSet char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u4567', "failing compareAndSet char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact('\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact('\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u4567'); ! assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u89AB'); ! assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); ! } ! ! { ! boolean success = false; ! for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact('\u0123', '\u4567'); ! } ! assertEquals(success, true, "weakCompareAndSet char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u4567', "weakCompareAndSet char value"); ! } ! ! { ! boolean success = false; ! for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { ! success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact('\u4567', '\u0123'); ! } ! assertEquals(success, true, "weakCompareAndSetAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(); ! assertEquals(x, '\u0123', "weakCompareAndSetAcquire char"); } + + { + boolean success = false; + for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { + success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact('\u0123', '\u4567'); + } + assertEquals(success, true, "weakCompareAndSetRelease char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(); + assertEquals(x, '\u4567', "weakCompareAndSetRelease char"); + } + + // Compare set and get + { + char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact( '\u0123'); + assertEquals(o, '\u4567', "getAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(); + assertEquals(x, '\u0123', "getAndSet char value"); + } + + hs.get(TestAccessMode.SET).invokeExact('\u0123'); + + // get and add, add and get + { + char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( '\u89AB'); + assertEquals(o, '\u0123', "getAndAdd char"); + char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact('\u89AB'); + assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value"); + } + } + + static void testStaticFieldUnsupported(Handles hs) throws Throwable { + } static void testArray(Handles hs) throws Throwable { char[] array = new char[10]; for (int i = 0; i < array.length; i++) { // Plain { ! hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u0123', "get char value"); } // Volatile { ! hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); ! assertEquals(x, '\u4567', "setVolatile char value"); } // Lazy { ! hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, '\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); ! assertEquals(x, '\u0123', "setRelease char value"); } // Opaque { ! hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); ! assertEquals(x, '\u4567', "setOpaque char value"); } + hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); + // Compare + { + boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567'); + assertEquals(r, true, "success compareAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u4567', "success compareAndSet char value"); } + + { + boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u89AB'); + assertEquals(r, false, "failing compareAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u4567', "failing compareAndSet char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, '\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value"); ! } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, '\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u4567'); ! assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u89AB'); ! assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); } ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u0123'); ! assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); ! } ! ! { ! char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u89AB'); ! assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); ! char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); ! assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); } + + { + boolean success = false; + for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { + success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567'); + } + assertEquals(success, true, "weakCompareAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u4567', "weakCompareAndSet char value"); + } + + { + boolean success = false; + for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { + success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567', '\u0123'); + } + assertEquals(success, true, "weakCompareAndSetAcquire char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u0123', "weakCompareAndSetAcquire char"); + } + + { + boolean success = false; + for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { + success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, '\u0123', '\u4567'); + } + assertEquals(success, true, "weakCompareAndSetRelease char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u4567', "weakCompareAndSetRelease char"); + } + + // Compare set and get + { + char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, '\u0123'); + assertEquals(o, '\u4567', "getAndSet char"); + char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); + assertEquals(x, '\u0123', "getAndSet char value"); + } + + hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); + + // get and add, add and get + { + char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, '\u89AB'); + assertEquals(o, '\u0123', "getAndAdd char"); + char c = (char) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, '\u89AB'); + assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value"); + } + } + } + + static void testArrayUnsupported(Handles hs) throws Throwable { + char[] array = new char[10]; + + final int i = 0; + } static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { char[] array = new char[10];
*** 316,329 **** }); } for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { checkIOOBE(am, () -> { ! hs.get(am).invokeExact(array, ci, 'a'); }); } } } } --- 565,600 ---- }); } for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { checkIOOBE(am, () -> { ! hs.get(am).invokeExact(array, ci, '\u0123'); ! }); ! } ! ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { ! checkIOOBE(am, () -> { ! boolean r = (boolean) hs.get(am).invokeExact(array, ci, '\u0123', '\u4567'); ! }); ! } ! ! for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { ! checkIOOBE(am, () -> { ! char r = (char) hs.get(am).invokeExact(array, ci, '\u4567', '\u0123'); }); } + for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { + checkIOOBE(am, () -> { + char o = (char) hs.get(am).invokeExact(array, ci, '\u0123'); + }); + } + for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { + checkIOOBE(am, () -> { + char o = (char) hs.get(am).invokeExact(array, ci, '\u89AB'); + }); + } } } }
< prev index next >