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