1 /*
   2  * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // -- This file was mechanically generated: Do not edit! -- //
  25 
  26 /*
  27  * @test
  28  * @run testng/othervm -Diters=10    -Xint                   VarHandleTestAccessChar
  29  * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar
  30  * @run testng/othervm -Diters=20000                         VarHandleTestAccessChar
  31  * @run testng/othervm -Diters=20000 -XX:-TieredCompilation  VarHandleTestAccessChar
  32  */
  33 
  34 import org.testng.annotations.BeforeClass;
  35 import org.testng.annotations.DataProvider;
  36 import org.testng.annotations.Test;
  37 
  38 import java.lang.invoke.MethodHandles;
  39 import java.lang.invoke.VarHandle;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import java.util.List;
  43 
  44 import static org.testng.Assert.*;
  45 
  46 public class VarHandleTestAccessChar extends VarHandleBaseTest {
  47     static final Class<?> type = char.class;
  48 
  49     static final char static_final_v = '\u0123';
  50 
  51     static char static_v;
  52 
  53     final char final_v = '\u0123';
  54 
  55     char v;
  56 
  57     static final char static_final_v2 = '\u0123';
  58 
  59     static char static_v2;
  60 
  61     final char final_v2 = '\u0123';
  62 
  63     char v2;
  64 
  65     VarHandle vhFinalField;
  66 
  67     VarHandle vhField;
  68 
  69     VarHandle vhStaticField;
  70 
  71     VarHandle vhStaticFinalField;
  72 
  73     VarHandle vhArray;
  74 
  75     VarHandle vhValueTypeField;
  76 
  77     VarHandle[] allocate(boolean same) {
  78         List<VarHandle> vhs = new ArrayList<>();
  79 
  80         String postfix = same ? "" : "2";
  81         VarHandle vh;
  82         try {
  83             vh = MethodHandles.lookup().findVarHandle(
  84                     VarHandleTestAccessChar.class, "final_v" + postfix, type);
  85             vhs.add(vh);
  86 
  87             vh = MethodHandles.lookup().findVarHandle(
  88                     VarHandleTestAccessChar.class, "v" + postfix, type);
  89             vhs.add(vh);
  90 
  91             vh = MethodHandles.lookup().findStaticVarHandle(
  92                 VarHandleTestAccessChar.class, "static_final_v" + postfix, type);
  93             vhs.add(vh);
  94 
  95             vh = MethodHandles.lookup().findStaticVarHandle(
  96                 VarHandleTestAccessChar.class, "static_v" + postfix, type);
  97             vhs.add(vh);
  98 
  99             if (same) {
 100                 vh = MethodHandles.arrayElementVarHandle(char[].class);
 101             }
 102             else {
 103                 vh = MethodHandles.arrayElementVarHandle(String[].class);
 104             }
 105             vhs.add(vh);
 106         } catch (Exception e) {
 107             throw new InternalError(e);
 108         }
 109         return vhs.toArray(new VarHandle[0]);
 110     }
 111 
 112     @BeforeClass
 113     public void setup() throws Exception {
 114         vhFinalField = MethodHandles.lookup().findVarHandle(
 115                 VarHandleTestAccessChar.class, "final_v", type);
 116 
 117         vhField = MethodHandles.lookup().findVarHandle(
 118                 VarHandleTestAccessChar.class, "v", type);
 119 
 120         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
 121             VarHandleTestAccessChar.class, "static_final_v", type);
 122 
 123         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
 124             VarHandleTestAccessChar.class, "static_v", type);
 125 
 126         vhArray = MethodHandles.arrayElementVarHandle(char[].class);
 127 
 128         vhValueTypeField = MethodHandles.lookup().findVarHandle(
 129                     Value.class, "char_v", type);
 130     }
 131 
 132 
 133     @DataProvider
 134     public Object[][] varHandlesProvider() throws Exception {
 135         List<VarHandle> vhs = new ArrayList<>();
 136         vhs.add(vhField);
 137         vhs.add(vhStaticField);
 138         vhs.add(vhArray);
 139 
 140         return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new);
 141     }
 142 
 143     @Test
 144     public void testEquals() {
 145         VarHandle[] vhs1 = allocate(true);
 146         VarHandle[] vhs2 = allocate(true);
 147 
 148         for (int i = 0; i < vhs1.length; i++) {
 149             for (int j = 0; j < vhs1.length; j++) {
 150                 if (i != j) {
 151                     assertNotEquals(vhs1[i], vhs1[j]);
 152                     assertNotEquals(vhs1[i], vhs2[j]);
 153                 }
 154             }
 155         }
 156 
 157         VarHandle[] vhs3 = allocate(false);
 158         for (int i = 0; i < vhs1.length; i++) {
 159             assertNotEquals(vhs1[i], vhs3[i]);
 160         }
 161     }
 162 
 163     @Test(dataProvider = "varHandlesProvider")
 164     public void testIsAccessModeSupported(VarHandle vh) {
 165         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
 166         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
 167         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
 168         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
 169         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
 170         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
 171         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 172         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 173 
 174         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 175         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
 176         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 177         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));
 178         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN));
 179         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET));
 180         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE));
 181         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE));
 182         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET));
 183         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE));
 184         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE));
 185 
 186         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD));
 187         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE));
 188         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE));
 189 
 190         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR));
 191         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE));
 192         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE));
 193         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND));
 194         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE));
 195         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE));
 196         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR));
 197         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE));
 198         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE));
 199     }
 200 
 201 
 202     @DataProvider
 203     public Object[][] typesProvider() throws Exception {
 204         List<Object[]> types = new ArrayList<>();
 205         types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessChar.class)});
 206         types.add(new Object[] {vhStaticField, Arrays.asList()});
 207         types.add(new Object[] {vhArray, Arrays.asList(char[].class, int.class)});
 208 
 209         return types.stream().toArray(Object[][]::new);
 210     }
 211 
 212     @Test(dataProvider = "typesProvider")
 213     public void testTypes(VarHandle vh, List<Class<?>> pts) {
 214         assertEquals(vh.varType(), type);
 215 
 216         assertEquals(vh.coordinateTypes(), pts);
 217 
 218         testTypes(vh);
 219     }
 220 
 221 
 222     @Test
 223     public void testLookupInstanceToStatic() {
 224         checkIAE("Lookup of static final field to instance final field", () -> {
 225             MethodHandles.lookup().findStaticVarHandle(
 226                     VarHandleTestAccessChar.class, "final_v", type);
 227         });
 228 
 229         checkIAE("Lookup of static field to instance field", () -> {
 230             MethodHandles.lookup().findStaticVarHandle(
 231                     VarHandleTestAccessChar.class, "v", type);
 232         });
 233     }
 234 
 235     @Test
 236     public void testLookupStaticToInstance() {
 237         checkIAE("Lookup of instance final field to static final field", () -> {
 238             MethodHandles.lookup().findVarHandle(
 239                 VarHandleTestAccessChar.class, "static_final_v", type);
 240         });
 241 
 242         checkIAE("Lookup of instance field to static field", () -> {
 243             vhStaticField = MethodHandles.lookup().findVarHandle(
 244                 VarHandleTestAccessChar.class, "static_v", type);
 245         });
 246     }
 247 
 248 
 249     @DataProvider
 250     public Object[][] accessTestCaseProvider() throws Exception {
 251         List<AccessTestCase<?>> cases = new ArrayList<>();
 252 
 253         cases.add(new VarHandleAccessTestCase("Instance final field",
 254                                               vhFinalField, vh -> testInstanceFinalField(this, vh)));
 255         cases.add(new VarHandleAccessTestCase("Instance final field unsupported",
 256                                               vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh),
 257                                               false));
 258 
 259         cases.add(new VarHandleAccessTestCase("Static final field",
 260                                               vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalField));
 261         cases.add(new VarHandleAccessTestCase("Static final field unsupported",
 262                                               vhStaticFinalField, VarHandleTestAccessChar::testStaticFinalFieldUnsupported,
 263                                               false));
 264 
 265         cases.add(new VarHandleAccessTestCase("Instance field",
 266                                               vhField, vh -> testInstanceField(this, vh)));
 267         cases.add(new VarHandleAccessTestCase("Instance field unsupported",
 268                                               vhField, vh -> testInstanceFieldUnsupported(this, vh),
 269                                               false));
 270 
 271         cases.add(new VarHandleAccessTestCase("Static field",
 272                                               vhStaticField, VarHandleTestAccessChar::testStaticField));
 273         cases.add(new VarHandleAccessTestCase("Static field unsupported",
 274                                               vhStaticField, VarHandleTestAccessChar::testStaticFieldUnsupported,
 275                                               false));
 276 
 277         cases.add(new VarHandleAccessTestCase("Array",
 278                                               vhArray, VarHandleTestAccessChar::testArray));
 279         cases.add(new VarHandleAccessTestCase("Array unsupported",
 280                                               vhArray, VarHandleTestAccessChar::testArrayUnsupported,
 281                                               false));
 282         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
 283                                               vhArray, VarHandleTestAccessChar::testArrayIndexOutOfBounds,
 284                                               false));
 285         cases.add(new VarHandleAccessTestCase("Value type field",
 286                                               vhValueTypeField, vh -> testValueTypeField(Value.getInstance(), vh)));
 287         cases.add(new VarHandleAccessTestCase("Value type field unsupported",
 288                                               vhValueTypeField, vh -> testValueTypeFieldUnsupported(Value.getInstance(), vh),
 289                                               false));
 290         // Work around issue with jtreg summary reporting which truncates
 291         // the String result of Object.toString to 30 characters, hence
 292         // the first dummy argument
 293         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
 294     }
 295 
 296     @Test(dataProvider = "accessTestCaseProvider")
 297     public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
 298         T t = atc.get();
 299         int iters = atc.requiresLoop() ? ITERS : 1;
 300         for (int c = 0; c < iters; c++) {
 301             atc.testAccess(t);
 302         }
 303     }
 304 
 305 
 306 
 307 
 308     static void testInstanceFinalField(VarHandleTestAccessChar recv, VarHandle vh) {
 309         // Plain
 310         {
 311             char x = (char) vh.get(recv);
 312             assertEquals(x, '\u0123', "get char value");
 313         }
 314 
 315 
 316         // Volatile
 317         {
 318             char x = (char) vh.getVolatile(recv);
 319             assertEquals(x, '\u0123', "getVolatile char value");
 320         }
 321 
 322         // Lazy
 323         {
 324             char x = (char) vh.getAcquire(recv);
 325             assertEquals(x, '\u0123', "getRelease char value");
 326         }
 327 
 328         // Opaque
 329         {
 330             char x = (char) vh.getOpaque(recv);
 331             assertEquals(x, '\u0123', "getOpaque char value");
 332         }
 333     }
 334 
 335     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
 336         checkUOE(() -> {
 337             vh.set(recv, '\u4567');
 338         });
 339 
 340         checkUOE(() -> {
 341             vh.setVolatile(recv, '\u4567');
 342         });
 343 
 344         checkUOE(() -> {
 345             vh.setRelease(recv, '\u4567');
 346         });
 347 
 348         checkUOE(() -> {
 349             vh.setOpaque(recv, '\u4567');
 350         });
 351 
 352 
 353 
 354     }
 355 
 356     static void testValueTypeField(Value recv, VarHandle vh) {
 357         // Plain
 358         {
 359             char x = (char) vh.get(recv);
 360             assertEquals(x, '\u0123', "get char value");
 361         }
 362     }
 363 
 364     static void testValueTypeFieldUnsupported(Value recv, VarHandle vh) {
 365         checkUOE(() -> {
 366             vh.set(recv, '\u4567');
 367         });
 368     }
 369 
 370     static void testStaticFinalField(VarHandle vh) {
 371         // Plain
 372         {
 373             char x = (char) vh.get();
 374             assertEquals(x, '\u0123', "get char value");
 375         }
 376 
 377 
 378         // Volatile
 379         {
 380             char x = (char) vh.getVolatile();
 381             assertEquals(x, '\u0123', "getVolatile char value");
 382         }
 383 
 384         // Lazy
 385         {
 386             char x = (char) vh.getAcquire();
 387             assertEquals(x, '\u0123', "getRelease char value");
 388         }
 389 
 390         // Opaque
 391         {
 392             char x = (char) vh.getOpaque();
 393             assertEquals(x, '\u0123', "getOpaque char value");
 394         }
 395     }
 396 
 397     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 398         checkUOE(() -> {
 399             vh.set('\u4567');
 400         });
 401 
 402         checkUOE(() -> {
 403             vh.setVolatile('\u4567');
 404         });
 405 
 406         checkUOE(() -> {
 407             vh.setRelease('\u4567');
 408         });
 409 
 410         checkUOE(() -> {
 411             vh.setOpaque('\u4567');
 412         });
 413 
 414 
 415 
 416     }
 417 
 418 
 419     static void testInstanceField(VarHandleTestAccessChar recv, VarHandle vh) {
 420         // Plain
 421         {
 422             vh.set(recv, '\u0123');
 423             char x = (char) vh.get(recv);
 424             assertEquals(x, '\u0123', "set char value");
 425         }
 426 
 427 
 428         // Volatile
 429         {
 430             vh.setVolatile(recv, '\u4567');
 431             char x = (char) vh.getVolatile(recv);
 432             assertEquals(x, '\u4567', "setVolatile char value");
 433         }
 434 
 435         // Lazy
 436         {
 437             vh.setRelease(recv, '\u0123');
 438             char x = (char) vh.getAcquire(recv);
 439             assertEquals(x, '\u0123', "setRelease char value");
 440         }
 441 
 442         // Opaque
 443         {
 444             vh.setOpaque(recv, '\u4567');
 445             char x = (char) vh.getOpaque(recv);
 446             assertEquals(x, '\u4567', "setOpaque char value");
 447         }
 448 
 449         vh.set(recv, '\u0123');
 450 
 451         // Compare
 452         {
 453             boolean r = vh.compareAndSet(recv, '\u0123', '\u4567');
 454             assertEquals(r, true, "success compareAndSet char");
 455             char x = (char) vh.get(recv);
 456             assertEquals(x, '\u4567', "success compareAndSet char value");
 457         }
 458 
 459         {
 460             boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB');
 461             assertEquals(r, false, "failing compareAndSet char");
 462             char x = (char) vh.get(recv);
 463             assertEquals(x, '\u4567', "failing compareAndSet char value");
 464         }
 465 
 466         {
 467             char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123');
 468             assertEquals(r, '\u4567', "success compareAndExchange char");
 469             char x = (char) vh.get(recv);
 470             assertEquals(x, '\u0123', "success compareAndExchange char value");
 471         }
 472 
 473         {
 474             char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB');
 475             assertEquals(r, '\u0123', "failing compareAndExchange char");
 476             char x = (char) vh.get(recv);
 477             assertEquals(x, '\u0123', "failing compareAndExchange char value");
 478         }
 479 
 480         {
 481             char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567');
 482             assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
 483             char x = (char) vh.get(recv);
 484             assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
 485         }
 486 
 487         {
 488             char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB');
 489             assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
 490             char x = (char) vh.get(recv);
 491             assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
 492         }
 493 
 494         {
 495             char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123');
 496             assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
 497             char x = (char) vh.get(recv);
 498             assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
 499         }
 500 
 501         {
 502             char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB');
 503             assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
 504             char x = (char) vh.get(recv);
 505             assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
 506         }
 507 
 508         {
 509             boolean success = false;
 510             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 511                 success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u4567');
 512             }
 513             assertEquals(success, true, "weakCompareAndSetPlain char");
 514             char x = (char) vh.get(recv);
 515             assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
 516         }
 517 
 518         {
 519             boolean success = false;
 520             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 521                 success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u0123');
 522             }
 523             assertEquals(success, true, "weakCompareAndSetAcquire char");
 524             char x = (char) vh.get(recv);
 525             assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
 526         }
 527 
 528         {
 529             boolean success = false;
 530             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 531                 success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u4567');
 532             }
 533             assertEquals(success, true, "weakCompareAndSetRelease char");
 534             char x = (char) vh.get(recv);
 535             assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
 536         }
 537 
 538         {
 539             boolean success = false;
 540             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 541                 success = vh.weakCompareAndSet(recv, '\u4567', '\u0123');
 542             }
 543             assertEquals(success, true, "weakCompareAndSet char");
 544             char x = (char) vh.get(recv);
 545             assertEquals(x, '\u0123', "weakCompareAndSet char value");
 546         }
 547 
 548         // Compare set and get
 549         {
 550             vh.set(recv, '\u0123');
 551 
 552             char o = (char) vh.getAndSet(recv, '\u4567');
 553             assertEquals(o, '\u0123', "getAndSet char");
 554             char x = (char) vh.get(recv);
 555             assertEquals(x, '\u4567', "getAndSet char value");
 556         }
 557 
 558         {
 559             vh.set(recv, '\u0123');
 560 
 561             char o = (char) vh.getAndSetAcquire(recv, '\u4567');
 562             assertEquals(o, '\u0123', "getAndSetAcquire char");
 563             char x = (char) vh.get(recv);
 564             assertEquals(x, '\u4567', "getAndSetAcquire char value");
 565         }
 566 
 567         {
 568             vh.set(recv, '\u0123');
 569 
 570             char o = (char) vh.getAndSetRelease(recv, '\u4567');
 571             assertEquals(o, '\u0123', "getAndSetRelease char");
 572             char x = (char) vh.get(recv);
 573             assertEquals(x, '\u4567', "getAndSetRelease char value");
 574         }
 575 
 576         // get and add, add and get
 577         {
 578             vh.set(recv, '\u0123');
 579 
 580             char o = (char) vh.getAndAdd(recv, '\u4567');
 581             assertEquals(o, '\u0123', "getAndAdd char");
 582             char x = (char) vh.get(recv);
 583             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
 584         }
 585 
 586         {
 587             vh.set(recv, '\u0123');
 588 
 589             char o = (char) vh.getAndAddAcquire(recv, '\u4567');
 590             assertEquals(o, '\u0123', "getAndAddAcquire char");
 591             char x = (char) vh.get(recv);
 592             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
 593         }
 594 
 595         {
 596             vh.set(recv, '\u0123');
 597 
 598             char o = (char) vh.getAndAddRelease(recv, '\u4567');
 599             assertEquals(o, '\u0123', "getAndAddReleasechar");
 600             char x = (char) vh.get(recv);
 601             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
 602         }
 603 
 604         // get and bitwise or
 605         {
 606             vh.set(recv, '\u0123');
 607 
 608             char o = (char) vh.getAndBitwiseOr(recv, '\u4567');
 609             assertEquals(o, '\u0123', "getAndBitwiseOr char");
 610             char x = (char) vh.get(recv);
 611             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
 612         }
 613 
 614         {
 615             vh.set(recv, '\u0123');
 616 
 617             char o = (char) vh.getAndBitwiseOrAcquire(recv, '\u4567');
 618             assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
 619             char x = (char) vh.get(recv);
 620             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
 621         }
 622 
 623         {
 624             vh.set(recv, '\u0123');
 625 
 626             char o = (char) vh.getAndBitwiseOrRelease(recv, '\u4567');
 627             assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
 628             char x = (char) vh.get(recv);
 629             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
 630         }
 631 
 632         // get and bitwise and
 633         {
 634             vh.set(recv, '\u0123');
 635 
 636             char o = (char) vh.getAndBitwiseAnd(recv, '\u4567');
 637             assertEquals(o, '\u0123', "getAndBitwiseAnd char");
 638             char x = (char) vh.get(recv);
 639             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
 640         }
 641 
 642         {
 643             vh.set(recv, '\u0123');
 644 
 645             char o = (char) vh.getAndBitwiseAndAcquire(recv, '\u4567');
 646             assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
 647             char x = (char) vh.get(recv);
 648             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
 649         }
 650 
 651         {
 652             vh.set(recv, '\u0123');
 653 
 654             char o = (char) vh.getAndBitwiseAndRelease(recv, '\u4567');
 655             assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
 656             char x = (char) vh.get(recv);
 657             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
 658         }
 659 
 660         // get and bitwise xor
 661         {
 662             vh.set(recv, '\u0123');
 663 
 664             char o = (char) vh.getAndBitwiseXor(recv, '\u4567');
 665             assertEquals(o, '\u0123', "getAndBitwiseXor char");
 666             char x = (char) vh.get(recv);
 667             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
 668         }
 669 
 670         {
 671             vh.set(recv, '\u0123');
 672 
 673             char o = (char) vh.getAndBitwiseXorAcquire(recv, '\u4567');
 674             assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
 675             char x = (char) vh.get(recv);
 676             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
 677         }
 678 
 679         {
 680             vh.set(recv, '\u0123');
 681 
 682             char o = (char) vh.getAndBitwiseXorRelease(recv, '\u4567');
 683             assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
 684             char x = (char) vh.get(recv);
 685             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
 686         }
 687     }
 688 
 689     static void testInstanceFieldUnsupported(VarHandleTestAccessChar recv, VarHandle vh) {
 690 
 691 
 692     }
 693 
 694 
 695     static void testStaticField(VarHandle vh) {
 696         // Plain
 697         {
 698             vh.set('\u0123');
 699             char x = (char) vh.get();
 700             assertEquals(x, '\u0123', "set char value");
 701         }
 702 
 703 
 704         // Volatile
 705         {
 706             vh.setVolatile('\u4567');
 707             char x = (char) vh.getVolatile();
 708             assertEquals(x, '\u4567', "setVolatile char value");
 709         }
 710 
 711         // Lazy
 712         {
 713             vh.setRelease('\u0123');
 714             char x = (char) vh.getAcquire();
 715             assertEquals(x, '\u0123', "setRelease char value");
 716         }
 717 
 718         // Opaque
 719         {
 720             vh.setOpaque('\u4567');
 721             char x = (char) vh.getOpaque();
 722             assertEquals(x, '\u4567', "setOpaque char value");
 723         }
 724 
 725         vh.set('\u0123');
 726 
 727         // Compare
 728         {
 729             boolean r = vh.compareAndSet('\u0123', '\u4567');
 730             assertEquals(r, true, "success compareAndSet char");
 731             char x = (char) vh.get();
 732             assertEquals(x, '\u4567', "success compareAndSet char value");
 733         }
 734 
 735         {
 736             boolean r = vh.compareAndSet('\u0123', '\u89AB');
 737             assertEquals(r, false, "failing compareAndSet char");
 738             char x = (char) vh.get();
 739             assertEquals(x, '\u4567', "failing compareAndSet char value");
 740         }
 741 
 742         {
 743             char r = (char) vh.compareAndExchange('\u4567', '\u0123');
 744             assertEquals(r, '\u4567', "success compareAndExchange char");
 745             char x = (char) vh.get();
 746             assertEquals(x, '\u0123', "success compareAndExchange char value");
 747         }
 748 
 749         {
 750             char r = (char) vh.compareAndExchange('\u4567', '\u89AB');
 751             assertEquals(r, '\u0123', "failing compareAndExchange char");
 752             char x = (char) vh.get();
 753             assertEquals(x, '\u0123', "failing compareAndExchange char value");
 754         }
 755 
 756         {
 757             char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567');
 758             assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
 759             char x = (char) vh.get();
 760             assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
 761         }
 762 
 763         {
 764             char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB');
 765             assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
 766             char x = (char) vh.get();
 767             assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
 768         }
 769 
 770         {
 771             char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123');
 772             assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
 773             char x = (char) vh.get();
 774             assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
 775         }
 776 
 777         {
 778             char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB');
 779             assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
 780             char x = (char) vh.get();
 781             assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
 782         }
 783 
 784         {
 785             boolean success = false;
 786             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 787                 success = vh.weakCompareAndSetPlain('\u0123', '\u4567');
 788             }
 789             assertEquals(success, true, "weakCompareAndSetPlain char");
 790             char x = (char) vh.get();
 791             assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
 792         }
 793 
 794         {
 795             boolean success = false;
 796             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 797                 success = vh.weakCompareAndSetAcquire('\u4567', '\u0123');
 798             }
 799             assertEquals(success, true, "weakCompareAndSetAcquire char");
 800             char x = (char) vh.get();
 801             assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
 802         }
 803 
 804         {
 805             boolean success = false;
 806             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 807                 success = vh.weakCompareAndSetRelease('\u0123', '\u4567');
 808             }
 809             assertEquals(success, true, "weakCompareAndSetRelease char");
 810             char x = (char) vh.get();
 811             assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
 812         }
 813 
 814         {
 815             boolean success = false;
 816             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 817                 success = vh.weakCompareAndSet('\u4567', '\u0123');
 818             }
 819             assertEquals(success, true, "weakCompareAndSet char");
 820             char x = (char) vh.get();
 821             assertEquals(x, '\u0123', "weakCompareAndSet char");
 822         }
 823 
 824         // Compare set and get
 825         {
 826             vh.set('\u0123');
 827 
 828             char o = (char) vh.getAndSet('\u4567');
 829             assertEquals(o, '\u0123', "getAndSet char");
 830             char x = (char) vh.get();
 831             assertEquals(x, '\u4567', "getAndSet char value");
 832         }
 833 
 834         {
 835             vh.set('\u0123');
 836 
 837             char o = (char) vh.getAndSetAcquire('\u4567');
 838             assertEquals(o, '\u0123', "getAndSetAcquire char");
 839             char x = (char) vh.get();
 840             assertEquals(x, '\u4567', "getAndSetAcquire char value");
 841         }
 842 
 843         {
 844             vh.set('\u0123');
 845 
 846             char o = (char) vh.getAndSetRelease('\u4567');
 847             assertEquals(o, '\u0123', "getAndSetRelease char");
 848             char x = (char) vh.get();
 849             assertEquals(x, '\u4567', "getAndSetRelease char value");
 850         }
 851 
 852         // get and add, add and get
 853         {
 854             vh.set('\u0123');
 855 
 856             char o = (char) vh.getAndAdd('\u4567');
 857             assertEquals(o, '\u0123', "getAndAdd char");
 858             char x = (char) vh.get();
 859             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
 860         }
 861 
 862         {
 863             vh.set('\u0123');
 864 
 865             char o = (char) vh.getAndAddAcquire('\u4567');
 866             assertEquals(o, '\u0123', "getAndAddAcquire char");
 867             char x = (char) vh.get();
 868             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
 869         }
 870 
 871         {
 872             vh.set('\u0123');
 873 
 874             char o = (char) vh.getAndAddRelease('\u4567');
 875             assertEquals(o, '\u0123', "getAndAddReleasechar");
 876             char x = (char) vh.get();
 877             assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
 878         }
 879 
 880         // get and bitwise or
 881         {
 882             vh.set('\u0123');
 883 
 884             char o = (char) vh.getAndBitwiseOr('\u4567');
 885             assertEquals(o, '\u0123', "getAndBitwiseOr char");
 886             char x = (char) vh.get();
 887             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
 888         }
 889 
 890         {
 891             vh.set('\u0123');
 892 
 893             char o = (char) vh.getAndBitwiseOrAcquire('\u4567');
 894             assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
 895             char x = (char) vh.get();
 896             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
 897         }
 898 
 899         {
 900             vh.set('\u0123');
 901 
 902             char o = (char) vh.getAndBitwiseOrRelease('\u4567');
 903             assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
 904             char x = (char) vh.get();
 905             assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
 906         }
 907 
 908         // get and bitwise and
 909         {
 910             vh.set('\u0123');
 911 
 912             char o = (char) vh.getAndBitwiseAnd('\u4567');
 913             assertEquals(o, '\u0123', "getAndBitwiseAnd char");
 914             char x = (char) vh.get();
 915             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
 916         }
 917 
 918         {
 919             vh.set('\u0123');
 920 
 921             char o = (char) vh.getAndBitwiseAndAcquire('\u4567');
 922             assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
 923             char x = (char) vh.get();
 924             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
 925         }
 926 
 927         {
 928             vh.set('\u0123');
 929 
 930             char o = (char) vh.getAndBitwiseAndRelease('\u4567');
 931             assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
 932             char x = (char) vh.get();
 933             assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
 934         }
 935 
 936         // get and bitwise xor
 937         {
 938             vh.set('\u0123');
 939 
 940             char o = (char) vh.getAndBitwiseXor('\u4567');
 941             assertEquals(o, '\u0123', "getAndBitwiseXor char");
 942             char x = (char) vh.get();
 943             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
 944         }
 945 
 946         {
 947             vh.set('\u0123');
 948 
 949             char o = (char) vh.getAndBitwiseXorAcquire('\u4567');
 950             assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
 951             char x = (char) vh.get();
 952             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
 953         }
 954 
 955         {
 956             vh.set('\u0123');
 957 
 958             char o = (char) vh.getAndBitwiseXorRelease('\u4567');
 959             assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
 960             char x = (char) vh.get();
 961             assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
 962         }
 963     }
 964 
 965     static void testStaticFieldUnsupported(VarHandle vh) {
 966 
 967 
 968     }
 969 
 970 
 971     static void testArray(VarHandle vh) {
 972         char[] array = new char[10];
 973 
 974         for (int i = 0; i < array.length; i++) {
 975             // Plain
 976             {
 977                 vh.set(array, i, '\u0123');
 978                 char x = (char) vh.get(array, i);
 979                 assertEquals(x, '\u0123', "get char value");
 980             }
 981 
 982 
 983             // Volatile
 984             {
 985                 vh.setVolatile(array, i, '\u4567');
 986                 char x = (char) vh.getVolatile(array, i);
 987                 assertEquals(x, '\u4567', "setVolatile char value");
 988             }
 989 
 990             // Lazy
 991             {
 992                 vh.setRelease(array, i, '\u0123');
 993                 char x = (char) vh.getAcquire(array, i);
 994                 assertEquals(x, '\u0123', "setRelease char value");
 995             }
 996 
 997             // Opaque
 998             {
 999                 vh.setOpaque(array, i, '\u4567');
1000                 char x = (char) vh.getOpaque(array, i);
1001                 assertEquals(x, '\u4567', "setOpaque char value");
1002             }
1003 
1004             vh.set(array, i, '\u0123');
1005 
1006             // Compare
1007             {
1008                 boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567');
1009                 assertEquals(r, true, "success compareAndSet char");
1010                 char x = (char) vh.get(array, i);
1011                 assertEquals(x, '\u4567', "success compareAndSet char value");
1012             }
1013 
1014             {
1015                 boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB');
1016                 assertEquals(r, false, "failing compareAndSet char");
1017                 char x = (char) vh.get(array, i);
1018                 assertEquals(x, '\u4567', "failing compareAndSet char value");
1019             }
1020 
1021             {
1022                 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123');
1023                 assertEquals(r, '\u4567', "success compareAndExchange char");
1024                 char x = (char) vh.get(array, i);
1025                 assertEquals(x, '\u0123', "success compareAndExchange char value");
1026             }
1027 
1028             {
1029                 char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB');
1030                 assertEquals(r, '\u0123', "failing compareAndExchange char");
1031                 char x = (char) vh.get(array, i);
1032                 assertEquals(x, '\u0123', "failing compareAndExchange char value");
1033             }
1034 
1035             {
1036                 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567');
1037                 assertEquals(r, '\u0123', "success compareAndExchangeAcquire char");
1038                 char x = (char) vh.get(array, i);
1039                 assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value");
1040             }
1041 
1042             {
1043                 char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB');
1044                 assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char");
1045                 char x = (char) vh.get(array, i);
1046                 assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value");
1047             }
1048 
1049             {
1050                 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123');
1051                 assertEquals(r, '\u4567', "success compareAndExchangeRelease char");
1052                 char x = (char) vh.get(array, i);
1053                 assertEquals(x, '\u0123', "success compareAndExchangeRelease char value");
1054             }
1055 
1056             {
1057                 char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB');
1058                 assertEquals(r, '\u0123', "failing compareAndExchangeRelease char");
1059                 char x = (char) vh.get(array, i);
1060                 assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value");
1061             }
1062 
1063             {
1064                 boolean success = false;
1065                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1066                     success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u4567');
1067                 }
1068                 assertEquals(success, true, "weakCompareAndSetPlain char");
1069                 char x = (char) vh.get(array, i);
1070                 assertEquals(x, '\u4567', "weakCompareAndSetPlain char value");
1071             }
1072 
1073             {
1074                 boolean success = false;
1075                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1076                     success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u0123');
1077                 }
1078                 assertEquals(success, true, "weakCompareAndSetAcquire char");
1079                 char x = (char) vh.get(array, i);
1080                 assertEquals(x, '\u0123', "weakCompareAndSetAcquire char");
1081             }
1082 
1083             {
1084                 boolean success = false;
1085                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1086                     success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u4567');
1087                 }
1088                 assertEquals(success, true, "weakCompareAndSetRelease char");
1089                 char x = (char) vh.get(array, i);
1090                 assertEquals(x, '\u4567', "weakCompareAndSetRelease char");
1091             }
1092 
1093             {
1094                 boolean success = false;
1095                 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
1096                     success = vh.weakCompareAndSet(array, i, '\u4567', '\u0123');
1097                 }
1098                 assertEquals(success, true, "weakCompareAndSet char");
1099                 char x = (char) vh.get(array, i);
1100                 assertEquals(x, '\u0123', "weakCompareAndSet char");
1101             }
1102 
1103             // Compare set and get
1104             {
1105                 vh.set(array, i, '\u0123');
1106 
1107                 char o = (char) vh.getAndSet(array, i, '\u4567');
1108                 assertEquals(o, '\u0123', "getAndSet char");
1109                 char x = (char) vh.get(array, i);
1110                 assertEquals(x, '\u4567', "getAndSet char value");
1111             }
1112 
1113             {
1114                 vh.set(array, i, '\u0123');
1115 
1116                 char o = (char) vh.getAndSetAcquire(array, i, '\u4567');
1117                 assertEquals(o, '\u0123', "getAndSetAcquire char");
1118                 char x = (char) vh.get(array, i);
1119                 assertEquals(x, '\u4567', "getAndSetAcquire char value");
1120             }
1121 
1122             {
1123                 vh.set(array, i, '\u0123');
1124 
1125                 char o = (char) vh.getAndSetRelease(array, i, '\u4567');
1126                 assertEquals(o, '\u0123', "getAndSetRelease char");
1127                 char x = (char) vh.get(array, i);
1128                 assertEquals(x, '\u4567', "getAndSetRelease char value");
1129             }
1130 
1131             // get and add, add and get
1132             {
1133                 vh.set(array, i, '\u0123');
1134 
1135                 char o = (char) vh.getAndAdd(array, i, '\u4567');
1136                 assertEquals(o, '\u0123', "getAndAdd char");
1137                 char x = (char) vh.get(array, i);
1138                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value");
1139             }
1140 
1141             {
1142                 vh.set(array, i, '\u0123');
1143 
1144                 char o = (char) vh.getAndAddAcquire(array, i, '\u4567');
1145                 assertEquals(o, '\u0123', "getAndAddAcquire char");
1146                 char x = (char) vh.get(array, i);
1147                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value");
1148             }
1149 
1150             {
1151                 vh.set(array, i, '\u0123');
1152 
1153                 char o = (char) vh.getAndAddRelease(array, i, '\u4567');
1154                 assertEquals(o, '\u0123', "getAndAddReleasechar");
1155                 char x = (char) vh.get(array, i);
1156                 assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value");
1157             }
1158 
1159             // get and bitwise or
1160             {
1161                 vh.set(array, i, '\u0123');
1162 
1163                 char o = (char) vh.getAndBitwiseOr(array, i, '\u4567');
1164                 assertEquals(o, '\u0123', "getAndBitwiseOr char");
1165                 char x = (char) vh.get(array, i);
1166                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value");
1167             }
1168 
1169             {
1170                 vh.set(array, i, '\u0123');
1171 
1172                 char o = (char) vh.getAndBitwiseOrAcquire(array, i, '\u4567');
1173                 assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char");
1174                 char x = (char) vh.get(array, i);
1175                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value");
1176             }
1177 
1178             {
1179                 vh.set(array, i, '\u0123');
1180 
1181                 char o = (char) vh.getAndBitwiseOrRelease(array, i, '\u4567');
1182                 assertEquals(o, '\u0123', "getAndBitwiseOrRelease char");
1183                 char x = (char) vh.get(array, i);
1184                 assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value");
1185             }
1186 
1187             // get and bitwise and
1188             {
1189                 vh.set(array, i, '\u0123');
1190 
1191                 char o = (char) vh.getAndBitwiseAnd(array, i, '\u4567');
1192                 assertEquals(o, '\u0123', "getAndBitwiseAnd char");
1193                 char x = (char) vh.get(array, i);
1194                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value");
1195             }
1196 
1197             {
1198                 vh.set(array, i, '\u0123');
1199 
1200                 char o = (char) vh.getAndBitwiseAndAcquire(array, i, '\u4567');
1201                 assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char");
1202                 char x = (char) vh.get(array, i);
1203                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value");
1204             }
1205 
1206             {
1207                 vh.set(array, i, '\u0123');
1208 
1209                 char o = (char) vh.getAndBitwiseAndRelease(array, i, '\u4567');
1210                 assertEquals(o, '\u0123', "getAndBitwiseAndRelease char");
1211                 char x = (char) vh.get(array, i);
1212                 assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value");
1213             }
1214 
1215             // get and bitwise xor
1216             {
1217                 vh.set(array, i, '\u0123');
1218 
1219                 char o = (char) vh.getAndBitwiseXor(array, i, '\u4567');
1220                 assertEquals(o, '\u0123', "getAndBitwiseXor char");
1221                 char x = (char) vh.get(array, i);
1222                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value");
1223             }
1224 
1225             {
1226                 vh.set(array, i, '\u0123');
1227 
1228                 char o = (char) vh.getAndBitwiseXorAcquire(array, i, '\u4567');
1229                 assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char");
1230                 char x = (char) vh.get(array, i);
1231                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value");
1232             }
1233 
1234             {
1235                 vh.set(array, i, '\u0123');
1236 
1237                 char o = (char) vh.getAndBitwiseXorRelease(array, i, '\u4567');
1238                 assertEquals(o, '\u0123', "getAndBitwiseXorRelease char");
1239                 char x = (char) vh.get(array, i);
1240                 assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value");
1241             }
1242         }
1243     }
1244 
1245     static void testArrayUnsupported(VarHandle vh) {
1246         char[] array = new char[10];
1247 
1248         int i = 0;
1249 
1250 
1251     }
1252 
1253     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1254         char[] array = new char[10];
1255 
1256         for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
1257             final int ci = i;
1258 
1259             checkAIOOBE(() -> {
1260                 char x = (char) vh.get(array, ci);
1261             });
1262 
1263             checkAIOOBE(() -> {
1264                 vh.set(array, ci, '\u0123');
1265             });
1266 
1267             checkAIOOBE(() -> {
1268                 char x = (char) vh.getVolatile(array, ci);
1269             });
1270 
1271             checkAIOOBE(() -> {
1272                 vh.setVolatile(array, ci, '\u0123');
1273             });
1274 
1275             checkAIOOBE(() -> {
1276                 char x = (char) vh.getAcquire(array, ci);
1277             });
1278 
1279             checkAIOOBE(() -> {
1280                 vh.setRelease(array, ci, '\u0123');
1281             });
1282 
1283             checkAIOOBE(() -> {
1284                 char x = (char) vh.getOpaque(array, ci);
1285             });
1286 
1287             checkAIOOBE(() -> {
1288                 vh.setOpaque(array, ci, '\u0123');
1289             });
1290 
1291             checkAIOOBE(() -> {
1292                 boolean r = vh.compareAndSet(array, ci, '\u0123', '\u4567');
1293             });
1294 
1295             checkAIOOBE(() -> {
1296                 char r = (char) vh.compareAndExchange(array, ci, '\u4567', '\u0123');
1297             });
1298 
1299             checkAIOOBE(() -> {
1300                 char r = (char) vh.compareAndExchangeAcquire(array, ci, '\u4567', '\u0123');
1301             });
1302 
1303             checkAIOOBE(() -> {
1304                 char r = (char) vh.compareAndExchangeRelease(array, ci, '\u4567', '\u0123');
1305             });
1306 
1307             checkAIOOBE(() -> {
1308                 boolean r = vh.weakCompareAndSetPlain(array, ci, '\u0123', '\u4567');
1309             });
1310 
1311             checkAIOOBE(() -> {
1312                 boolean r = vh.weakCompareAndSet(array, ci, '\u0123', '\u4567');
1313             });
1314 
1315             checkAIOOBE(() -> {
1316                 boolean r = vh.weakCompareAndSetAcquire(array, ci, '\u0123', '\u4567');
1317             });
1318 
1319             checkAIOOBE(() -> {
1320                 boolean r = vh.weakCompareAndSetRelease(array, ci, '\u0123', '\u4567');
1321             });
1322 
1323             checkAIOOBE(() -> {
1324                 char o = (char) vh.getAndSet(array, ci, '\u0123');
1325             });
1326 
1327             checkAIOOBE(() -> {
1328                 char o = (char) vh.getAndSetAcquire(array, ci, '\u0123');
1329             });
1330 
1331             checkAIOOBE(() -> {
1332                 char o = (char) vh.getAndSetRelease(array, ci, '\u0123');
1333             });
1334 
1335             checkAIOOBE(() -> {
1336                 char o = (char) vh.getAndAdd(array, ci, '\u0123');
1337             });
1338 
1339             checkAIOOBE(() -> {
1340                 char o = (char) vh.getAndAddAcquire(array, ci, '\u0123');
1341             });
1342 
1343             checkAIOOBE(() -> {
1344                 char o = (char) vh.getAndAddRelease(array, ci, '\u0123');
1345             });
1346 
1347             checkAIOOBE(() -> {
1348                 char o = (char) vh.getAndBitwiseOr(array, ci, '\u0123');
1349             });
1350 
1351             checkAIOOBE(() -> {
1352                 char o = (char) vh.getAndBitwiseOrAcquire(array, ci, '\u0123');
1353             });
1354 
1355             checkAIOOBE(() -> {
1356                 char o = (char) vh.getAndBitwiseOrRelease(array, ci, '\u0123');
1357             });
1358 
1359             checkAIOOBE(() -> {
1360                 char o = (char) vh.getAndBitwiseAnd(array, ci, '\u0123');
1361             });
1362 
1363             checkAIOOBE(() -> {
1364                 char o = (char) vh.getAndBitwiseAndAcquire(array, ci, '\u0123');
1365             });
1366 
1367             checkAIOOBE(() -> {
1368                 char o = (char) vh.getAndBitwiseAndRelease(array, ci, '\u0123');
1369             });
1370 
1371             checkAIOOBE(() -> {
1372                 char o = (char) vh.getAndBitwiseXor(array, ci, '\u0123');
1373             });
1374 
1375             checkAIOOBE(() -> {
1376                 char o = (char) vh.getAndBitwiseXorAcquire(array, ci, '\u0123');
1377             });
1378 
1379             checkAIOOBE(() -> {
1380                 char o = (char) vh.getAndBitwiseXorRelease(array, ci, '\u0123');
1381             });
1382         }
1383     }
1384 
1385 }
1386