Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, 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=10 -Xint VarHandleTestAccessInt |
| 27 | * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt |
| 28 | * @run testng/othervm -Diters=20000 VarHandleTestAccessInt |
| 29 | * @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessInt |
| 30 | */ |
| 31 | |
| 32 | import org.testng.annotations.BeforeClass; |
| 33 | import org.testng.annotations.DataProvider; |
| 34 | import org.testng.annotations.Test; |
| 35 | |
| 36 | import java.lang.invoke.MethodHandles; |
| 37 | import java.lang.invoke.VarHandle; |
| 38 | import java.util.ArrayList; |
| 39 | import java.util.Arrays; |
| 40 | import java.util.List; |
| 41 | |
| 42 | import static org.testng.Assert.*; |
| 43 | |
| 44 | public class VarHandleTestAccessInt extends VarHandleBaseTest { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 45 | static final int static_final_v = 0x01234567; |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 46 | |
| 47 | static int static_v; |
| 48 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 49 | final int final_v = 0x01234567; |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 50 | |
| 51 | int v; |
| 52 | |
| 53 | VarHandle vhFinalField; |
| 54 | |
| 55 | VarHandle vhField; |
| 56 | |
| 57 | VarHandle vhStaticField; |
| 58 | |
| 59 | VarHandle vhStaticFinalField; |
| 60 | |
| 61 | VarHandle vhArray; |
| 62 | |
| 63 | @BeforeClass |
| 64 | public void setup() throws Exception { |
| 65 | vhFinalField = MethodHandles.lookup().findVarHandle( |
| 66 | VarHandleTestAccessInt.class, "final_v", int.class); |
| 67 | |
| 68 | vhField = MethodHandles.lookup().findVarHandle( |
| 69 | VarHandleTestAccessInt.class, "v", int.class); |
| 70 | |
| 71 | vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
| 72 | VarHandleTestAccessInt.class, "static_final_v", int.class); |
| 73 | |
| 74 | vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
| 75 | VarHandleTestAccessInt.class, "static_v", int.class); |
| 76 | |
| 77 | vhArray = MethodHandles.arrayElementVarHandle(int[].class); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | @DataProvider |
| 82 | public Object[][] varHandlesProvider() throws Exception { |
| 83 | List<VarHandle> vhs = new ArrayList<>(); |
| 84 | vhs.add(vhField); |
| 85 | vhs.add(vhStaticField); |
| 86 | vhs.add(vhArray); |
| 87 | |
| 88 | return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new); |
| 89 | } |
| 90 | |
| 91 | @Test(dataProvider = "varHandlesProvider") |
| 92 | public void testIsAccessModeSupported(VarHandle vh) { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 93 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); |
| 94 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); |
| 95 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE)); |
| 96 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE)); |
| 97 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE)); |
| 98 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE)); |
| 99 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); |
| 100 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 101 | |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 102 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 103 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE)); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 104 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); |
| 105 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 106 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_PLAIN)); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 107 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); |
| 108 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); |
| 109 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 110 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 111 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_ACQUIRE)); |
| 112 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET_RELEASE)); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 113 | |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 114 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 115 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_ACQUIRE)); |
| 116 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD_RELEASE)); |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 117 | |
| 118 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR)); |
| 119 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_ACQUIRE)); |
| 120 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_OR_RELEASE)); |
| 121 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND)); |
| 122 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_ACQUIRE)); |
| 123 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_AND_RELEASE)); |
| 124 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR)); |
| 125 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_ACQUIRE)); |
| 126 | assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
| 130 | @DataProvider |
| 131 | public Object[][] typesProvider() throws Exception { |
| 132 | List<Object[]> types = new ArrayList<>(); |
| 133 | types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessInt.class)}); |
| 134 | types.add(new Object[] {vhStaticField, Arrays.asList()}); |
| 135 | types.add(new Object[] {vhArray, Arrays.asList(int[].class, int.class)}); |
| 136 | |
| 137 | return types.stream().toArray(Object[][]::new); |
| 138 | } |
| 139 | |
| 140 | @Test(dataProvider = "typesProvider") |
| 141 | public void testTypes(VarHandle vh, List<Class<?>> pts) { |
| 142 | assertEquals(vh.varType(), int.class); |
| 143 | |
| 144 | assertEquals(vh.coordinateTypes(), pts); |
| 145 | |
| 146 | testTypes(vh); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | @Test |
| 151 | public void testLookupInstanceToStatic() { |
| 152 | checkIAE("Lookup of static final field to instance final field", () -> { |
| 153 | MethodHandles.lookup().findStaticVarHandle( |
| 154 | VarHandleTestAccessInt.class, "final_v", int.class); |
| 155 | }); |
| 156 | |
| 157 | checkIAE("Lookup of static field to instance field", () -> { |
| 158 | MethodHandles.lookup().findStaticVarHandle( |
| 159 | VarHandleTestAccessInt.class, "v", int.class); |
| 160 | }); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void testLookupStaticToInstance() { |
| 165 | checkIAE("Lookup of instance final field to static final field", () -> { |
| 166 | MethodHandles.lookup().findVarHandle( |
| 167 | VarHandleTestAccessInt.class, "static_final_v", int.class); |
| 168 | }); |
| 169 | |
| 170 | checkIAE("Lookup of instance field to static field", () -> { |
| 171 | vhStaticField = MethodHandles.lookup().findVarHandle( |
| 172 | VarHandleTestAccessInt.class, "static_v", int.class); |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | @DataProvider |
| 178 | public Object[][] accessTestCaseProvider() throws Exception { |
| 179 | List<AccessTestCase<?>> cases = new ArrayList<>(); |
| 180 | |
| 181 | cases.add(new VarHandleAccessTestCase("Instance final field", |
| 182 | vhFinalField, vh -> testInstanceFinalField(this, vh))); |
| 183 | cases.add(new VarHandleAccessTestCase("Instance final field unsupported", |
| 184 | vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh), |
| 185 | false)); |
| 186 | |
| 187 | cases.add(new VarHandleAccessTestCase("Static final field", |
| 188 | vhStaticFinalField, VarHandleTestAccessInt::testStaticFinalField)); |
| 189 | cases.add(new VarHandleAccessTestCase("Static final field unsupported", |
| 190 | vhStaticFinalField, VarHandleTestAccessInt::testStaticFinalFieldUnsupported, |
| 191 | false)); |
| 192 | |
| 193 | cases.add(new VarHandleAccessTestCase("Instance field", |
| 194 | vhField, vh -> testInstanceField(this, vh))); |
| 195 | cases.add(new VarHandleAccessTestCase("Instance field unsupported", |
| 196 | vhField, vh -> testInstanceFieldUnsupported(this, vh), |
| 197 | false)); |
| 198 | |
| 199 | cases.add(new VarHandleAccessTestCase("Static field", |
| 200 | vhStaticField, VarHandleTestAccessInt::testStaticField)); |
| 201 | cases.add(new VarHandleAccessTestCase("Static field unsupported", |
| 202 | vhStaticField, VarHandleTestAccessInt::testStaticFieldUnsupported, |
| 203 | false)); |
| 204 | |
| 205 | cases.add(new VarHandleAccessTestCase("Array", |
| 206 | vhArray, VarHandleTestAccessInt::testArray)); |
| 207 | cases.add(new VarHandleAccessTestCase("Array unsupported", |
| 208 | vhArray, VarHandleTestAccessInt::testArrayUnsupported, |
| 209 | false)); |
| 210 | cases.add(new VarHandleAccessTestCase("Array index out of bounds", |
| 211 | vhArray, VarHandleTestAccessInt::testArrayIndexOutOfBounds, |
| 212 | false)); |
| 213 | |
| 214 | // Work around issue with jtreg summary reporting which truncates |
| 215 | // the String result of Object.toString to 30 characters, hence |
| 216 | // the first dummy argument |
| 217 | return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
| 218 | } |
| 219 | |
| 220 | @Test(dataProvider = "accessTestCaseProvider") |
| 221 | public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { |
| 222 | T t = atc.get(); |
| 223 | int iters = atc.requiresLoop() ? ITERS : 1; |
| 224 | for (int c = 0; c < iters; c++) { |
| 225 | atc.testAccess(t); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | static void testInstanceFinalField(VarHandleTestAccessInt recv, VarHandle vh) { |
| 233 | // Plain |
| 234 | { |
| 235 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 236 | assertEquals(x, 0x01234567, "get int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
| 240 | // Volatile |
| 241 | { |
| 242 | int x = (int) vh.getVolatile(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 243 | assertEquals(x, 0x01234567, "getVolatile int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Lazy |
| 247 | { |
| 248 | int x = (int) vh.getAcquire(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 249 | assertEquals(x, 0x01234567, "getRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // Opaque |
| 253 | { |
| 254 | int x = (int) vh.getOpaque(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 255 | assertEquals(x, 0x01234567, "getOpaque int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 256 | } |
| 257 | } |
| 258 | |
| 259 | static void testInstanceFinalFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) { |
| 260 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 261 | vh.set(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 262 | }); |
| 263 | |
| 264 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 265 | vh.setVolatile(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 266 | }); |
| 267 | |
| 268 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 269 | vh.setRelease(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 270 | }); |
| 271 | |
| 272 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 273 | vh.setOpaque(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 274 | }); |
| 275 | |
| 276 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 277 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
| 281 | static void testStaticFinalField(VarHandle vh) { |
| 282 | // Plain |
| 283 | { |
| 284 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 285 | assertEquals(x, 0x01234567, "get int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
| 289 | // Volatile |
| 290 | { |
| 291 | int x = (int) vh.getVolatile(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 292 | assertEquals(x, 0x01234567, "getVolatile int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // Lazy |
| 296 | { |
| 297 | int x = (int) vh.getAcquire(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 298 | assertEquals(x, 0x01234567, "getRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | // Opaque |
| 302 | { |
| 303 | int x = (int) vh.getOpaque(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 304 | assertEquals(x, 0x01234567, "getOpaque int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
| 308 | static void testStaticFinalFieldUnsupported(VarHandle vh) { |
| 309 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 310 | vh.set(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 311 | }); |
| 312 | |
| 313 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 314 | vh.setVolatile(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 315 | }); |
| 316 | |
| 317 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 318 | vh.setRelease(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 319 | }); |
| 320 | |
| 321 | checkUOE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 322 | vh.setOpaque(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 323 | }); |
| 324 | |
| 325 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 326 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
| 330 | static void testInstanceField(VarHandleTestAccessInt recv, VarHandle vh) { |
| 331 | // Plain |
| 332 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 333 | vh.set(recv, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 334 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 335 | assertEquals(x, 0x01234567, "set int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
| 339 | // Volatile |
| 340 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 341 | vh.setVolatile(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 342 | int x = (int) vh.getVolatile(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 343 | assertEquals(x, 0x89ABCDEF, "setVolatile int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | // Lazy |
| 347 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 348 | vh.setRelease(recv, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 349 | int x = (int) vh.getAcquire(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 350 | assertEquals(x, 0x01234567, "setRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | // Opaque |
| 354 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 355 | vh.setOpaque(recv, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 356 | int x = (int) vh.getOpaque(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 357 | assertEquals(x, 0x89ABCDEF, "setOpaque int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 360 | vh.set(recv, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 361 | |
| 362 | // Compare |
| 363 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 364 | boolean r = vh.compareAndSet(recv, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 365 | assertEquals(r, true, "success compareAndSet int"); |
| 366 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 367 | assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 371 | boolean r = vh.compareAndSet(recv, 0x01234567, 0xCAFEBABE); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 372 | assertEquals(r, false, "failing compareAndSet int"); |
| 373 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 374 | assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 378 | int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0x01234567); |
| 379 | assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 380 | int x = (int) vh.get(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 381 | assertEquals(x, 0x01234567, "success compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 385 | int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0xCAFEBABE); |
| 386 | assertEquals(r, 0x01234567, "failing compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 387 | int x = (int) vh.get(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 388 | assertEquals(x, 0x01234567, "failing compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 392 | int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x89ABCDEF); |
| 393 | assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 394 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 395 | assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 399 | int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0xCAFEBABE); |
| 400 | assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 401 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 402 | assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 406 | int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0x01234567); |
| 407 | assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 408 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 409 | assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 413 | int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0xCAFEBABE); |
| 414 | assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 415 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 416 | assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 420 | boolean success = false; |
| 421 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 422 | success = vh.weakCompareAndSetPlain(recv, 0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 423 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 424 | assertEquals(success, true, "weakCompareAndSetPlain int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 425 | int x = (int) vh.get(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 426 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 430 | boolean success = false; |
| 431 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 432 | success = vh.weakCompareAndSetAcquire(recv, 0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 433 | } |
| 434 | assertEquals(success, true, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 435 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 436 | assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 440 | boolean success = false; |
| 441 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 442 | success = vh.weakCompareAndSetRelease(recv, 0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 443 | } |
| 444 | assertEquals(success, true, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 445 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 446 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 449 | { |
| 450 | boolean success = false; |
| 451 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 452 | success = vh.weakCompareAndSet(recv, 0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 453 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 454 | assertEquals(success, true, "weakCompareAndSet int"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 455 | int x = (int) vh.get(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 456 | assertEquals(x, 0x01234567, "weakCompareAndSet int value"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 457 | } |
| 458 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 459 | // Compare set and get |
| 460 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 461 | vh.set(recv, 0x01234567); |
| 462 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 463 | int o = (int) vh.getAndSet(recv, 0x89ABCDEF); |
| 464 | assertEquals(o, 0x01234567, "getAndSet int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 465 | int x = (int) vh.get(recv); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 466 | assertEquals(x, 0x89ABCDEF, "getAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 469 | { |
| 470 | vh.set(recv, 0x01234567); |
| 471 | |
| 472 | int o = (int) vh.getAndSetAcquire(recv, 0x89ABCDEF); |
| 473 | assertEquals(o, 0x01234567, "getAndSetAcquire int"); |
| 474 | int x = (int) vh.get(recv); |
| 475 | assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); |
| 476 | } |
| 477 | |
| 478 | { |
| 479 | vh.set(recv, 0x01234567); |
| 480 | |
| 481 | int o = (int) vh.getAndSetRelease(recv, 0x89ABCDEF); |
| 482 | assertEquals(o, 0x01234567, "getAndSetRelease int"); |
| 483 | int x = (int) vh.get(recv); |
| 484 | assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); |
| 485 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 486 | |
| 487 | // get and add, add and get |
| 488 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 489 | vh.set(recv, 0x01234567); |
| 490 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 491 | int o = (int) vh.getAndAdd(recv, 0x89ABCDEF); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 492 | assertEquals(o, 0x01234567, "getAndAdd int"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 493 | int x = (int) vh.get(recv); |
| 494 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 495 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 496 | |
| 497 | { |
| 498 | vh.set(recv, 0x01234567); |
| 499 | |
| 500 | int o = (int) vh.getAndAddAcquire(recv, 0x89ABCDEF); |
| 501 | assertEquals(o, 0x01234567, "getAndAddAcquire int"); |
| 502 | int x = (int) vh.get(recv); |
| 503 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); |
| 504 | } |
| 505 | |
| 506 | { |
| 507 | vh.set(recv, 0x01234567); |
| 508 | |
| 509 | int o = (int) vh.getAndAddRelease(recv, 0x89ABCDEF); |
| 510 | assertEquals(o, 0x01234567, "getAndAddReleaseint"); |
| 511 | int x = (int) vh.get(recv); |
| 512 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); |
| 513 | } |
| 514 | |
| 515 | // get and bitwise or |
| 516 | { |
| 517 | vh.set(recv, 0x01234567); |
| 518 | |
| 519 | int o = (int) vh.getAndBitwiseOr(recv, 0x89ABCDEF); |
| 520 | assertEquals(o, 0x01234567, "getAndBitwiseOr int"); |
| 521 | int x = (int) vh.get(recv); |
| 522 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); |
| 523 | } |
| 524 | |
| 525 | { |
| 526 | vh.set(recv, 0x01234567); |
| 527 | |
| 528 | int o = (int) vh.getAndBitwiseOrAcquire(recv, 0x89ABCDEF); |
| 529 | assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); |
| 530 | int x = (int) vh.get(recv); |
| 531 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); |
| 532 | } |
| 533 | |
| 534 | { |
| 535 | vh.set(recv, 0x01234567); |
| 536 | |
| 537 | int o = (int) vh.getAndBitwiseOrRelease(recv, 0x89ABCDEF); |
| 538 | assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); |
| 539 | int x = (int) vh.get(recv); |
| 540 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); |
| 541 | } |
| 542 | |
| 543 | // get and bitwise and |
| 544 | { |
| 545 | vh.set(recv, 0x01234567); |
| 546 | |
| 547 | int o = (int) vh.getAndBitwiseAnd(recv, 0x89ABCDEF); |
| 548 | assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); |
| 549 | int x = (int) vh.get(recv); |
| 550 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); |
| 551 | } |
| 552 | |
| 553 | { |
| 554 | vh.set(recv, 0x01234567); |
| 555 | |
| 556 | int o = (int) vh.getAndBitwiseAndAcquire(recv, 0x89ABCDEF); |
| 557 | assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); |
| 558 | int x = (int) vh.get(recv); |
| 559 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); |
| 560 | } |
| 561 | |
| 562 | { |
| 563 | vh.set(recv, 0x01234567); |
| 564 | |
| 565 | int o = (int) vh.getAndBitwiseAndRelease(recv, 0x89ABCDEF); |
| 566 | assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); |
| 567 | int x = (int) vh.get(recv); |
| 568 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); |
| 569 | } |
| 570 | |
| 571 | // get and bitwise xor |
| 572 | { |
| 573 | vh.set(recv, 0x01234567); |
| 574 | |
| 575 | int o = (int) vh.getAndBitwiseXor(recv, 0x89ABCDEF); |
| 576 | assertEquals(o, 0x01234567, "getAndBitwiseXor int"); |
| 577 | int x = (int) vh.get(recv); |
| 578 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); |
| 579 | } |
| 580 | |
| 581 | { |
| 582 | vh.set(recv, 0x01234567); |
| 583 | |
| 584 | int o = (int) vh.getAndBitwiseXorAcquire(recv, 0x89ABCDEF); |
| 585 | assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); |
| 586 | int x = (int) vh.get(recv); |
| 587 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); |
| 588 | } |
| 589 | |
| 590 | { |
| 591 | vh.set(recv, 0x01234567); |
| 592 | |
| 593 | int o = (int) vh.getAndBitwiseXorRelease(recv, 0x89ABCDEF); |
| 594 | assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); |
| 595 | int x = (int) vh.get(recv); |
| 596 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); |
| 597 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void testInstanceFieldUnsupported(VarHandleTestAccessInt recv, VarHandle vh) { |
| 601 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 602 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
| 606 | static void testStaticField(VarHandle vh) { |
| 607 | // Plain |
| 608 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 609 | vh.set(0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 610 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 611 | assertEquals(x, 0x01234567, "set int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | |
| 615 | // Volatile |
| 616 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 617 | vh.setVolatile(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 618 | int x = (int) vh.getVolatile(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 619 | assertEquals(x, 0x89ABCDEF, "setVolatile int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // Lazy |
| 623 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 624 | vh.setRelease(0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 625 | int x = (int) vh.getAcquire(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 626 | assertEquals(x, 0x01234567, "setRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | // Opaque |
| 630 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 631 | vh.setOpaque(0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 632 | int x = (int) vh.getOpaque(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 633 | assertEquals(x, 0x89ABCDEF, "setOpaque int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 634 | } |
| 635 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 636 | vh.set(0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 637 | |
| 638 | // Compare |
| 639 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 640 | boolean r = vh.compareAndSet(0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 641 | assertEquals(r, true, "success compareAndSet int"); |
| 642 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 643 | assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 647 | boolean r = vh.compareAndSet(0x01234567, 0xCAFEBABE); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 648 | assertEquals(r, false, "failing compareAndSet int"); |
| 649 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 650 | assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 654 | int r = (int) vh.compareAndExchange(0x89ABCDEF, 0x01234567); |
| 655 | assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 656 | int x = (int) vh.get(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 657 | assertEquals(x, 0x01234567, "success compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 661 | int r = (int) vh.compareAndExchange(0x89ABCDEF, 0xCAFEBABE); |
| 662 | assertEquals(r, 0x01234567, "failing compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 663 | int x = (int) vh.get(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 664 | assertEquals(x, 0x01234567, "failing compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 668 | int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0x89ABCDEF); |
| 669 | assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 670 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 671 | assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 675 | int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0xCAFEBABE); |
| 676 | assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 677 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 678 | assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 682 | int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0x01234567); |
| 683 | assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 684 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 685 | assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 689 | int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0xCAFEBABE); |
| 690 | assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 691 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 692 | assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 696 | boolean success = false; |
| 697 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 698 | success = vh.weakCompareAndSetPlain(0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 699 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 700 | assertEquals(success, true, "weakCompareAndSetPlain int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 701 | int x = (int) vh.get(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 702 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 706 | boolean success = false; |
| 707 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 708 | success = vh.weakCompareAndSetAcquire(0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 709 | } |
| 710 | assertEquals(success, true, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 711 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 712 | assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 716 | boolean success = false; |
| 717 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 718 | success = vh.weakCompareAndSetRelease(0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 719 | } |
| 720 | assertEquals(success, true, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 721 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 722 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 725 | { |
| 726 | boolean success = false; |
| 727 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 728 | success = vh.weakCompareAndSet(0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 729 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 730 | assertEquals(success, true, "weakCompareAndSet int"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 731 | int x = (int) vh.get(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 732 | assertEquals(x, 0x01234567, "weakCompareAndSet int"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 733 | } |
| 734 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 735 | // Compare set and get |
| 736 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 737 | vh.set(0x01234567); |
| 738 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 739 | int o = (int) vh.getAndSet(0x89ABCDEF); |
| 740 | assertEquals(o, 0x01234567, "getAndSet int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 741 | int x = (int) vh.get(); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 742 | assertEquals(x, 0x89ABCDEF, "getAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 743 | } |
| 744 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 745 | { |
| 746 | vh.set(0x01234567); |
| 747 | |
| 748 | int o = (int) vh.getAndSetAcquire(0x89ABCDEF); |
| 749 | assertEquals(o, 0x01234567, "getAndSetAcquire int"); |
| 750 | int x = (int) vh.get(); |
| 751 | assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); |
| 752 | } |
| 753 | |
| 754 | { |
| 755 | vh.set(0x01234567); |
| 756 | |
| 757 | int o = (int) vh.getAndSetRelease(0x89ABCDEF); |
| 758 | assertEquals(o, 0x01234567, "getAndSetRelease int"); |
| 759 | int x = (int) vh.get(); |
| 760 | assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); |
| 761 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 762 | |
| 763 | // get and add, add and get |
| 764 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 765 | vh.set(0x01234567); |
| 766 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 767 | int o = (int) vh.getAndAdd(0x89ABCDEF); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 768 | assertEquals(o, 0x01234567, "getAndAdd int"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 769 | int x = (int) vh.get(); |
| 770 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 771 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 772 | |
| 773 | { |
| 774 | vh.set(0x01234567); |
| 775 | |
| 776 | int o = (int) vh.getAndAddAcquire(0x89ABCDEF); |
| 777 | assertEquals(o, 0x01234567, "getAndAddAcquire int"); |
| 778 | int x = (int) vh.get(); |
| 779 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); |
| 780 | } |
| 781 | |
| 782 | { |
| 783 | vh.set(0x01234567); |
| 784 | |
| 785 | int o = (int) vh.getAndAddRelease(0x89ABCDEF); |
| 786 | assertEquals(o, 0x01234567, "getAndAddReleaseint"); |
| 787 | int x = (int) vh.get(); |
| 788 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); |
| 789 | } |
| 790 | |
| 791 | // get and bitwise or |
| 792 | { |
| 793 | vh.set(0x01234567); |
| 794 | |
| 795 | int o = (int) vh.getAndBitwiseOr(0x89ABCDEF); |
| 796 | assertEquals(o, 0x01234567, "getAndBitwiseOr int"); |
| 797 | int x = (int) vh.get(); |
| 798 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); |
| 799 | } |
| 800 | |
| 801 | { |
| 802 | vh.set(0x01234567); |
| 803 | |
| 804 | int o = (int) vh.getAndBitwiseOrAcquire(0x89ABCDEF); |
| 805 | assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); |
| 806 | int x = (int) vh.get(); |
| 807 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); |
| 808 | } |
| 809 | |
| 810 | { |
| 811 | vh.set(0x01234567); |
| 812 | |
| 813 | int o = (int) vh.getAndBitwiseOrRelease(0x89ABCDEF); |
| 814 | assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); |
| 815 | int x = (int) vh.get(); |
| 816 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); |
| 817 | } |
| 818 | |
| 819 | // get and bitwise and |
| 820 | { |
| 821 | vh.set(0x01234567); |
| 822 | |
| 823 | int o = (int) vh.getAndBitwiseAnd(0x89ABCDEF); |
| 824 | assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); |
| 825 | int x = (int) vh.get(); |
| 826 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); |
| 827 | } |
| 828 | |
| 829 | { |
| 830 | vh.set(0x01234567); |
| 831 | |
| 832 | int o = (int) vh.getAndBitwiseAndAcquire(0x89ABCDEF); |
| 833 | assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); |
| 834 | int x = (int) vh.get(); |
| 835 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); |
| 836 | } |
| 837 | |
| 838 | { |
| 839 | vh.set(0x01234567); |
| 840 | |
| 841 | int o = (int) vh.getAndBitwiseAndRelease(0x89ABCDEF); |
| 842 | assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); |
| 843 | int x = (int) vh.get(); |
| 844 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); |
| 845 | } |
| 846 | |
| 847 | // get and bitwise xor |
| 848 | { |
| 849 | vh.set(0x01234567); |
| 850 | |
| 851 | int o = (int) vh.getAndBitwiseXor(0x89ABCDEF); |
| 852 | assertEquals(o, 0x01234567, "getAndBitwiseXor int"); |
| 853 | int x = (int) vh.get(); |
| 854 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); |
| 855 | } |
| 856 | |
| 857 | { |
| 858 | vh.set(0x01234567); |
| 859 | |
| 860 | int o = (int) vh.getAndBitwiseXorAcquire(0x89ABCDEF); |
| 861 | assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); |
| 862 | int x = (int) vh.get(); |
| 863 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); |
| 864 | } |
| 865 | |
| 866 | { |
| 867 | vh.set(0x01234567); |
| 868 | |
| 869 | int o = (int) vh.getAndBitwiseXorRelease(0x89ABCDEF); |
| 870 | assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); |
| 871 | int x = (int) vh.get(); |
| 872 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); |
| 873 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static void testStaticFieldUnsupported(VarHandle vh) { |
| 877 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 878 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
| 882 | static void testArray(VarHandle vh) { |
| 883 | int[] array = new int[10]; |
| 884 | |
| 885 | for (int i = 0; i < array.length; i++) { |
| 886 | // Plain |
| 887 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 888 | vh.set(array, i, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 889 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 890 | assertEquals(x, 0x01234567, "get int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | |
| 894 | // Volatile |
| 895 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 896 | vh.setVolatile(array, i, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 897 | int x = (int) vh.getVolatile(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 898 | assertEquals(x, 0x89ABCDEF, "setVolatile int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | // Lazy |
| 902 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 903 | vh.setRelease(array, i, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 904 | int x = (int) vh.getAcquire(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 905 | assertEquals(x, 0x01234567, "setRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | // Opaque |
| 909 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 910 | vh.setOpaque(array, i, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 911 | int x = (int) vh.getOpaque(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 912 | assertEquals(x, 0x89ABCDEF, "setOpaque int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 915 | vh.set(array, i, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 916 | |
| 917 | // Compare |
| 918 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 919 | boolean r = vh.compareAndSet(array, i, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 920 | assertEquals(r, true, "success compareAndSet int"); |
| 921 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 922 | assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 926 | boolean r = vh.compareAndSet(array, i, 0x01234567, 0xCAFEBABE); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 927 | assertEquals(r, false, "failing compareAndSet int"); |
| 928 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 929 | assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 933 | int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0x01234567); |
| 934 | assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 935 | int x = (int) vh.get(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 936 | assertEquals(x, 0x01234567, "success compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 940 | int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0xCAFEBABE); |
| 941 | assertEquals(r, 0x01234567, "failing compareAndExchange int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 942 | int x = (int) vh.get(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 943 | assertEquals(x, 0x01234567, "failing compareAndExchange int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 947 | int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0x89ABCDEF); |
| 948 | assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 949 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 950 | assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 954 | int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0xCAFEBABE); |
| 955 | assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 956 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 957 | assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 961 | int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0x01234567); |
| 962 | assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 963 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 964 | assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 968 | int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0xCAFEBABE); |
| 969 | assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 970 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 971 | assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 975 | boolean success = false; |
| 976 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 977 | success = vh.weakCompareAndSetPlain(array, i, 0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 978 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 979 | assertEquals(success, true, "weakCompareAndSetPlain int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 980 | int x = (int) vh.get(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 981 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetPlain int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 985 | boolean success = false; |
| 986 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 987 | success = vh.weakCompareAndSetAcquire(array, i, 0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 988 | } |
| 989 | assertEquals(success, true, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 990 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 991 | assertEquals(x, 0x01234567, "weakCompareAndSetAcquire int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | { |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 995 | boolean success = false; |
| 996 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 997 | success = vh.weakCompareAndSetRelease(array, i, 0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 4f53885 | 2016-05-04 17:17:28 +0300 | [diff] [blame] | 998 | } |
| 999 | assertEquals(success, true, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1000 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1001 | assertEquals(x, 0x89ABCDEF, "weakCompareAndSetRelease int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 1004 | { |
| 1005 | boolean success = false; |
| 1006 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 1007 | success = vh.weakCompareAndSet(array, i, 0x89ABCDEF, 0x01234567); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 1008 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 1009 | assertEquals(success, true, "weakCompareAndSet int"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 1010 | int x = (int) vh.get(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 1011 | assertEquals(x, 0x01234567, "weakCompareAndSet int"); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 1012 | } |
| 1013 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1014 | // Compare set and get |
| 1015 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1016 | vh.set(array, i, 0x01234567); |
| 1017 | |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1018 | int o = (int) vh.getAndSet(array, i, 0x89ABCDEF); |
| 1019 | assertEquals(o, 0x01234567, "getAndSet int"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1020 | int x = (int) vh.get(array, i); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1021 | assertEquals(x, 0x89ABCDEF, "getAndSet int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1022 | } |
| 1023 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1024 | { |
| 1025 | vh.set(array, i, 0x01234567); |
| 1026 | |
| 1027 | int o = (int) vh.getAndSetAcquire(array, i, 0x89ABCDEF); |
| 1028 | assertEquals(o, 0x01234567, "getAndSetAcquire int"); |
| 1029 | int x = (int) vh.get(array, i); |
| 1030 | assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); |
| 1031 | } |
| 1032 | |
| 1033 | { |
| 1034 | vh.set(array, i, 0x01234567); |
| 1035 | |
| 1036 | int o = (int) vh.getAndSetRelease(array, i, 0x89ABCDEF); |
| 1037 | assertEquals(o, 0x01234567, "getAndSetRelease int"); |
| 1038 | int x = (int) vh.get(array, i); |
| 1039 | assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); |
| 1040 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1041 | |
| 1042 | // get and add, add and get |
| 1043 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1044 | vh.set(array, i, 0x01234567); |
| 1045 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 1046 | int o = (int) vh.getAndAdd(array, i, 0x89ABCDEF); |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1047 | assertEquals(o, 0x01234567, "getAndAdd int"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 1048 | int x = (int) vh.get(array, i); |
| 1049 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1050 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1051 | |
| 1052 | { |
| 1053 | vh.set(array, i, 0x01234567); |
| 1054 | |
| 1055 | int o = (int) vh.getAndAddAcquire(array, i, 0x89ABCDEF); |
| 1056 | assertEquals(o, 0x01234567, "getAndAddAcquire int"); |
| 1057 | int x = (int) vh.get(array, i); |
| 1058 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); |
| 1059 | } |
| 1060 | |
| 1061 | { |
| 1062 | vh.set(array, i, 0x01234567); |
| 1063 | |
| 1064 | int o = (int) vh.getAndAddRelease(array, i, 0x89ABCDEF); |
| 1065 | assertEquals(o, 0x01234567, "getAndAddReleaseint"); |
| 1066 | int x = (int) vh.get(array, i); |
| 1067 | assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); |
| 1068 | } |
| 1069 | |
| 1070 | // get and bitwise or |
| 1071 | { |
| 1072 | vh.set(array, i, 0x01234567); |
| 1073 | |
| 1074 | int o = (int) vh.getAndBitwiseOr(array, i, 0x89ABCDEF); |
| 1075 | assertEquals(o, 0x01234567, "getAndBitwiseOr int"); |
| 1076 | int x = (int) vh.get(array, i); |
| 1077 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); |
| 1078 | } |
| 1079 | |
| 1080 | { |
| 1081 | vh.set(array, i, 0x01234567); |
| 1082 | |
| 1083 | int o = (int) vh.getAndBitwiseOrAcquire(array, i, 0x89ABCDEF); |
| 1084 | assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); |
| 1085 | int x = (int) vh.get(array, i); |
| 1086 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); |
| 1087 | } |
| 1088 | |
| 1089 | { |
| 1090 | vh.set(array, i, 0x01234567); |
| 1091 | |
| 1092 | int o = (int) vh.getAndBitwiseOrRelease(array, i, 0x89ABCDEF); |
| 1093 | assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); |
| 1094 | int x = (int) vh.get(array, i); |
| 1095 | assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); |
| 1096 | } |
| 1097 | |
| 1098 | // get and bitwise and |
| 1099 | { |
| 1100 | vh.set(array, i, 0x01234567); |
| 1101 | |
| 1102 | int o = (int) vh.getAndBitwiseAnd(array, i, 0x89ABCDEF); |
| 1103 | assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); |
| 1104 | int x = (int) vh.get(array, i); |
| 1105 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); |
| 1106 | } |
| 1107 | |
| 1108 | { |
| 1109 | vh.set(array, i, 0x01234567); |
| 1110 | |
| 1111 | int o = (int) vh.getAndBitwiseAndAcquire(array, i, 0x89ABCDEF); |
| 1112 | assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); |
| 1113 | int x = (int) vh.get(array, i); |
| 1114 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); |
| 1115 | } |
| 1116 | |
| 1117 | { |
| 1118 | vh.set(array, i, 0x01234567); |
| 1119 | |
| 1120 | int o = (int) vh.getAndBitwiseAndRelease(array, i, 0x89ABCDEF); |
| 1121 | assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); |
| 1122 | int x = (int) vh.get(array, i); |
| 1123 | assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); |
| 1124 | } |
| 1125 | |
| 1126 | // get and bitwise xor |
| 1127 | { |
| 1128 | vh.set(array, i, 0x01234567); |
| 1129 | |
| 1130 | int o = (int) vh.getAndBitwiseXor(array, i, 0x89ABCDEF); |
| 1131 | assertEquals(o, 0x01234567, "getAndBitwiseXor int"); |
| 1132 | int x = (int) vh.get(array, i); |
| 1133 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); |
| 1134 | } |
| 1135 | |
| 1136 | { |
| 1137 | vh.set(array, i, 0x01234567); |
| 1138 | |
| 1139 | int o = (int) vh.getAndBitwiseXorAcquire(array, i, 0x89ABCDEF); |
| 1140 | assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); |
| 1141 | int x = (int) vh.get(array, i); |
| 1142 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); |
| 1143 | } |
| 1144 | |
| 1145 | { |
| 1146 | vh.set(array, i, 0x01234567); |
| 1147 | |
| 1148 | int o = (int) vh.getAndBitwiseXorRelease(array, i, 0x89ABCDEF); |
| 1149 | assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); |
| 1150 | int x = (int) vh.get(array, i); |
| 1151 | assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); |
| 1152 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | static void testArrayUnsupported(VarHandle vh) { |
| 1157 | int[] array = new int[10]; |
| 1158 | |
| 1159 | int i = 0; |
| 1160 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1161 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { |
| 1165 | int[] array = new int[10]; |
| 1166 | |
| 1167 | for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
| 1168 | final int ci = i; |
| 1169 | |
| 1170 | checkIOOBE(() -> { |
| 1171 | int x = (int) vh.get(array, ci); |
| 1172 | }); |
| 1173 | |
| 1174 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1175 | vh.set(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1176 | }); |
| 1177 | |
| 1178 | checkIOOBE(() -> { |
| 1179 | int x = (int) vh.getVolatile(array, ci); |
| 1180 | }); |
| 1181 | |
| 1182 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1183 | vh.setVolatile(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1184 | }); |
| 1185 | |
| 1186 | checkIOOBE(() -> { |
| 1187 | int x = (int) vh.getAcquire(array, ci); |
| 1188 | }); |
| 1189 | |
| 1190 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1191 | vh.setRelease(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1192 | }); |
| 1193 | |
| 1194 | checkIOOBE(() -> { |
| 1195 | int x = (int) vh.getOpaque(array, ci); |
| 1196 | }); |
| 1197 | |
| 1198 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1199 | vh.setOpaque(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1200 | }); |
| 1201 | |
| 1202 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1203 | boolean r = vh.compareAndSet(array, ci, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1204 | }); |
| 1205 | |
| 1206 | checkIOOBE(() -> { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 1207 | int r = (int) vh.compareAndExchange(array, ci, 0x89ABCDEF, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1208 | }); |
| 1209 | |
| 1210 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1211 | int r = (int) vh.compareAndExchangeAcquire(array, ci, 0x89ABCDEF, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1212 | }); |
| 1213 | |
| 1214 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1215 | int r = (int) vh.compareAndExchangeRelease(array, ci, 0x89ABCDEF, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1216 | }); |
| 1217 | |
| 1218 | checkIOOBE(() -> { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 1219 | boolean r = vh.weakCompareAndSetPlain(array, ci, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1220 | }); |
| 1221 | |
| 1222 | checkIOOBE(() -> { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 1223 | boolean r = vh.weakCompareAndSet(array, ci, 0x01234567, 0x89ABCDEF); |
Aleksey Shipilev | 33bb922 | 2016-05-17 22:28:00 +0300 | [diff] [blame] | 1224 | }); |
| 1225 | |
| 1226 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1227 | boolean r = vh.weakCompareAndSetAcquire(array, ci, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1228 | }); |
| 1229 | |
| 1230 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1231 | boolean r = vh.weakCompareAndSetRelease(array, ci, 0x01234567, 0x89ABCDEF); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1232 | }); |
| 1233 | |
| 1234 | checkIOOBE(() -> { |
Aleksey Shipilev | e663206 | 2016-06-15 11:20:15 +0300 | [diff] [blame] | 1235 | int o = (int) vh.getAndSet(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1236 | }); |
| 1237 | |
| 1238 | checkIOOBE(() -> { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1239 | int o = (int) vh.getAndSetAcquire(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1240 | }); |
| 1241 | |
| 1242 | checkIOOBE(() -> { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1243 | int o = (int) vh.getAndSetRelease(array, ci, 0x01234567); |
| 1244 | }); |
| 1245 | |
| 1246 | checkIOOBE(() -> { |
| 1247 | int o = (int) vh.getAndAdd(array, ci, 0x01234567); |
| 1248 | }); |
| 1249 | |
| 1250 | checkIOOBE(() -> { |
| 1251 | int o = (int) vh.getAndAddAcquire(array, ci, 0x01234567); |
| 1252 | }); |
| 1253 | |
| 1254 | checkIOOBE(() -> { |
| 1255 | int o = (int) vh.getAndAddRelease(array, ci, 0x01234567); |
| 1256 | }); |
| 1257 | |
| 1258 | checkIOOBE(() -> { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 1259 | int o = (int) vh.getAndBitwiseOr(array, ci, 0x01234567); |
| 1260 | }); |
| 1261 | |
| 1262 | checkIOOBE(() -> { |
| 1263 | int o = (int) vh.getAndBitwiseOrAcquire(array, ci, 0x01234567); |
| 1264 | }); |
| 1265 | |
| 1266 | checkIOOBE(() -> { |
| 1267 | int o = (int) vh.getAndBitwiseOrRelease(array, ci, 0x01234567); |
| 1268 | }); |
| 1269 | |
| 1270 | checkIOOBE(() -> { |
| 1271 | int o = (int) vh.getAndBitwiseAnd(array, ci, 0x01234567); |
| 1272 | }); |
| 1273 | |
| 1274 | checkIOOBE(() -> { |
| 1275 | int o = (int) vh.getAndBitwiseAndAcquire(array, ci, 0x01234567); |
| 1276 | }); |
| 1277 | |
| 1278 | checkIOOBE(() -> { |
| 1279 | int o = (int) vh.getAndBitwiseAndRelease(array, ci, 0x01234567); |
| 1280 | }); |
| 1281 | |
| 1282 | checkIOOBE(() -> { |
| 1283 | int o = (int) vh.getAndBitwiseXor(array, ci, 0x01234567); |
| 1284 | }); |
| 1285 | |
| 1286 | checkIOOBE(() -> { |
| 1287 | int o = (int) vh.getAndBitwiseXorAcquire(array, ci, 0x01234567); |
| 1288 | }); |
| 1289 | |
| 1290 | checkIOOBE(() -> { |
| 1291 | int o = (int) vh.getAndBitwiseXorRelease(array, ci, 0x01234567); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 1292 | }); |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | |