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                                                   VarHandleTestAccessFloat
  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 VarHandleTestAccessFloat
  32  * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1                         VarHandleTestAccessFloat
  33  * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation  VarHandleTestAccessFloat
  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 VarHandleTestAccessFloat extends VarHandleBaseTest {
  49     static final float static_final_v = 1.0f;
  50 
  51     static float static_v;
  52 
  53     final float final_v = 1.0f;
  54 
  55     float v;
  56 
  57     static final float static_final_v2 = 1.0f;
  58 
  59     static float static_v2;
  60 
  61     final float final_v2 = 1.0f;
  62 
  63     float 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                     VarHandleTestAccessFloat.class, "final_v" + postfix, float.class);
  84             vhs.add(vh);
  85 
  86             vh = MethodHandles.lookup().findVarHandle(
  87                     VarHandleTestAccessFloat.class, "v" + postfix, float.class);
  88             vhs.add(vh);
  89 
  90             vh = MethodHandles.lookup().findStaticVarHandle(
  91                 VarHandleTestAccessFloat.class, "static_final_v" + postfix, float.class);
  92             vhs.add(vh);
  93 
  94             vh = MethodHandles.lookup().findStaticVarHandle(
  95                 VarHandleTestAccessFloat.class, "static_v" + postfix, float.class);
  96             vhs.add(vh);
  97 
  98             if (same) {
  99                 vh = MethodHandles.arrayElementVarHandle(float[].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                 VarHandleTestAccessFloat.class, "final_v", float.class);
 115 
 116         vhField = MethodHandles.lookup().findVarHandle(
 117                 VarHandleTestAccessFloat.class, "v", float.class);
 118 
 119         vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
 120             VarHandleTestAccessFloat.class, "static_final_v", float.class);
 121 
 122         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
 123             VarHandleTestAccessFloat.class, "static_v", float.class);
 124 
 125         vhArray = MethodHandles.arrayElementVarHandle(float[].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(VarHandleTestAccessFloat.class)});
 202         types.add(new Object[] {vhStaticField, Arrays.asList()});
 203         types.add(new Object[] {vhArray, Arrays.asList(float[].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(), float.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                     VarHandleTestAccessFloat.class, "final_v", float.class);
 223         });
 224 
 225         checkIAE("Lookup of static field to instance field", () -> {
 226             MethodHandles.lookup().findStaticVarHandle(
 227                     VarHandleTestAccessFloat.class, "v", float.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                 VarHandleTestAccessFloat.class, "static_final_v", float.class);
 236         });
 237 
 238         checkIAE("Lookup of instance field to static field", () -> {
 239             vhStaticField = MethodHandles.lookup().findVarHandle(
 240                 VarHandleTestAccessFloat.class, "static_v", float.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, VarHandleTestAccessFloat::testStaticFinalField));
 257         cases.add(new VarHandleAccessTestCase("Static final field unsupported",
 258                                               vhStaticFinalField, VarHandleTestAccessFloat::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, VarHandleTestAccessFloat::testStaticField));
 269         cases.add(new VarHandleAccessTestCase("Static field unsupported",
 270                                               vhStaticField, VarHandleTestAccessFloat::testStaticFieldUnsupported,
 271                                               false));
 272 
 273         cases.add(new VarHandleAccessTestCase("Array",
 274                                               vhArray, VarHandleTestAccessFloat::testArray));
 275         cases.add(new VarHandleAccessTestCase("Array unsupported",
 276                                               vhArray, VarHandleTestAccessFloat::testArrayUnsupported,
 277                                               false));
 278         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
 279                                               vhArray, VarHandleTestAccessFloat::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(VarHandleTestAccessFloat recv, VarHandle vh) {
 297         // Plain
 298         {
 299             float x = (float) vh.get(recv);
 300             assertEquals(x, 1.0f, "get float value");
 301         }
 302 
 303 
 304         // Volatile
 305         {
 306             float x = (float) vh.getVolatile(recv);
 307             assertEquals(x, 1.0f, "getVolatile float value");
 308         }
 309 
 310         // Lazy
 311         {
 312             float x = (float) vh.getAcquire(recv);
 313             assertEquals(x, 1.0f, "getRelease float value");
 314         }
 315 
 316         // Opaque
 317         {
 318             float x = (float) vh.getOpaque(recv);
 319             assertEquals(x, 1.0f, "getOpaque float value");
 320         }
 321     }
 322 
 323     static void testInstanceFinalFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
 324         checkUOE(() -> {
 325             vh.set(recv, 2.0f);
 326         });
 327 
 328         checkUOE(() -> {
 329             vh.setVolatile(recv, 2.0f);
 330         });
 331 
 332         checkUOE(() -> {
 333             vh.setRelease(recv, 2.0f);
 334         });
 335 
 336         checkUOE(() -> {
 337             vh.setOpaque(recv, 2.0f);
 338         });
 339 
 340 
 341 
 342         checkUOE(() -> {
 343             float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
 344         });
 345 
 346         checkUOE(() -> {
 347             float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
 348         });
 349 
 350         checkUOE(() -> {
 351             float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
 352         });
 353 
 354         checkUOE(() -> {
 355             float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
 356         });
 357 
 358         checkUOE(() -> {
 359             float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
 360         });
 361 
 362         checkUOE(() -> {
 363             float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
 364         });
 365 
 366         checkUOE(() -> {
 367             float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
 368         });
 369 
 370         checkUOE(() -> {
 371             float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
 372         });
 373 
 374         checkUOE(() -> {
 375             float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
 376         });
 377     }
 378 
 379 
 380     static void testStaticFinalField(VarHandle vh) {
 381         // Plain
 382         {
 383             float x = (float) vh.get();
 384             assertEquals(x, 1.0f, "get float value");
 385         }
 386 
 387 
 388         // Volatile
 389         {
 390             float x = (float) vh.getVolatile();
 391             assertEquals(x, 1.0f, "getVolatile float value");
 392         }
 393 
 394         // Lazy
 395         {
 396             float x = (float) vh.getAcquire();
 397             assertEquals(x, 1.0f, "getRelease float value");
 398         }
 399 
 400         // Opaque
 401         {
 402             float x = (float) vh.getOpaque();
 403             assertEquals(x, 1.0f, "getOpaque float value");
 404         }
 405     }
 406 
 407     static void testStaticFinalFieldUnsupported(VarHandle vh) {
 408         checkUOE(() -> {
 409             vh.set(2.0f);
 410         });
 411 
 412         checkUOE(() -> {
 413             vh.setVolatile(2.0f);
 414         });
 415 
 416         checkUOE(() -> {
 417             vh.setRelease(2.0f);
 418         });
 419 
 420         checkUOE(() -> {
 421             vh.setOpaque(2.0f);
 422         });
 423 
 424 
 425 
 426         checkUOE(() -> {
 427             float o = (float) vh.getAndBitwiseOr(1.0f);
 428         });
 429 
 430         checkUOE(() -> {
 431             float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
 432         });
 433 
 434         checkUOE(() -> {
 435             float o = (float) vh.getAndBitwiseOrRelease(1.0f);
 436         });
 437 
 438         checkUOE(() -> {
 439             float o = (float) vh.getAndBitwiseAnd(1.0f);
 440         });
 441 
 442         checkUOE(() -> {
 443             float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
 444         });
 445 
 446         checkUOE(() -> {
 447             float o = (float) vh.getAndBitwiseAndRelease(1.0f);
 448         });
 449 
 450         checkUOE(() -> {
 451             float o = (float) vh.getAndBitwiseXor(1.0f);
 452         });
 453 
 454         checkUOE(() -> {
 455             float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
 456         });
 457 
 458         checkUOE(() -> {
 459             float o = (float) vh.getAndBitwiseXorRelease(1.0f);
 460         });
 461     }
 462 
 463 
 464     static void testInstanceField(VarHandleTestAccessFloat recv, VarHandle vh) {
 465         // Plain
 466         {
 467             vh.set(recv, 1.0f);
 468             float x = (float) vh.get(recv);
 469             assertEquals(x, 1.0f, "set float value");
 470         }
 471 
 472 
 473         // Volatile
 474         {
 475             vh.setVolatile(recv, 2.0f);
 476             float x = (float) vh.getVolatile(recv);
 477             assertEquals(x, 2.0f, "setVolatile float value");
 478         }
 479 
 480         // Lazy
 481         {
 482             vh.setRelease(recv, 1.0f);
 483             float x = (float) vh.getAcquire(recv);
 484             assertEquals(x, 1.0f, "setRelease float value");
 485         }
 486 
 487         // Opaque
 488         {
 489             vh.setOpaque(recv, 2.0f);
 490             float x = (float) vh.getOpaque(recv);
 491             assertEquals(x, 2.0f, "setOpaque float value");
 492         }
 493 
 494         vh.set(recv, 1.0f);
 495 
 496         // Compare
 497         {
 498             boolean r = vh.compareAndSet(recv, 1.0f, 2.0f);
 499             assertEquals(r, true, "success compareAndSet float");
 500             float x = (float) vh.get(recv);
 501             assertEquals(x, 2.0f, "success compareAndSet float value");
 502         }
 503 
 504         {
 505             boolean r = vh.compareAndSet(recv, 1.0f, 3.0f);
 506             assertEquals(r, false, "failing compareAndSet float");
 507             float x = (float) vh.get(recv);
 508             assertEquals(x, 2.0f, "failing compareAndSet float value");
 509         }
 510 
 511         {
 512             float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f);
 513             assertEquals(r, 2.0f, "success compareAndExchange float");
 514             float x = (float) vh.get(recv);
 515             assertEquals(x, 1.0f, "success compareAndExchange float value");
 516         }
 517 
 518         {
 519             float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f);
 520             assertEquals(r, 1.0f, "failing compareAndExchange float");
 521             float x = (float) vh.get(recv);
 522             assertEquals(x, 1.0f, "failing compareAndExchange float value");
 523         }
 524 
 525         {
 526             float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f);
 527             assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
 528             float x = (float) vh.get(recv);
 529             assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
 530         }
 531 
 532         {
 533             float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f);
 534             assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
 535             float x = (float) vh.get(recv);
 536             assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
 537         }
 538 
 539         {
 540             float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f);
 541             assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
 542             float x = (float) vh.get(recv);
 543             assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
 544         }
 545 
 546         {
 547             float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f);
 548             assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
 549             float x = (float) vh.get(recv);
 550             assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
 551         }
 552 
 553         {
 554             boolean success = false;
 555             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 556                 success = vh.weakCompareAndSetPlain(recv, 1.0f, 2.0f);
 557                 if (!success) weakDelay();
 558             }
 559             assertEquals(success, true, "success weakCompareAndSetPlain float");
 560             float x = (float) vh.get(recv);
 561             assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
 562         }
 563 
 564         {
 565             boolean success = vh.weakCompareAndSetPlain(recv, 1.0f, 3.0f);
 566             assertEquals(success, false, "failing weakCompareAndSetPlain float");
 567             float x = (float) vh.get(recv);
 568             assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
 569         }
 570 
 571         {
 572             boolean success = false;
 573             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 574                 success = vh.weakCompareAndSetAcquire(recv, 2.0f, 1.0f);
 575                 if (!success) weakDelay();
 576             }
 577             assertEquals(success, true, "success weakCompareAndSetAcquire float");
 578             float x = (float) vh.get(recv);
 579             assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
 580         }
 581 
 582         {
 583             boolean success = vh.weakCompareAndSetAcquire(recv, 2.0f, 3.0f);
 584             assertEquals(success, false, "failing weakCompareAndSetAcquire float");
 585             float x = (float) vh.get(recv);
 586             assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
 587         }
 588 
 589         {
 590             boolean success = false;
 591             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 592                 success = vh.weakCompareAndSetRelease(recv, 1.0f, 2.0f);
 593                 if (!success) weakDelay();
 594             }
 595             assertEquals(success, true, "success weakCompareAndSetRelease float");
 596             float x = (float) vh.get(recv);
 597             assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
 598         }
 599 
 600         {
 601             boolean success = vh.weakCompareAndSetRelease(recv, 1.0f, 3.0f);
 602             assertEquals(success, false, "failing weakCompareAndSetRelease float");
 603             float x = (float) vh.get(recv);
 604             assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
 605         }
 606 
 607         {
 608             boolean success = false;
 609             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 610                 success = vh.weakCompareAndSet(recv, 2.0f, 1.0f);
 611                 if (!success) weakDelay();
 612             }
 613             assertEquals(success, true, "success weakCompareAndSet float");
 614             float x = (float) vh.get(recv);
 615             assertEquals(x, 1.0f, "success weakCompareAndSet float value");
 616         }
 617 
 618         {
 619             boolean success = vh.weakCompareAndSet(recv, 2.0f, 3.0f);
 620             assertEquals(success, false, "failing weakCompareAndSet float");
 621             float x = (float) vh.get(recv);
 622             assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
 623         }
 624 
 625         // Compare set and get
 626         {
 627             vh.set(recv, 1.0f);
 628 
 629             float o = (float) vh.getAndSet(recv, 2.0f);
 630             assertEquals(o, 1.0f, "getAndSet float");
 631             float x = (float) vh.get(recv);
 632             assertEquals(x, 2.0f, "getAndSet float value");
 633         }
 634 
 635         {
 636             vh.set(recv, 1.0f);
 637 
 638             float o = (float) vh.getAndSetAcquire(recv, 2.0f);
 639             assertEquals(o, 1.0f, "getAndSetAcquire float");
 640             float x = (float) vh.get(recv);
 641             assertEquals(x, 2.0f, "getAndSetAcquire float value");
 642         }
 643 
 644         {
 645             vh.set(recv, 1.0f);
 646 
 647             float o = (float) vh.getAndSetRelease(recv, 2.0f);
 648             assertEquals(o, 1.0f, "getAndSetRelease float");
 649             float x = (float) vh.get(recv);
 650             assertEquals(x, 2.0f, "getAndSetRelease float value");
 651         }
 652 
 653         // get and add, add and get
 654         {
 655             vh.set(recv, 1.0f);
 656 
 657             float o = (float) vh.getAndAdd(recv, 2.0f);
 658             assertEquals(o, 1.0f, "getAndAdd float");
 659             float x = (float) vh.get(recv);
 660             assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
 661         }
 662 
 663         {
 664             vh.set(recv, 1.0f);
 665 
 666             float o = (float) vh.getAndAddAcquire(recv, 2.0f);
 667             assertEquals(o, 1.0f, "getAndAddAcquire float");
 668             float x = (float) vh.get(recv);
 669             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
 670         }
 671 
 672         {
 673             vh.set(recv, 1.0f);
 674 
 675             float o = (float) vh.getAndAddRelease(recv, 2.0f);
 676             assertEquals(o, 1.0f, "getAndAddReleasefloat");
 677             float x = (float) vh.get(recv);
 678             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
 679         }
 680 
 681     }
 682 
 683     static void testInstanceFieldUnsupported(VarHandleTestAccessFloat recv, VarHandle vh) {
 684 
 685 
 686         checkUOE(() -> {
 687             float o = (float) vh.getAndBitwiseOr(recv, 1.0f);
 688         });
 689 
 690         checkUOE(() -> {
 691             float o = (float) vh.getAndBitwiseOrAcquire(recv, 1.0f);
 692         });
 693 
 694         checkUOE(() -> {
 695             float o = (float) vh.getAndBitwiseOrRelease(recv, 1.0f);
 696         });
 697 
 698         checkUOE(() -> {
 699             float o = (float) vh.getAndBitwiseAnd(recv, 1.0f);
 700         });
 701 
 702         checkUOE(() -> {
 703             float o = (float) vh.getAndBitwiseAndAcquire(recv, 1.0f);
 704         });
 705 
 706         checkUOE(() -> {
 707             float o = (float) vh.getAndBitwiseAndRelease(recv, 1.0f);
 708         });
 709 
 710         checkUOE(() -> {
 711             float o = (float) vh.getAndBitwiseXor(recv, 1.0f);
 712         });
 713 
 714         checkUOE(() -> {
 715             float o = (float) vh.getAndBitwiseXorAcquire(recv, 1.0f);
 716         });
 717 
 718         checkUOE(() -> {
 719             float o = (float) vh.getAndBitwiseXorRelease(recv, 1.0f);
 720         });
 721     }
 722 
 723 
 724     static void testStaticField(VarHandle vh) {
 725         // Plain
 726         {
 727             vh.set(1.0f);
 728             float x = (float) vh.get();
 729             assertEquals(x, 1.0f, "set float value");
 730         }
 731 
 732 
 733         // Volatile
 734         {
 735             vh.setVolatile(2.0f);
 736             float x = (float) vh.getVolatile();
 737             assertEquals(x, 2.0f, "setVolatile float value");
 738         }
 739 
 740         // Lazy
 741         {
 742             vh.setRelease(1.0f);
 743             float x = (float) vh.getAcquire();
 744             assertEquals(x, 1.0f, "setRelease float value");
 745         }
 746 
 747         // Opaque
 748         {
 749             vh.setOpaque(2.0f);
 750             float x = (float) vh.getOpaque();
 751             assertEquals(x, 2.0f, "setOpaque float value");
 752         }
 753 
 754         vh.set(1.0f);
 755 
 756         // Compare
 757         {
 758             boolean r = vh.compareAndSet(1.0f, 2.0f);
 759             assertEquals(r, true, "success compareAndSet float");
 760             float x = (float) vh.get();
 761             assertEquals(x, 2.0f, "success compareAndSet float value");
 762         }
 763 
 764         {
 765             boolean r = vh.compareAndSet(1.0f, 3.0f);
 766             assertEquals(r, false, "failing compareAndSet float");
 767             float x = (float) vh.get();
 768             assertEquals(x, 2.0f, "failing compareAndSet float value");
 769         }
 770 
 771         {
 772             float r = (float) vh.compareAndExchange(2.0f, 1.0f);
 773             assertEquals(r, 2.0f, "success compareAndExchange float");
 774             float x = (float) vh.get();
 775             assertEquals(x, 1.0f, "success compareAndExchange float value");
 776         }
 777 
 778         {
 779             float r = (float) vh.compareAndExchange(2.0f, 3.0f);
 780             assertEquals(r, 1.0f, "failing compareAndExchange float");
 781             float x = (float) vh.get();
 782             assertEquals(x, 1.0f, "failing compareAndExchange float value");
 783         }
 784 
 785         {
 786             float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f);
 787             assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
 788             float x = (float) vh.get();
 789             assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
 790         }
 791 
 792         {
 793             float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f);
 794             assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
 795             float x = (float) vh.get();
 796             assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
 797         }
 798 
 799         {
 800             float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f);
 801             assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
 802             float x = (float) vh.get();
 803             assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
 804         }
 805 
 806         {
 807             float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f);
 808             assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
 809             float x = (float) vh.get();
 810             assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value");
 811         }
 812 
 813         {
 814             boolean success = false;
 815             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 816                 success = vh.weakCompareAndSetPlain(1.0f, 2.0f);
 817                 if (!success) weakDelay();
 818             }
 819             assertEquals(success, true, "success weakCompareAndSetPlain float");
 820             float x = (float) vh.get();
 821             assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
 822         }
 823 
 824         {
 825             boolean success = vh.weakCompareAndSetPlain(1.0f, 3.0f);
 826             assertEquals(success, false, "failing weakCompareAndSetPlain float");
 827             float x = (float) vh.get();
 828             assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value");
 829         }
 830 
 831         {
 832             boolean success = false;
 833             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 834                 success = vh.weakCompareAndSetAcquire(2.0f, 1.0f);
 835                 if (!success) weakDelay();
 836             }
 837             assertEquals(success, true, "success weakCompareAndSetAcquire float");
 838             float x = (float) vh.get();
 839             assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
 840         }
 841 
 842         {
 843             boolean success = vh.weakCompareAndSetAcquire(2.0f, 3.0f);
 844             assertEquals(success, false, "failing weakCompareAndSetAcquire float");
 845             float x = (float) vh.get();
 846             assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value");
 847         }
 848 
 849         {
 850             boolean success = false;
 851             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 852                 success = vh.weakCompareAndSetRelease(1.0f, 2.0f);
 853                 if (!success) weakDelay();
 854             }
 855             assertEquals(success, true, "success weakCompareAndSetRelease float");
 856             float x = (float) vh.get();
 857             assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
 858         }
 859 
 860         {
 861             boolean success = vh.weakCompareAndSetRelease(1.0f, 3.0f);
 862             assertEquals(success, false, "failing weakCompareAndSetRelease float");
 863             float x = (float) vh.get();
 864             assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value");
 865         }
 866 
 867         {
 868             boolean success = false;
 869             for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
 870                 success = vh.weakCompareAndSet(2.0f, 1.0f);
 871                 if (!success) weakDelay();
 872             }
 873             assertEquals(success, true, "success weakCompareAndSet float");
 874             float x = (float) vh.get();
 875             assertEquals(x, 1.0f, "success weakCompareAndSet float");
 876         }
 877 
 878         {
 879             boolean success = vh.weakCompareAndSet(2.0f, 3.0f);
 880             assertEquals(success, false, "failing weakCompareAndSet float");
 881             float x = (float) vh.get();
 882             assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
 883         }
 884 
 885         // Compare set and get
 886         {
 887             vh.set(1.0f);
 888 
 889             float o = (float) vh.getAndSet(2.0f);
 890             assertEquals(o, 1.0f, "getAndSet float");
 891             float x = (float) vh.get();
 892             assertEquals(x, 2.0f, "getAndSet float value");
 893         }
 894 
 895         {
 896             vh.set(1.0f);
 897 
 898             float o = (float) vh.getAndSetAcquire(2.0f);
 899             assertEquals(o, 1.0f, "getAndSetAcquire float");
 900             float x = (float) vh.get();
 901             assertEquals(x, 2.0f, "getAndSetAcquire float value");
 902         }
 903 
 904         {
 905             vh.set(1.0f);
 906 
 907             float o = (float) vh.getAndSetRelease(2.0f);
 908             assertEquals(o, 1.0f, "getAndSetRelease float");
 909             float x = (float) vh.get();
 910             assertEquals(x, 2.0f, "getAndSetRelease float value");
 911         }
 912 
 913         // get and add, add and get
 914         {
 915             vh.set(1.0f);
 916 
 917             float o = (float) vh.getAndAdd(2.0f);
 918             assertEquals(o, 1.0f, "getAndAdd float");
 919             float x = (float) vh.get();
 920             assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
 921         }
 922 
 923         {
 924             vh.set(1.0f);
 925 
 926             float o = (float) vh.getAndAddAcquire(2.0f);
 927             assertEquals(o, 1.0f, "getAndAddAcquire float");
 928             float x = (float) vh.get();
 929             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
 930         }
 931 
 932         {
 933             vh.set(1.0f);
 934 
 935             float o = (float) vh.getAndAddRelease(2.0f);
 936             assertEquals(o, 1.0f, "getAndAddReleasefloat");
 937             float x = (float) vh.get();
 938             assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
 939         }
 940 
 941     }
 942 
 943     static void testStaticFieldUnsupported(VarHandle vh) {
 944 
 945 
 946         checkUOE(() -> {
 947             float o = (float) vh.getAndBitwiseOr(1.0f);
 948         });
 949 
 950         checkUOE(() -> {
 951             float o = (float) vh.getAndBitwiseOrAcquire(1.0f);
 952         });
 953 
 954         checkUOE(() -> {
 955             float o = (float) vh.getAndBitwiseOrRelease(1.0f);
 956         });
 957 
 958         checkUOE(() -> {
 959             float o = (float) vh.getAndBitwiseAnd(1.0f);
 960         });
 961 
 962         checkUOE(() -> {
 963             float o = (float) vh.getAndBitwiseAndAcquire(1.0f);
 964         });
 965 
 966         checkUOE(() -> {
 967             float o = (float) vh.getAndBitwiseAndRelease(1.0f);
 968         });
 969 
 970         checkUOE(() -> {
 971             float o = (float) vh.getAndBitwiseXor(1.0f);
 972         });
 973 
 974         checkUOE(() -> {
 975             float o = (float) vh.getAndBitwiseXorAcquire(1.0f);
 976         });
 977 
 978         checkUOE(() -> {
 979             float o = (float) vh.getAndBitwiseXorRelease(1.0f);
 980         });
 981     }
 982 
 983 
 984     static void testArray(VarHandle vh) {
 985         float[] array = new float[10];
 986 
 987         for (int i = 0; i < array.length; i++) {
 988             // Plain
 989             {
 990                 vh.set(array, i, 1.0f);
 991                 float x = (float) vh.get(array, i);
 992                 assertEquals(x, 1.0f, "get float value");
 993             }
 994 
 995 
 996             // Volatile
 997             {
 998                 vh.setVolatile(array, i, 2.0f);
 999                 float x = (float) vh.getVolatile(array, i);
1000                 assertEquals(x, 2.0f, "setVolatile float value");
1001             }
1002 
1003             // Lazy
1004             {
1005                 vh.setRelease(array, i, 1.0f);
1006                 float x = (float) vh.getAcquire(array, i);
1007                 assertEquals(x, 1.0f, "setRelease float value");
1008             }
1009 
1010             // Opaque
1011             {
1012                 vh.setOpaque(array, i, 2.0f);
1013                 float x = (float) vh.getOpaque(array, i);
1014                 assertEquals(x, 2.0f, "setOpaque float value");
1015             }
1016 
1017             vh.set(array, i, 1.0f);
1018 
1019             // Compare
1020             {
1021                 boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f);
1022                 assertEquals(r, true, "success compareAndSet float");
1023                 float x = (float) vh.get(array, i);
1024                 assertEquals(x, 2.0f, "success compareAndSet float value");
1025             }
1026 
1027             {
1028                 boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f);
1029                 assertEquals(r, false, "failing compareAndSet float");
1030                 float x = (float) vh.get(array, i);
1031                 assertEquals(x, 2.0f, "failing compareAndSet float value");
1032             }
1033 
1034             {
1035                 float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f);
1036                 assertEquals(r, 2.0f, "success compareAndExchange float");
1037                 float x = (float) vh.get(array, i);
1038                 assertEquals(x, 1.0f, "success compareAndExchange float value");
1039             }
1040 
1041             {
1042                 float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f);
1043                 assertEquals(r, 1.0f, "failing compareAndExchange float");
1044                 float x = (float) vh.get(array, i);
1045                 assertEquals(x, 1.0f, "failing compareAndExchange float value");
1046             }
1047 
1048             {
1049                 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f);
1050                 assertEquals(r, 1.0f, "success compareAndExchangeAcquire float");
1051                 float x = (float) vh.get(array, i);
1052                 assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value");
1053             }
1054 
1055             {
1056                 float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f);
1057                 assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float");
1058                 float x = (float) vh.get(array, i);
1059                 assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value");
1060             }
1061 
1062             {
1063                 float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f);
1064                 assertEquals(r, 2.0f, "success compareAndExchangeRelease float");
1065                 float x = (float) vh.get(array, i);
1066                 assertEquals(x, 1.0f, "success compareAndExchangeRelease float value");
1067             }
1068 
1069             {
1070                 float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f);
1071                 assertEquals(r, 1.0f, "failing compareAndExchangeRelease float");
1072                 float x = (float) vh.get(array, i);
1073                 assertEquals(x, 1.0f, "failing compareAndExchangeRelease float 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.0f, 2.0f);
1080                     if (!success) weakDelay();
1081                 }
1082                 assertEquals(success, true, "success weakCompareAndSetPlain float");
1083                 float x = (float) vh.get(array, i);
1084                 assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value");
1085             }
1086 
1087             {
1088                 boolean success = vh.weakCompareAndSetPlain(array, i, 1.0f, 3.0f);
1089                 assertEquals(success, false, "failing weakCompareAndSetPlain float");
1090                 float x = (float) vh.get(array, i);
1091                 assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float 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.0f, 1.0f);
1098                     if (!success) weakDelay();
1099                 }
1100                 assertEquals(success, true, "success weakCompareAndSetAcquire float");
1101                 float x = (float) vh.get(array, i);
1102                 assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float");
1103             }
1104 
1105             {
1106                 boolean success = vh.weakCompareAndSetAcquire(array, i, 2.0f, 3.0f);
1107                 assertEquals(success, false, "failing weakCompareAndSetAcquire float");
1108                 float x = (float) vh.get(array, i);
1109                 assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float 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.0f, 2.0f);
1116                     if (!success) weakDelay();
1117                 }
1118                 assertEquals(success, true, "success weakCompareAndSetRelease float");
1119                 float x = (float) vh.get(array, i);
1120                 assertEquals(x, 2.0f, "success weakCompareAndSetRelease float");
1121             }
1122 
1123             {
1124                 boolean success = vh.weakCompareAndSetRelease(array, i, 1.0f, 3.0f);
1125                 assertEquals(success, false, "failing weakCompareAndSetRelease float");
1126                 float x = (float) vh.get(array, i);
1127                 assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float 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.0f, 1.0f);
1134                     if (!success) weakDelay();
1135                 }
1136                 assertEquals(success, true, "success weakCompareAndSet float");
1137                 float x = (float) vh.get(array, i);
1138                 assertEquals(x, 1.0f, "success weakCompareAndSet float");
1139             }
1140 
1141             {
1142                 boolean success = vh.weakCompareAndSet(array, i, 2.0f, 3.0f);
1143                 assertEquals(success, false, "failing weakCompareAndSet float");
1144                 float x = (float) vh.get(array, i);
1145                 assertEquals(x, 1.0f, "failing weakCompareAndSet float value");
1146             }
1147 
1148             // Compare set and get
1149             {
1150                 vh.set(array, i, 1.0f);
1151 
1152                 float o = (float) vh.getAndSet(array, i, 2.0f);
1153                 assertEquals(o, 1.0f, "getAndSet float");
1154                 float x = (float) vh.get(array, i);
1155                 assertEquals(x, 2.0f, "getAndSet float value");
1156             }
1157 
1158             {
1159                 vh.set(array, i, 1.0f);
1160 
1161                 float o = (float) vh.getAndSetAcquire(array, i, 2.0f);
1162                 assertEquals(o, 1.0f, "getAndSetAcquire float");
1163                 float x = (float) vh.get(array, i);
1164                 assertEquals(x, 2.0f, "getAndSetAcquire float value");
1165             }
1166 
1167             {
1168                 vh.set(array, i, 1.0f);
1169 
1170                 float o = (float) vh.getAndSetRelease(array, i, 2.0f);
1171                 assertEquals(o, 1.0f, "getAndSetRelease float");
1172                 float x = (float) vh.get(array, i);
1173                 assertEquals(x, 2.0f, "getAndSetRelease float value");
1174             }
1175 
1176             // get and add, add and get
1177             {
1178                 vh.set(array, i, 1.0f);
1179 
1180                 float o = (float) vh.getAndAdd(array, i, 2.0f);
1181                 assertEquals(o, 1.0f, "getAndAdd float");
1182                 float x = (float) vh.get(array, i);
1183                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value");
1184             }
1185 
1186             {
1187                 vh.set(array, i, 1.0f);
1188 
1189                 float o = (float) vh.getAndAddAcquire(array, i, 2.0f);
1190                 assertEquals(o, 1.0f, "getAndAddAcquire float");
1191                 float x = (float) vh.get(array, i);
1192                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value");
1193             }
1194 
1195             {
1196                 vh.set(array, i, 1.0f);
1197 
1198                 float o = (float) vh.getAndAddRelease(array, i, 2.0f);
1199                 assertEquals(o, 1.0f, "getAndAddReleasefloat");
1200                 float x = (float) vh.get(array, i);
1201                 assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value");
1202             }
1203 
1204         }
1205     }
1206 
1207     static void testArrayUnsupported(VarHandle vh) {
1208         float[] array = new float[10];
1209 
1210         int i = 0;
1211 
1212 
1213         checkUOE(() -> {
1214             float o = (float) vh.getAndBitwiseOr(array, i, 1.0f);
1215         });
1216 
1217         checkUOE(() -> {
1218             float o = (float) vh.getAndBitwiseOrAcquire(array, i, 1.0f);
1219         });
1220 
1221         checkUOE(() -> {
1222             float o = (float) vh.getAndBitwiseOrRelease(array, i, 1.0f);
1223         });
1224 
1225         checkUOE(() -> {
1226             float o = (float) vh.getAndBitwiseAnd(array, i, 1.0f);
1227         });
1228 
1229         checkUOE(() -> {
1230             float o = (float) vh.getAndBitwiseAndAcquire(array, i, 1.0f);
1231         });
1232 
1233         checkUOE(() -> {
1234             float o = (float) vh.getAndBitwiseAndRelease(array, i, 1.0f);
1235         });
1236 
1237         checkUOE(() -> {
1238             float o = (float) vh.getAndBitwiseXor(array, i, 1.0f);
1239         });
1240 
1241         checkUOE(() -> {
1242             float o = (float) vh.getAndBitwiseXorAcquire(array, i, 1.0f);
1243         });
1244 
1245         checkUOE(() -> {
1246             float o = (float) vh.getAndBitwiseXorRelease(array, i, 1.0f);
1247         });
1248     }
1249 
1250     static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
1251         float[] array = new float[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                 float x = (float) vh.get(array, ci);
1258             });
1259 
1260             checkAIOOBE(() -> {
1261                 vh.set(array, ci, 1.0f);
1262             });
1263 
1264             checkAIOOBE(() -> {
1265                 float x = (float) vh.getVolatile(array, ci);
1266             });
1267 
1268             checkAIOOBE(() -> {
1269                 vh.setVolatile(array, ci, 1.0f);
1270             });
1271 
1272             checkAIOOBE(() -> {
1273                 float x = (float) vh.getAcquire(array, ci);
1274             });
1275 
1276             checkAIOOBE(() -> {
1277                 vh.setRelease(array, ci, 1.0f);
1278             });
1279 
1280             checkAIOOBE(() -> {
1281                 float x = (float) vh.getOpaque(array, ci);
1282             });
1283 
1284             checkAIOOBE(() -> {
1285                 vh.setOpaque(array, ci, 1.0f);
1286             });
1287 
1288             checkAIOOBE(() -> {
1289                 boolean r = vh.compareAndSet(array, ci, 1.0f, 2.0f);
1290             });
1291 
1292             checkAIOOBE(() -> {
1293                 float r = (float) vh.compareAndExchange(array, ci, 2.0f, 1.0f);
1294             });
1295 
1296             checkAIOOBE(() -> {
1297                 float r = (float) vh.compareAndExchangeAcquire(array, ci, 2.0f, 1.0f);
1298             });
1299 
1300             checkAIOOBE(() -> {
1301                 float r = (float) vh.compareAndExchangeRelease(array, ci, 2.0f, 1.0f);
1302             });
1303 
1304             checkAIOOBE(() -> {
1305                 boolean r = vh.weakCompareAndSetPlain(array, ci, 1.0f, 2.0f);
1306             });
1307 
1308             checkAIOOBE(() -> {
1309                 boolean r = vh.weakCompareAndSet(array, ci, 1.0f, 2.0f);
1310             });
1311 
1312             checkAIOOBE(() -> {
1313                 boolean r = vh.weakCompareAndSetAcquire(array, ci, 1.0f, 2.0f);
1314             });
1315 
1316             checkAIOOBE(() -> {
1317                 boolean r = vh.weakCompareAndSetRelease(array, ci, 1.0f, 2.0f);
1318             });
1319 
1320             checkAIOOBE(() -> {
1321                 float o = (float) vh.getAndSet(array, ci, 1.0f);
1322             });
1323 
1324             checkAIOOBE(() -> {
1325                 float o = (float) vh.getAndSetAcquire(array, ci, 1.0f);
1326             });
1327 
1328             checkAIOOBE(() -> {
1329                 float o = (float) vh.getAndSetRelease(array, ci, 1.0f);
1330             });
1331 
1332             checkAIOOBE(() -> {
1333                 float o = (float) vh.getAndAdd(array, ci, 1.0f);
1334             });
1335 
1336             checkAIOOBE(() -> {
1337                 float o = (float) vh.getAndAddAcquire(array, ci, 1.0f);
1338             });
1339 
1340             checkAIOOBE(() -> {
1341                 float o = (float) vh.getAndAddRelease(array, ci, 1.0f);
1342             });
1343 
1344         }
1345     }
1346 
1347 }
1348