< prev index next >

test/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java

Print this page

        

@@ -40,15 +40,15 @@
 import java.util.List;
 
 import static org.testng.Assert.*;
 
 public class VarHandleTestAccessChar extends VarHandleBaseTest {
-    static final char static_final_v = 'a';
+    static final char static_final_v = '\u0123';
 
     static char static_v;
 
-    final char final_v = 'a';
+    final char final_v = '\u0123';
 
     char v;
 
     VarHandle vhFinalField;
 

@@ -97,22 +97,21 @@
         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
-        assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
+        assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET));
     }
 
 
     @DataProvider
     public Object[][] typesProvider() throws Exception {

@@ -218,410 +217,535 @@
 
     static void testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh) {
         // Plain
         {
             char x = (char) vh.get(recv);
-            assertEquals(x, 'a', "get char value");
+            assertEquals(x, '\u0123', "get char value");
         }
 
 
         // Volatile
         {
             char x = (char) vh.getVolatile(recv);
-            assertEquals(x, 'a', "getVolatile char value");
+            assertEquals(x, '\u0123', "getVolatile char value");
         }
 
         // Lazy
         {
             char x = (char) vh.getAcquire(recv);
-            assertEquals(x, 'a', "getRelease char value");
+            assertEquals(x, '\u0123', "getRelease char value");
         }
 
         // Opaque
         {
             char x = (char) vh.getOpaque(recv);
-            assertEquals(x, 'a', "getOpaque char value");
+            assertEquals(x, '\u0123', "getOpaque char value");
         }
     }
 
     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
         checkUOE(() -> {
-            vh.set(recv, 'b');
+            vh.set(recv, '\u4567');
         });
 
         checkUOE(() -> {
-            vh.setVolatile(recv, 'b');
+            vh.setVolatile(recv, '\u4567');
         });
 
         checkUOE(() -> {
-            vh.setRelease(recv, 'b');
+            vh.setRelease(recv, '\u4567');
         });
 
         checkUOE(() -> {
-            vh.setOpaque(recv, 'b');
+            vh.setOpaque(recv, '\u4567');
         });
 
