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