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