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