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