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