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