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