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