-        checkUOE(() -> {
-            boolean r = vh.compareAndSet(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeVolatile(recv, 'a', 'b');
-        });
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeAcquire(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeRelease(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSet(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetVolatile(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetAcquire(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetRelease(recv, 'a', 'b');
-        });
-
-        checkUOE(() -> {
-            char o = (char) vh.getAndAdd(recv, 'a');
-        });
-
-        checkUOE(() -> {
-            char o = (char) vh.addAndGet(recv, 'a');
-        });
     }
 
 
     static void testStaticFinalField(VarHandle vh) {
         // Plain
         {
             char x = (char) vh.get();
-            assertEquals(x, 'a', "get char value");
+            assertEquals(x, '\u0123', "get char value");
         }
 
 
         // Volatile
         {
             char x = (char) vh.getVolatile();
-            assertEquals(x, 'a', "getVolatile char value");
+            assertEquals(x, '\u0123', "getVolatile char value");
         }
 
         // Lazy
         {
             char x = (char) vh.getAcquire();
-            assertEquals(x, 'a', "getRelease char value");
+            assertEquals(x, '\u0123', "getRelease char value");
         }
 
         // Opaque
         {
             char x = (char) vh.getOpaque();
-            assertEquals(x, 'a', "getOpaque char value");
+            assertEquals(x, '\u0123', "getOpaque char value");
         }
     }
 
     static void testStaticFinalFieldUnsupported(VarHandle vh) {
         checkUOE(() -> {
-            vh.set('b');
+            vh.set('\u4567');
         });
 
         checkUOE(() -> {
-            vh.setVolatile('b');
+            vh.setVolatile('\u4567');
         });
 
         checkUOE(() -> {
-            vh.setRelease('b');
+            vh.setRelease('\u4567');
         });
 
         checkUOE(() -> {
-            vh.setOpaque('b');
+            vh.setOpaque('\u4567');
         });
 
-        checkUOE(() -> {
-            boolean r = vh.compareAndSet('a', 'b');
-        });
-
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeVolatile('a', 'b');
-        });
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeAcquire('a', 'b');
-        });
-
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeRelease('a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSet('a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetVolatile('a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetAcquire('a', 'b');
-        });
-
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetRelease('a', 'b');
-        });
-
-        checkUOE(() -> {
-            char o = (char) vh.getAndAdd('a');
-        });
-
-        checkUOE(() -> {
-            char o = (char) vh.addAndGet('a');
-        });
     }
 
 
     static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) {
         // Plain
         {
-            vh.set(recv, 'a');
+            vh.set(recv, '\u0123');
             char x = (char) vh.get(recv);
-            assertEquals(x, 'a', "set char value");
+            assertEquals(x, '\u0123', "set char value");
         }
 
 
         // Volatile
         {
-            vh.setVolatile(recv, 'b');
+            vh.setVolatile(recv, '\u4567');
             char x = (char) vh.getVolatile(recv);
-            assertEquals(x, 'b', "setVolatile char value");
+            assertEquals(x, '\u4567', "setVolatile char value");
         }
 
         // Lazy
         {
-            vh.setRelease(recv, 'a');
+            vh.setRelease(recv, '\u0123');
             char x = (char) vh.getAcquire(recv);
-            assertEquals(x, 'a', "setRelease char value");
+            assertEquals(x, '\u0123', "setRelease char value");
         }
 
         // Opaque
         {
-            vh.setOpaque(recv, 'b');
+            vh.setOpaque(recv, '\u4567');
             char x = (char) vh.getOpaque(recv);
-            assertEquals(x, 'b', "setOpaque char value");
+            assertEquals(x, '\u4567', "setOpaque char value");
         }
 
+        vh.set(recv, '\u0123');
 
+        // Compare
+        {
+            boolean r = vh.compareAndSet(recv, '\u0123', '\u4567');
+            assertEquals(r, true, "success compareAndSet char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "success compareAndSet char value");
     }
 
-    static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
-        checkUOE(() -> {
-            boolean r = vh.compareAndSet(recv, 'a', 'b');
-        });
+        {
+            boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB');
+            assertEquals(r, false, "failing compareAndSet char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "failing compareAndSet char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeVolatile(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeVolatile(recv, '\u4567', '\u0123');
+            assertEquals(r, '\u4567', "success compareAndExchangeVolatile char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeAcquire(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeVolatile(recv, '\u4567', '\u89AB');
+            assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeRelease(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567');
+            assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSet(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB');
+            assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetVolatile(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123');
+            assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetAcquire(recv, 'a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB');
+            assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetRelease(recv, 'a', 'b');
-        });
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSet(recv, '\u0123', '\u4567');
+            }
+            assertEquals(success, true, "weakCompareAndSet char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "weakCompareAndSet char value");
+        }
 
-        checkUOE(() -> {
-            char o = (char) vh.getAndAdd(recv, 'a');
-        });
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123');
+            }
+            assertEquals(success, true, "weakCompareAndSetAcquire char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+        }
+
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567');
+            }
+            assertEquals(success, true, "weakCompareAndSetRelease char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+        }
+
+        // Compare set and get
+        {
+            char o = (char) vh.getAndSet(recv, '\u0123');
+            assertEquals(o, '\u4567', "getAndSet char");
+            char x = (char) vh.get(recv);
+            assertEquals(x, '\u0123', "getAndSet char value");
+        }
+
+        vh.set(recv, '\u0123');
+
+        // get and add, add and get
+        {
+            char o = (char) vh.getAndAdd(recv, '\u89AB');
+            assertEquals(o, '\u0123', "getAndAdd char");
+            char c = (char) vh.addAndGet(recv, '\u89AB');
+            assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
+        }
+    }
+
+    static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
 
-        checkUOE(() -> {
-            char o = (char) vh.addAndGet(recv, 'a');
-        });
     }
 
 
     static void testStaticField(VarHandle vh) {
         // Plain
         {
-            vh.set('a');
+            vh.set('\u0123');
             char x = (char) vh.get();
-            assertEquals(x, 'a', "set char value");
+            assertEquals(x, '\u0123', "set char value");
         }
 
 
         // Volatile
         {
-            vh.setVolatile('b');
+            vh.setVolatile('\u4567');
             char x = (char) vh.getVolatile();
-            assertEquals(x, 'b', "setVolatile char value");
+            assertEquals(x, '\u4567', "setVolatile char value");
         }
 
         // Lazy
         {
-            vh.setRelease('a');
+            vh.setRelease('\u0123');
             char x = (char) vh.getAcquire();
-            assertEquals(x, 'a', "setRelease char value");
+            assertEquals(x, '\u0123', "setRelease char value");
         }
 
         // Opaque
         {
-            vh.setOpaque('b');
+            vh.setOpaque('\u4567');
             char x = (char) vh.getOpaque();
-            assertEquals(x, 'b', "setOpaque char value");
+            assertEquals(x, '\u4567', "setOpaque char value");
         }
 
+        vh.set('\u0123');
 
+        // Compare
+        {
+            boolean r = vh.compareAndSet('\u0123', '\u4567');
+            assertEquals(r, true, "success compareAndSet char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "success compareAndSet char value");
     }
 
-    static void testStaticFieldUnsupported(VarHandle vh) {
-        checkUOE(() -> {
-            boolean r = vh.compareAndSet('a', 'b');
-        });
+        {
+            boolean r = vh.compareAndSet('\u0123', '\u89AB');
+            assertEquals(r, false, "failing compareAndSet char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "failing compareAndSet char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeVolatile('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeVolatile('\u4567', '\u0123');
+            assertEquals(r, '\u4567', "success compareAndExchangeVolatile char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeAcquire('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeVolatile('\u4567', '\u89AB');
+            assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value");
+        }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeRelease('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567');
+            assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSet('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB');
+            assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetVolatile('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123');
+            assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetAcquire('a', 'b');
-        });
+        {
+            char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB');
+            assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+        }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetRelease('a', 'b');
-        });
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSet('\u0123', '\u4567');
+            }
+            assertEquals(success, true, "weakCompareAndSet char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "weakCompareAndSet char value");
+        }
 
-        checkUOE(() -> {
-            char o = (char) vh.getAndAdd('a');
-        });
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSetAcquire('\u4567', '\u0123');
+            }
+            assertEquals(success, true, "weakCompareAndSetAcquire char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+        }
+
+        {
+            boolean success = false;
+            for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                success = vh.weakCompareAndSetRelease('\u0123', '\u4567');
+            }
+            assertEquals(success, true, "weakCompareAndSetRelease char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+        }
+
+        // Compare set and get
+        {
+            char o = (char) vh.getAndSet( '\u0123');
+            assertEquals(o, '\u4567', "getAndSet char");
+            char x = (char) vh.get();
+            assertEquals(x, '\u0123', "getAndSet char value");
+        }
+
+        vh.set('\u0123');
+
+        // get and add, add and get
+        {
+            char o = (char) vh.getAndAdd( '\u89AB');
+            assertEquals(o, '\u0123', "getAndAdd char");
+            char c = (char) vh.addAndGet('\u89AB');
+            assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
+        }
+    }
+
+    static void testStaticFieldUnsupported(VarHandle vh) {
 
-        checkUOE(() -> {
-            char o = (char) vh.addAndGet('a');
-        });
     }
 
 
     static void testArray(VarHandle vh) {
         char[] array = new char[10];
 
         for (int i = 0; i < array.length; i++) {
             // Plain
             {
-                vh.set(array, i, 'a');
+                vh.set(array, i, '\u0123');
                 char x = (char) vh.get(array, i);
-                assertEquals(x, 'a', "get char value");
+                assertEquals(x, '\u0123', "get char value");
             }
 
 
             // Volatile
             {
-                vh.setVolatile(array, i, 'b');
+                vh.setVolatile(array, i, '\u4567');
                 char x = (char) vh.getVolatile(array, i);
-                assertEquals(x, 'b', "setVolatile char value");
+                assertEquals(x, '\u4567', "setVolatile char value");
             }
 
             // Lazy
             {
-                vh.setRelease(array, i, 'a');
+                vh.setRelease(array, i, '\u0123');
                 char x = (char) vh.getAcquire(array, i);
-                assertEquals(x, 'a', "setRelease char value");
+                assertEquals(x, '\u0123', "setRelease char value");
             }
 
             // Opaque
             {
-                vh.setOpaque(array, i, 'b');
+                vh.setOpaque(array, i, '\u4567');
                 char x = (char) vh.getOpaque(array, i);
-                assertEquals(x, 'b', "setOpaque char value");
+                assertEquals(x, '\u4567', "setOpaque char value");
             }
 
+            vh.set(array, i, '\u0123');
 
+            // Compare
+            {
+                boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567');
+                assertEquals(r, true, "success compareAndSet char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "success compareAndSet char value");
         }
+
+            {
+                boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB');
+                assertEquals(r, false, "failing compareAndSet char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "failing compareAndSet char value");
     }
 
-    static void testArrayUnsupported(VarHandle vh) {
-        char[] array = new char[10];
+            {
+                char r = (char) vh.compareAndExchangeVolatile(array, i, '\u4567', '\u0123');
+                assertEquals(r, '\u4567', "success compareAndExchangeVolatile char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "success compareAndExchangeVolatile char value");
+            }
 
-        int i = 0;
-        checkUOE(() -> {
-            boolean r = vh.compareAndSet(array, i, 'a', 'b');
-        });
+            {
+                char r = (char) vh.compareAndExchangeVolatile(array, i, '\u4567', '\u89AB');
+                assertEquals(r, '\u0123', "failing compareAndExchangeVolatile char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "failing compareAndExchangeVolatile char value");
+            }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeVolatile(array, i, 'a', 'b');
-        });
+            {
+                char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567');
+                assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
+            }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeAcquire(array, i, 'a', 'b');
-        });
+            {
+                char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB');
+                assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
+            }
 
-        checkUOE(() -> {
-            char r = (char) vh.compareAndExchangeRelease(array, i, 'a', 'b');
-        });
+            {
+                char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123');
+                assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
+            }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSet(array, i, 'a', 'b');
-        });
+            {
+                char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB');
+                assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
+            }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetVolatile(array, i, 'a', 'b');
-        });
+            {
+                boolean success = false;
+                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                    success = vh.weakCompareAndSet(array, i, '\u0123', '\u4567');
+                }
+                assertEquals(success, true, "weakCompareAndSet char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "weakCompareAndSet char value");
+            }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetAcquire(array, i, 'a', 'b');
-        });
+            {
+                boolean success = false;
+                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                    success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123');
+                }
+                assertEquals(success, true, "weakCompareAndSetAcquire char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
+            }
 
-        checkUOE(() -> {
-            boolean r = vh.weakCompareAndSetRelease(array, i, 'a', 'b');
-        });
+            {
+                boolean success = false;
+                for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
+                    success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567');
+                }
+                assertEquals(success, true, "weakCompareAndSetRelease char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
+            }
 
-        checkUOE(() -> {
-            char o = (char) vh.getAndAdd(array, i, 'a');
-        });
+            // Compare set and get
+            {
+                char o = (char) vh.getAndSet(array, i, '\u0123');
+                assertEquals(o, '\u4567', "getAndSet char");
+                char x = (char) vh.get(array, i);
+                assertEquals(x, '\u0123', "getAndSet char value");
+            }
+
+            vh.set(array, i, '\u0123');
+
+            // get and add, add and get
+            {
+                char o = (char) vh.getAndAdd(array, i, '\u89AB');
+                assertEquals(o, '\u0123', "getAndAdd char");
+                char c = (char) vh.addAndGet(array, i, '\u89AB');
+                assertEquals(c, (char)('\u0123' + '\u89AB' + '\u89AB'), "getAndAdd char value");
+            }
+        }
+    }
+
+    static void testArrayUnsupported(VarHandle vh) {
+        char[] array = new char[10];
+
+        int i = 0;
 
-        checkUOE(() -> {
-            char o = (char) vh.addAndGet(array, i, 'a');
-        });
     }
 
     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
         char[] array = new char[10];
 

