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 VarHandleTestMethodHandleAccessByte |
| 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 VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 42 | static final byte static_final_v = (byte)0x01; |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 43 | |
| 44 | static byte static_v; |
| 45 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 46 | final byte final_v = (byte)0x01; |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 47 | |
| 48 | byte 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 | VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class); |
| 64 | |
| 65 | vhField = MethodHandles.lookup().findVarHandle( |
| 66 | VarHandleTestMethodHandleAccessByte.class, "v", byte.class); |
| 67 | |
| 68 | vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
| 69 | VarHandleTestMethodHandleAccessByte.class, "static_final_v", byte.class); |
| 70 | |
| 71 | vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
| 72 | VarHandleTestMethodHandleAccessByte.class, "static_v", byte.class); |
| 73 | |
| 74 | vhArray = MethodHandles.arrayElementVarHandle(byte[].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, VarHandleTestMethodHandleAccessByte::testStaticField)); |
| 91 | cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
| 92 | vhStaticField, f, VarHandleTestMethodHandleAccessByte::testStaticFieldUnsupported, |
| 93 | false)); |
| 94 | |
| 95 | cases.add(new MethodHandleAccessTestCase("Array", |
| 96 | vhArray, f, VarHandleTestMethodHandleAccessByte::testArray)); |
| 97 | cases.add(new MethodHandleAccessTestCase("Array unsupported", |
| 98 | vhArray, f, VarHandleTestMethodHandleAccessByte::testArrayUnsupported, |
| 99 | false)); |
| 100 | cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
| 101 | vhArray, f, VarHandleTestMethodHandleAccessByte::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(VarHandleTestMethodHandleAccessByte 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, (byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 125 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 126 | assertEquals(x, (byte)0x01, "set byte 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, (byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 133 | byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 134 | assertEquals(x, (byte)0x23, "setVolatile byte 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, (byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 140 | byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 141 | assertEquals(x, (byte)0x01, "setRelease byte 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, (byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 147 | byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 148 | assertEquals(x, (byte)0x23, "setOpaque byte 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, (byte)0x01); |
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, (byte)0x01, (byte)0x23); |
| 156 | assertEquals(r, true, "success compareAndSet byte"); |
| 157 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 158 | assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
| 159 | } |
| 160 | |
| 161 | { |
| 162 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45); |
| 163 | assertEquals(r, false, "failing compareAndSet byte"); |
| 164 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 165 | assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
| 166 | } |
| 167 | |
| 168 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 169 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x01); |
| 170 | assertEquals(r, (byte)0x23, "success compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 171 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 172 | assertEquals(x, (byte)0x01, "success compareAndExchange byte 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 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x45); |
| 177 | assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 178 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 179 | assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | { |
| 183 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23); |
| 184 | assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
| 185 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 186 | assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
| 187 | } |
| 188 | |
| 189 | { |
| 190 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45); |
| 191 | assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
| 192 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 193 | assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01); |
| 198 | assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
| 199 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 200 | assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
| 201 | } |
| 202 | |
| 203 | { |
| 204 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45); |
| 205 | assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
| 206 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 207 | assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte 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, (byte)0x01, (byte)0x23); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 216 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 217 | assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte 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, (byte)0x23, (byte)0x01); |
| 224 | } |
| 225 | assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
| 226 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 227 | assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
| 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, (byte)0x01, (byte)0x23); |
| 234 | } |
| 235 | assertEquals(success, true, "weakCompareAndSetRelease byte"); |
| 236 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 237 | assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
| 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, (byte)0x23, (byte)0x01); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 246 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 247 | assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Compare set and get |
| 251 | { |
| 252 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23); |
| 253 | assertEquals(o, (byte)0x01, "getAndSet byte"); |
| 254 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 255 | assertEquals(x, (byte)0x23, "getAndSet byte 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, (byte)0x01); |
| 261 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 262 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x23); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 263 | assertEquals(o, (byte)0x01, "getAndAdd byte"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 264 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 265 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte 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, (byte)0x01); |
| 270 | |
| 271 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (byte)0x23); |
| 272 | assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); |
| 273 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 274 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); |
| 275 | } |
| 276 | |
| 277 | { |
| 278 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 279 | |
| 280 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (byte)0x23); |
| 281 | assertEquals(o, (byte)0x01, "getAndAddRelease byte"); |
| 282 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 283 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); |
| 284 | } |
| 285 | |
| 286 | // get and bitwise or |
| 287 | { |
| 288 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 289 | |
| 290 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (byte)0x23); |
| 291 | assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); |
| 292 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 293 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); |
| 294 | } |
| 295 | |
| 296 | { |
| 297 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 298 | |
| 299 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (byte)0x23); |
| 300 | assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); |
| 301 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 302 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); |
| 303 | } |
| 304 | |
| 305 | { |
| 306 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 307 | |
| 308 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (byte)0x23); |
| 309 | assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); |
| 310 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 311 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); |
| 312 | } |
| 313 | |
| 314 | // get and bitwise and |
| 315 | { |
| 316 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 317 | |
| 318 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (byte)0x23); |
| 319 | assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); |
| 320 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 321 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); |
| 322 | } |
| 323 | |
| 324 | { |
| 325 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 326 | |
| 327 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (byte)0x23); |
| 328 | assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); |
| 329 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 330 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); |
| 331 | } |
| 332 | |
| 333 | { |
| 334 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 335 | |
| 336 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (byte)0x23); |
| 337 | assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); |
| 338 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 339 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); |
| 340 | } |
| 341 | |
| 342 | // get and bitwise xor |
| 343 | { |
| 344 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 345 | |
| 346 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (byte)0x23); |
| 347 | assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); |
| 348 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 349 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); |
| 350 | } |
| 351 | |
| 352 | { |
| 353 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 354 | |
| 355 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (byte)0x23); |
| 356 | assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); |
| 357 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 358 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); |
| 359 | } |
| 360 | |
| 361 | { |
| 362 | hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
| 363 | |
| 364 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (byte)0x23); |
| 365 | assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); |
| 366 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 367 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); |
| 368 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte 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((byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 381 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 382 | assertEquals(x, (byte)0x01, "set byte 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((byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 389 | byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 390 | assertEquals(x, (byte)0x23, "setVolatile byte 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((byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 396 | byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 397 | assertEquals(x, (byte)0x01, "setRelease byte 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((byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 403 | byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 404 | assertEquals(x, (byte)0x23, "setOpaque byte 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((byte)0x01); |
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((byte)0x01, (byte)0x23); |
| 412 | assertEquals(r, true, "success compareAndSet byte"); |
| 413 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 414 | assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
| 415 | } |
| 416 | |
| 417 | { |
| 418 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45); |
| 419 | assertEquals(r, false, "failing compareAndSet byte"); |
| 420 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 421 | assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
| 422 | } |
| 423 | |
| 424 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 425 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x01); |
| 426 | assertEquals(r, (byte)0x23, "success compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 427 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 428 | assertEquals(x, (byte)0x01, "success compareAndExchange byte 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 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x45); |
| 433 | assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 434 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 435 | assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | { |
| 439 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23); |
| 440 | assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
| 441 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 442 | assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
| 443 | } |
| 444 | |
| 445 | { |
| 446 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45); |
| 447 | assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
| 448 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 449 | assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
| 450 | } |
| 451 | |
| 452 | { |
| 453 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01); |
| 454 | assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
| 455 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 456 | assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
| 457 | } |
| 458 | |
| 459 | { |
| 460 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45); |
| 461 | assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
| 462 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 463 | assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte 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((byte)0x01, (byte)0x23); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 472 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 473 | assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte 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((byte)0x23, (byte)0x01); |
| 480 | } |
| 481 | assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
| 482 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 483 | assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
| 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((byte)0x01, (byte)0x23); |
| 490 | } |
| 491 | assertEquals(success, true, "weakCompareAndSetRelease byte"); |
| 492 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 493 | assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
| 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((byte)0x23, (byte)0x01); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 502 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 503 | assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); |
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((byte)0x01); |
| 509 | |
| 510 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact((byte)0x23); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 511 | assertEquals(o, (byte)0x01, "getAndSet byte"); |
| 512 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 513 | assertEquals(x, (byte)0x23, "getAndSet byte 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((byte)0x01); |
| 519 | |
| 520 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((byte)0x23); |
| 521 | assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); |
| 522 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 523 | assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); |
| 524 | } |
| 525 | |
| 526 | // Compare set and get |
| 527 | { |
| 528 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 529 | |
| 530 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((byte)0x23); |
| 531 | assertEquals(o, (byte)0x01, "getAndSetRelease byte"); |
| 532 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 533 | assertEquals(x, (byte)0x23, "getAndSetRelease byte 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((byte)0x01); |
| 539 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 540 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((byte)0x23); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 541 | assertEquals(o, (byte)0x01, "getAndAdd byte"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 542 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 543 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte 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((byte)0x01); |
| 548 | |
| 549 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((byte)0x23); |
| 550 | assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); |
| 551 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 552 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); |
| 553 | } |
| 554 | |
| 555 | { |
| 556 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 557 | |
| 558 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((byte)0x23); |
| 559 | assertEquals(o, (byte)0x01, "getAndAddRelease byte"); |
| 560 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 561 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); |
| 562 | } |
| 563 | |
| 564 | // get and bitwise or |
| 565 | { |
| 566 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 567 | |
| 568 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((byte)0x23); |
| 569 | assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); |
| 570 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 571 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); |
| 572 | } |
| 573 | |
| 574 | { |
| 575 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 576 | |
| 577 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((byte)0x23); |
| 578 | assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); |
| 579 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 580 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); |
| 581 | } |
| 582 | |
| 583 | { |
| 584 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 585 | |
| 586 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((byte)0x23); |
| 587 | assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); |
| 588 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 589 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); |
| 590 | } |
| 591 | |
| 592 | // get and bitwise and |
| 593 | { |
| 594 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 595 | |
| 596 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((byte)0x23); |
| 597 | assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); |
| 598 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 599 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); |
| 600 | } |
| 601 | |
| 602 | { |
| 603 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 604 | |
| 605 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((byte)0x23); |
| 606 | assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); |
| 607 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 608 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); |
| 609 | } |
| 610 | |
| 611 | { |
| 612 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 613 | |
| 614 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((byte)0x23); |
| 615 | assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); |
| 616 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 617 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); |
| 618 | } |
| 619 | |
| 620 | // get and bitwise xor |
| 621 | { |
| 622 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 623 | |
| 624 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((byte)0x23); |
| 625 | assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); |
| 626 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 627 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); |
| 628 | } |
| 629 | |
| 630 | { |
| 631 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 632 | |
| 633 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((byte)0x23); |
| 634 | assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); |
| 635 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 636 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); |
| 637 | } |
| 638 | |
| 639 | { |
| 640 | hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
| 641 | |
| 642 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((byte)0x23); |
| 643 | assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); |
| 644 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
| 645 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte 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 | byte[] array = new byte[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, (byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 662 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 663 | assertEquals(x, (byte)0x01, "get byte 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, (byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 670 | byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 671 | assertEquals(x, (byte)0x23, "setVolatile byte 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, (byte)0x01); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 677 | byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 678 | assertEquals(x, (byte)0x01, "setRelease byte 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, (byte)0x23); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 684 | byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 685 | assertEquals(x, (byte)0x23, "setOpaque byte 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, (byte)0x01); |
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, (byte)0x01, (byte)0x23); |
| 693 | assertEquals(r, true, "success compareAndSet byte"); |
| 694 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 695 | assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
| 696 | } |
| 697 | |
| 698 | { |
| 699 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45); |
| 700 | assertEquals(r, false, "failing compareAndSet byte"); |
| 701 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 702 | assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
| 703 | } |
| 704 | |
| 705 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 706 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
| 707 | assertEquals(r, (byte)0x23, "success compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 708 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 709 | assertEquals(x, (byte)0x01, "success compareAndExchange byte 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 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x45); |
| 714 | assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 715 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 716 | assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | { |
| 720 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23); |
| 721 | assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
| 722 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 723 | assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
| 724 | } |
| 725 | |
| 726 | { |
| 727 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45); |
| 728 | assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
| 729 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 730 | assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
| 731 | } |
| 732 | |
| 733 | { |
| 734 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
| 735 | assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
| 736 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 737 | assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
| 738 | } |
| 739 | |
| 740 | { |
| 741 | byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45); |
| 742 | assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
| 743 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 744 | assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte 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, (byte)0x01, (byte)0x23); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 753 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 754 | assertEquals(x, (byte)0x23, "weakCompareAndSetPlain byte 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, (byte)0x23, (byte)0x01); |
| 761 | } |
| 762 | assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
| 763 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 764 | assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
| 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, (byte)0x01, (byte)0x23); |
| 771 | } |
| 772 | assertEquals(success, true, "weakCompareAndSetRelease byte"); |
| 773 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 774 | assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
| 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, (byte)0x23, (byte)0x01); |
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 byte"); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 783 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 784 | assertEquals(x, (byte)0x01, "weakCompareAndSet byte"); |
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, (byte)0x01); |
| 790 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 791 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23); |
| 792 | assertEquals(o, (byte)0x01, "getAndSet byte"); |
| 793 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 794 | assertEquals(x, (byte)0x23, "getAndSet byte value"); |
| 795 | } |
| 796 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 797 | { |
| 798 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 799 | |
| 800 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23); |
| 801 | assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); |
| 802 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 803 | assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); |
| 804 | } |
| 805 | |
| 806 | { |
| 807 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 808 | |
| 809 | byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (byte)0x23); |
| 810 | assertEquals(o, (byte)0x01, "getAndSetRelease byte"); |
| 811 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 812 | assertEquals(x, (byte)0x23, "getAndSetRelease byte 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, (byte)0x01); |
| 818 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 819 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x23); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 820 | assertEquals(o, (byte)0x01, "getAndAdd byte"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 821 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 822 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte 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, (byte)0x01); |
| 827 | |
| 828 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (byte)0x23); |
| 829 | assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); |
| 830 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 831 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); |
| 832 | } |
| 833 | |
| 834 | { |
| 835 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 836 | |
| 837 | byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (byte)0x23); |
| 838 | assertEquals(o, (byte)0x01, "getAndAddRelease byte"); |
| 839 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 840 | assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); |
| 841 | } |
| 842 | |
| 843 | // get and bitwise or |
| 844 | { |
| 845 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 846 | |
| 847 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (byte)0x23); |
| 848 | assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); |
| 849 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 850 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); |
| 851 | } |
| 852 | |
| 853 | { |
| 854 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 855 | |
| 856 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (byte)0x23); |
| 857 | assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); |
| 858 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 859 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); |
| 860 | } |
| 861 | |
| 862 | { |
| 863 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 864 | |
| 865 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (byte)0x23); |
| 866 | assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); |
| 867 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 868 | assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); |
| 869 | } |
| 870 | |
| 871 | // get and bitwise and |
| 872 | { |
| 873 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 874 | |
| 875 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (byte)0x23); |
| 876 | assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); |
| 877 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 878 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); |
| 879 | } |
| 880 | |
| 881 | { |
| 882 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 883 | |
| 884 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (byte)0x23); |
| 885 | assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); |
| 886 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 887 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); |
| 888 | } |
| 889 | |
| 890 | { |
| 891 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 892 | |
| 893 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (byte)0x23); |
| 894 | assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); |
| 895 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 896 | assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); |
| 897 | } |
| 898 | |
| 899 | // get and bitwise xor |
| 900 | { |
| 901 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 902 | |
| 903 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (byte)0x23); |
| 904 | assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); |
| 905 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 906 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); |
| 907 | } |
| 908 | |
| 909 | { |
| 910 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 911 | |
| 912 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (byte)0x23); |
| 913 | assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); |
| 914 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 915 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); |
| 916 | } |
| 917 | |
| 918 | { |
| 919 | hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
| 920 | |
| 921 | byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (byte)0x23); |
| 922 | assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); |
| 923 | byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 924 | assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte 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 | byte[] array = new byte[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 | byte[] array = new byte[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 | byte x = (byte) 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, (byte)0x01); |
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, (byte)0x01, (byte)0x23); |
| 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 | byte r = (byte) hs.get(am).invokeExact(array, ci, (byte)0x23, (byte)0x01); |
| 964 | }); |
| 965 | } |
| 966 | |
| 967 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
| 968 | checkIOOBE(am, () -> { |
| 969 | byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x01); |
| 970 | }); |
| 971 | } |
| 972 | |
| 973 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
| 974 | checkIOOBE(am, () -> { |
| 975 | byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45); |
| 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 | byte o = (byte) hs.get(am).invokeExact(array, ci, (byte)0x45); |
| 982 | }); |
| 983 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | } |
| 987 | |