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 VarHandleTestMethodHandleAccessShort 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 VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { 47 static final short static_final_v = (short)0x0123; 48 49 static short static_v; 50 51 final short final_v = (short)0x0123; 52 53 short 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 VarHandleTestMethodHandleAccessShort.class, "final_v", short.class); 69 70 vhField = MethodHandles.lookup().findVarHandle( 71 VarHandleTestMethodHandleAccessShort.class, "v", short.class); 72 73 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( 74 VarHandleTestMethodHandleAccessShort.class, "static_final_v", short.class); 75 76 vhStaticField = MethodHandles.lookup().findStaticVarHandle( 77 VarHandleTestMethodHandleAccessShort.class, "static_v", short.class); 78 79 vhArray = MethodHandles.arrayElementVarHandle(short[].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, VarHandleTestMethodHandleAccessShort::testStaticField)); 96 cases.add(new MethodHandleAccessTestCase("Static field unsupported", 97 vhStaticField, f, VarHandleTestMethodHandleAccessShort::testStaticFieldUnsupported, 98 false)); 99 100 cases.add(new MethodHandleAccessTestCase("Array", 101 vhArray, f, VarHandleTestMethodHandleAccessShort::testArray)); 102 cases.add(new MethodHandleAccessTestCase("Array unsupported", 103 vhArray, f, VarHandleTestMethodHandleAccessShort::testArrayUnsupported, 104 false)); 105 cases.add(new MethodHandleAccessTestCase("Array index out of bounds", 106 vhArray, f, VarHandleTestMethodHandleAccessShort::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(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable { 127 // Plain 128 { 129 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 130 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 131 assertEquals(x, (short)0x0123, "set short value"); 132 } 133 134 135 // Volatile 136 { 137 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)0x4567); 138 short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); 139 assertEquals(x, (short)0x4567, "setVolatile short value"); 140 } 141 142 // Lazy 143 { 144 hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)0x0123); 145 short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); 146 assertEquals(x, (short)0x0123, "setRelease short value"); 147 } 148 149 // Opaque 150 { 151 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)0x4567); 152 short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); 153 assertEquals(x, (short)0x4567, "setOpaque short value"); 154 } 155 156 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 157 158 // Compare 159 { 160 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567); 161 assertEquals(r, true, "success compareAndSet short"); 162 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 163 assertEquals(x, (short)0x4567, "success compareAndSet short value"); 164 } 165 166 { 167 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x89AB); 168 assertEquals(r, false, "failing compareAndSet short"); 169 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 170 assertEquals(x, (short)0x4567, "failing compareAndSet short value"); 171 } 172 173 { 174 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x0123); 175 assertEquals(r, (short)0x4567, "success compareAndExchange short"); 176 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 177 assertEquals(x, (short)0x0123, "success compareAndExchange short value"); 178 } 179 180 { 181 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x89AB); 182 assertEquals(r, (short)0x0123, "failing compareAndExchange short"); 183 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 184 assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); 185 } 186 187 { 188 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x4567); 189 assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); 190 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 191 assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); 192 } 193 194 { 195 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x89AB); 196 assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); 197 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 198 assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); 199 } 200 201 { 202 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x0123); 203 assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); 204 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 205 assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); 206 } 207 208 { 209 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x89AB); 210 assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); 211 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 212 assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short 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, (short)0x0123, (short)0x4567); 220 if (!success) weakDelay(); 221 } 222 assertEquals(success, true, "success weakCompareAndSetPlain short"); 223 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 224 assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); 225 } 226 227 { 228 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (short)0x0123, (short)0x89AB); 229 assertEquals(success, false, "failing weakCompareAndSetPlain short"); 230 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 231 assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short 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, (short)0x4567, (short)0x0123); 239 if (!success) weakDelay(); 240 } 241 assertEquals(success, true, "success weakCompareAndSetAcquire short"); 242 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 243 assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); 244 } 245 246 { 247 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (short)0x4567, (short)0x89AB); 248 assertEquals(success, false, "failing weakCompareAndSetAcquire short"); 249 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 250 assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short 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, (short)0x0123, (short)0x4567); 258 if (!success) weakDelay(); 259 } 260 assertEquals(success, true, "success weakCompareAndSetRelease short"); 261 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 262 assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); 263 } 264 265 { 266 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (short)0x0123, (short)0x89AB); 267 assertEquals(success, false, "failing weakCompareAndSetRelease short"); 268 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 269 assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short 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, (short)0x4567, (short)0x0123); 277 if (!success) weakDelay(); 278 } 279 assertEquals(success, true, "success weakCompareAndSet short"); 280 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 281 assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); 282 } 283 284 { 285 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (short)0x4567, (short)0x89AB); 286 assertEquals(success, false, "failing weakCompareAndSet short"); 287 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 288 assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); 289 } 290 291 // Compare set and get 292 { 293 short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (short)0x4567); 294 assertEquals(o, (short)0x0123, "getAndSet short"); 295 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 296 assertEquals(x, (short)0x4567, "getAndSet short value"); 297 } 298 299 // get and add, add and get 300 { 301 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 302 303 short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (short)0x4567); 304 assertEquals(o, (short)0x0123, "getAndAdd short"); 305 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 306 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); 307 } 308 309 { 310 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 311 312 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (short)0x4567); 313 assertEquals(o, (short)0x0123, "getAndAddAcquire short"); 314 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 315 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); 316 } 317 318 { 319 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 320 321 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (short)0x4567); 322 assertEquals(o, (short)0x0123, "getAndAddRelease short"); 323 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 324 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); 325 } 326 327 // get and bitwise or 328 { 329 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 330 331 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (short)0x4567); 332 assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); 333 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 334 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); 335 } 336 337 { 338 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 339 340 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (short)0x4567); 341 assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); 342 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 343 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); 344 } 345 346 { 347 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 348 349 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (short)0x4567); 350 assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); 351 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 352 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); 353 } 354 355 // get and bitwise and 356 { 357 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 358 359 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (short)0x4567); 360 assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); 361 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 362 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); 363 } 364 365 { 366 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 367 368 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (short)0x4567); 369 assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); 370 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 371 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); 372 } 373 374 { 375 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 376 377 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (short)0x4567); 378 assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); 379 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 380 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); 381 } 382 383 // get and bitwise xor 384 { 385 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 386 387 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (short)0x4567); 388 assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); 389 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 390 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); 391 } 392 393 { 394 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 395 396 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (short)0x4567); 397 assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); 398 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 399 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); 400 } 401 402 { 403 hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); 404 405 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (short)0x4567); 406 assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); 407 short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); 408 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); 409 } 410 } 411 412 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessShort 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((short)0x0123); 422 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 423 assertEquals(x, (short)0x0123, "set short value"); 424 } 425 426 427 // Volatile 428 { 429 hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)0x4567); 430 short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); 431 assertEquals(x, (short)0x4567, "setVolatile short value"); 432 } 433 434 // Lazy 435 { 436 hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)0x0123); 437 short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); 438 assertEquals(x, (short)0x0123, "setRelease short value"); 439 } 440 441 // Opaque 442 { 443 hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)0x4567); 444 short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); 445 assertEquals(x, (short)0x4567, "setOpaque short value"); 446 } 447 448 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 449 450 // Compare 451 { 452 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567); 453 assertEquals(r, true, "success compareAndSet short"); 454 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 455 assertEquals(x, (short)0x4567, "success compareAndSet short value"); 456 } 457 458 { 459 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x89AB); 460 assertEquals(r, false, "failing compareAndSet short"); 461 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 462 assertEquals(x, (short)0x4567, "failing compareAndSet short value"); 463 } 464 465 { 466 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x0123); 467 assertEquals(r, (short)0x4567, "success compareAndExchange short"); 468 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 469 assertEquals(x, (short)0x0123, "success compareAndExchange short value"); 470 } 471 472 { 473 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x89AB); 474 assertEquals(r, (short)0x0123, "failing compareAndExchange short"); 475 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 476 assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); 477 } 478 479 { 480 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x4567); 481 assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); 482 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 483 assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); 484 } 485 486 { 487 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x89AB); 488 assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); 489 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 490 assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); 491 } 492 493 { 494 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x0123); 495 assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); 496 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 497 assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); 498 } 499 500 { 501 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x89AB); 502 assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); 503 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 504 assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short 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((short)0x0123, (short)0x4567); 512 if (!success) weakDelay(); 513 } 514 assertEquals(success, true, "success weakCompareAndSetPlain short"); 515 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 516 assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); 517 } 518 519 { 520 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((short)0x0123, (short)0x89AB); 521 assertEquals(success, false, "failing weakCompareAndSetPlain short"); 522 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 523 assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short 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((short)0x4567, (short)0x0123); 531 if (!success) weakDelay(); 532 } 533 assertEquals(success, true, "success weakCompareAndSetAcquire short"); 534 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 535 assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); 536 } 537 538 { 539 MethodHandle mh = hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE); 540 boolean success = (boolean) mh.invokeExact((short)0x4567, (short)0x89AB); 541 assertEquals(success, false, "failing weakCompareAndSetAcquire short"); 542 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 543 assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short 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((short)0x0123, (short)0x4567); 551 if (!success) weakDelay(); 552 } 553 assertEquals(success, true, "success weakCompareAndSetRelease short"); 554 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 555 assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); 556 } 557 558 { 559 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((short)0x0123, (short)0x89AB); 560 assertEquals(success, false, "failing weakCompareAndSetRelease short"); 561 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 562 assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short 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((short)0x4567, (short)0x0123); 570 if (!success) weakDelay(); 571 } 572 assertEquals(success, true, "success weakCompareAndSet short"); 573 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 574 assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); 575 } 576 577 { 578 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((short)0x4567, (short)0x89AB); 579 assertEquals(success, false, "failing weakCompareAndSet short"); 580 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 581 assertEquals(x, (short)0x0123, "failing weakCompareAndSetRe short value"); 582 } 583 584 // Compare set and get 585 { 586 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 587 588 short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact((short)0x4567); 589 assertEquals(o, (short)0x0123, "getAndSet short"); 590 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 591 assertEquals(x, (short)0x4567, "getAndSet short value"); 592 } 593 594 // Compare set and get 595 { 596 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 597 598 short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((short)0x4567); 599 assertEquals(o, (short)0x0123, "getAndSetAcquire short"); 600 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 601 assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); 602 } 603 604 // Compare set and get 605 { 606 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 607 608 short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((short)0x4567); 609 assertEquals(o, (short)0x0123, "getAndSetRelease short"); 610 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 611 assertEquals(x, (short)0x4567, "getAndSetRelease short value"); 612 } 613 614 // get and add, add and get 615 { 616 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 617 618 short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((short)0x4567); 619 assertEquals(o, (short)0x0123, "getAndAdd short"); 620 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 621 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); 622 } 623 624 { 625 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 626 627 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((short)0x4567); 628 assertEquals(o, (short)0x0123, "getAndAddAcquire short"); 629 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 630 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); 631 } 632 633 { 634 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 635 636 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((short)0x4567); 637 assertEquals(o, (short)0x0123, "getAndAddRelease short"); 638 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 639 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); 640 } 641 642 // get and bitwise or 643 { 644 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 645 646 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((short)0x4567); 647 assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); 648 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 649 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); 650 } 651 652 { 653 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 654 655 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((short)0x4567); 656 assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); 657 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 658 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); 659 } 660 661 { 662 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 663 664 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((short)0x4567); 665 assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); 666 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 667 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); 668 } 669 670 // get and bitwise and 671 { 672 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 673 674 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((short)0x4567); 675 assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); 676 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 677 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); 678 } 679 680 { 681 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 682 683 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((short)0x4567); 684 assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); 685 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 686 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); 687 } 688 689 { 690 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 691 692 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((short)0x4567); 693 assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); 694 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 695 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); 696 } 697 698 // get and bitwise xor 699 { 700 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 701 702 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((short)0x4567); 703 assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); 704 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 705 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); 706 } 707 708 { 709 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 710 711 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((short)0x4567); 712 assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); 713 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 714 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); 715 } 716 717 { 718 hs.get(TestAccessMode.SET).invokeExact((short)0x0123); 719 720 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((short)0x4567); 721 assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); 722 short x = (short) hs.get(TestAccessMode.GET).invokeExact(); 723 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short 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 short[] array = new short[10]; 735 736 for (int i = 0; i < array.length; i++) { 737 // Plain 738 { 739 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 740 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 741 assertEquals(x, (short)0x0123, "get short value"); 742 } 743 744 745 // Volatile 746 { 747 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)0x4567); 748 short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); 749 assertEquals(x, (short)0x4567, "setVolatile short value"); 750 } 751 752 // Lazy 753 { 754 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)0x0123); 755 short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); 756 assertEquals(x, (short)0x0123, "setRelease short value"); 757 } 758 759 // Opaque 760 { 761 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)0x4567); 762 short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); 763 assertEquals(x, (short)0x4567, "setOpaque short value"); 764 } 765 766 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 767 768 // Compare 769 { 770 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567); 771 assertEquals(r, true, "success compareAndSet short"); 772 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 773 assertEquals(x, (short)0x4567, "success compareAndSet short value"); 774 } 775 776 { 777 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x89AB); 778 assertEquals(r, false, "failing compareAndSet short"); 779 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 780 assertEquals(x, (short)0x4567, "failing compareAndSet short value"); 781 } 782 783 { 784 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x0123); 785 assertEquals(r, (short)0x4567, "success compareAndExchange short"); 786 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 787 assertEquals(x, (short)0x0123, "success compareAndExchange short value"); 788 } 789 790 { 791 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x89AB); 792 assertEquals(r, (short)0x0123, "failing compareAndExchange short"); 793 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 794 assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); 795 } 796 797 { 798 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x4567); 799 assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); 800 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 801 assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); 802 } 803 804 { 805 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB); 806 assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); 807 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 808 assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); 809 } 810 811 { 812 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x0123); 813 assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); 814 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 815 assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); 816 } 817 818 { 819 short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x89AB); 820 assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); 821 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 822 assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short 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, (short)0x0123, (short)0x4567); 830 if (!success) weakDelay(); 831 } 832 assertEquals(success, true, "success weakCompareAndSetPlain short"); 833 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 834 assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); 835 } 836 837 { 838 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (short)0x0123, (short)0x89AB); 839 assertEquals(success, false, "failing weakCompareAndSetPlain short"); 840 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 841 assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short 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, (short)0x4567, (short)0x0123); 849 if (!success) weakDelay(); 850 } 851 assertEquals(success, true, "success weakCompareAndSetAcquire short"); 852 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 853 assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); 854 } 855 856 { 857 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567, (short)0x89AB); 858 assertEquals(success, false, "failing weakCompareAndSetAcquire short"); 859 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 860 assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short 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, (short)0x0123, (short)0x4567); 868 if (!success) weakDelay(); 869 } 870 assertEquals(success, true, "success weakCompareAndSetRelease short"); 871 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 872 assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); 873 } 874 875 { 876 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB); 877 assertEquals(success, false, "failing weakCompareAndSetAcquire short"); 878 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 879 assertEquals(x, (short)0x4567, "failing weakCompareAndSetAcquire short 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, (short)0x4567, (short)0x0123); 887 if (!success) weakDelay(); 888 } 889 assertEquals(success, true, "success weakCompareAndSet short"); 890 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 891 assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); 892 } 893 894 { 895 boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (short)0x4567, (short)0x89AB); 896 assertEquals(success, false, "failing weakCompareAndSet short"); 897 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 898 assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); 899 } 900 901 // Compare set and get 902 { 903 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 904 905 short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (short)0x4567); 906 assertEquals(o, (short)0x0123, "getAndSet short"); 907 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 908 assertEquals(x, (short)0x4567, "getAndSet short value"); 909 } 910 911 { 912 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 913 914 short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567); 915 assertEquals(o, (short)0x0123, "getAndSetAcquire short"); 916 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 917 assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); 918 } 919 920 { 921 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 922 923 short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (short)0x4567); 924 assertEquals(o, (short)0x0123, "getAndSetRelease short"); 925 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 926 assertEquals(x, (short)0x4567, "getAndSetRelease short value"); 927 } 928 929 // get and add, add and get 930 { 931 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 932 933 short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (short)0x4567); 934 assertEquals(o, (short)0x0123, "getAndAdd short"); 935 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 936 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); 937 } 938 939 { 940 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 941 942 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (short)0x4567); 943 assertEquals(o, (short)0x0123, "getAndAddAcquire short"); 944 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 945 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); 946 } 947 948 { 949 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 950 951 short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (short)0x4567); 952 assertEquals(o, (short)0x0123, "getAndAddRelease short"); 953 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 954 assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); 955 } 956 957 // get and bitwise or 958 { 959 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 960 961 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (short)0x4567); 962 assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); 963 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 964 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); 965 } 966 967 { 968 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 969 970 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (short)0x4567); 971 assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); 972 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 973 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); 974 } 975 976 { 977 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 978 979 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (short)0x4567); 980 assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); 981 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 982 assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); 983 } 984 985 // get and bitwise and 986 { 987 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 988 989 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (short)0x4567); 990 assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); 991 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 992 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); 993 } 994 995 { 996 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 997 998 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (short)0x4567); 999 assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); 1000 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 1001 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); 1002 } 1003 1004 { 1005 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 1006 1007 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (short)0x4567); 1008 assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); 1009 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 1010 assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); 1011 } 1012 1013 // get and bitwise xor 1014 { 1015 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 1016 1017 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (short)0x4567); 1018 assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); 1019 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 1020 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); 1021 } 1022 1023 { 1024 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 1025 1026 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (short)0x4567); 1027 assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); 1028 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 1029 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); 1030 } 1031 1032 { 1033 hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); 1034 1035 short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (short)0x4567); 1036 assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); 1037 short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); 1038 assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); 1039 } 1040 } 1041 } 1042 1043 static void testArrayUnsupported(Handles hs) throws Throwable { 1044 short[] array = new short[10]; 1045 1046 final int i = 0; 1047 1048 1049 } 1050 1051 static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { 1052 short[] array = new short[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 short x = (short) 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, (short)0x0123); 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, (short)0x0123, (short)0x4567); 1072 }); 1073 } 1074 1075 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { 1076 checkAIOOBE(am, () -> { 1077 short r = (short) hs.get(am).invokeExact(array, ci, (short)0x4567, (short)0x0123); 1078 }); 1079 } 1080 1081 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { 1082 checkAIOOBE(am, () -> { 1083 short o = (short) hs.get(am).invokeExact(array, ci, (short)0x0123); 1084 }); 1085 } 1086 1087 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { 1088 checkAIOOBE(am, () -> { 1089 short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB); 1090 }); 1091 } 1092 1093 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) { 1094 checkAIOOBE(am, () -> { 1095 short o = (short) hs.get(am).invokeExact(array, ci, (short)0x89AB); 1096 }); 1097 } 1098 } 1099 } 1100 } 1101