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