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