@@ -631,37 +755,75 @@
             checkIOOBE(() -> {
                 char x = (char) vh.get(array, ci);
             });
 
             checkIOOBE(() -> {
-                vh.set(array, ci, 'a');
+                vh.set(array, ci, '\u0123');
             });
 
             checkIOOBE(() -> {
                 char x = (char) vh.getVolatile(array, ci);
             });
 
             checkIOOBE(() -> {
-                vh.setVolatile(array, ci, 'a');
+                vh.setVolatile(array, ci, '\u0123');
             });
 
             checkIOOBE(() -> {
                 char x = (char) vh.getAcquire(array, ci);
             });
 
             checkIOOBE(() -> {
-                vh.setRelease(array, ci, 'a');
+                vh.setRelease(array, ci, '\u0123');
             });
 
             checkIOOBE(() -> {
                 char x = (char) vh.getOpaque(array, ci);
             });
 
             checkIOOBE(() -> {
-                vh.setOpaque(array, ci, 'a');
+                vh.setOpaque(array, ci, '\u0123');
+            });
+
+            checkIOOBE(() -> {
+                boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567');
+            });
+
+            checkIOOBE(() -> {
+                char r = (char) vh.compareAndExchangeVolatile(array, ci, '\u4567', '\u0123');
+            });
+
+            checkIOOBE(() -> {
+                char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123');
+            });
+
+            checkIOOBE(() -> {
+                char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123');
+            });
+
+            checkIOOBE(() -> {
+                boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567');
+            });
+
+            checkIOOBE(() -> {
+                boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567');
+            });
+
+            checkIOOBE(() -> {
+                boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567');
             });
 
+            checkIOOBE(() -> {
+                char o = (char) vh.getAndSet(array, ci, '\u0123');
+            });
 
+            checkIOOBE(() -> {
+                char o = (char) vh.getAndAdd(array, ci, '\u89AB');
+            });
+
+            checkIOOBE(() -> {
+                char o = (char) vh.addAndGet(array, ci, '\u89AB');
+            });
         }
     }
 }
 
< prev index next >