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 VarHandleTestMethodHandleAccessFloat |
| 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 VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { |
| 42 | static final float static_final_v = 1.0f; |
| 43 | |
| 44 | static float static_v; |
| 45 | |
| 46 | final float final_v = 1.0f; |
| 47 | |
| 48 | float 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 | VarHandleTestMethodHandleAccessFloat.class, "final_v", float.class); |
| 64 | |
| 65 | vhField = MethodHandles.lookup().findVarHandle( |
| 66 | VarHandleTestMethodHandleAccessFloat.class, "v", float.class); |
| 67 | |
| 68 | vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
| 69 | VarHandleTestMethodHandleAccessFloat.class, "static_final_v", float.class); |
| 70 | |
| 71 | vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
| 72 | VarHandleTestMethodHandleAccessFloat.class, "static_v", float.class); |
| 73 | |
| 74 | vhArray = MethodHandles.arrayElementVarHandle(float[].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, VarHandleTestMethodHandleAccessFloat::testStaticField)); |
| 91 | cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
| 92 | vhStaticField, f, VarHandleTestMethodHandleAccessFloat::testStaticFieldUnsupported, |
| 93 | false)); |
| 94 | |
| 95 | cases.add(new MethodHandleAccessTestCase("Array", |
| 96 | vhArray, f, VarHandleTestMethodHandleAccessFloat::testArray)); |
| 97 | cases.add(new MethodHandleAccessTestCase("Array unsupported", |
| 98 | vhArray, f, VarHandleTestMethodHandleAccessFloat::testArrayUnsupported, |
| 99 | false)); |
| 100 | cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
| 101 | vhArray, f, VarHandleTestMethodHandleAccessFloat::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(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable { |
| 122 | // Plain |
| 123 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 124 | hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); |
| 125 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 126 | assertEquals(x, 1.0f, "set float value"); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | // Volatile |
| 131 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 132 | hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0f); |
| 133 | float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 134 | assertEquals(x, 2.0f, "setVolatile float value"); |
| 135 | } |
| 136 | |
| 137 | // Lazy |
| 138 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 139 | hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0f); |
| 140 | float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 141 | assertEquals(x, 1.0f, "setRelease float value"); |
| 142 | } |
| 143 | |
| 144 | // Opaque |
| 145 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 146 | hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0f); |
| 147 | float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 148 | assertEquals(x, 2.0f, "setOpaque float value"); |
| 149 | } |
| 150 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 151 | hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 152 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 153 | // Compare |
| 154 | { |
| 155 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f); |
| 156 | assertEquals(r, true, "success compareAndSet float"); |
| 157 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 158 | assertEquals(x, 2.0f, "success compareAndSet float value"); |
| 159 | } |
| 160 | |
| 161 | { |
| 162 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f); |
| 163 | assertEquals(r, false, "failing compareAndSet float"); |
| 164 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 165 | assertEquals(x, 2.0f, "failing compareAndSet float value"); |
| 166 | } |
| 167 | |
| 168 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 169 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f); |
| 170 | assertEquals(r, 2.0f, "success compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 171 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 172 | assertEquals(x, 1.0f, "success compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 176 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f); |
| 177 | assertEquals(r, 1.0f, "failing compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 178 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 179 | assertEquals(x, 1.0f, "failing compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | { |
| 183 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f); |
| 184 | assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); |
| 185 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 186 | assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); |
| 187 | } |
| 188 | |
| 189 | { |
| 190 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f); |
| 191 | assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); |
| 192 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 193 | assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f); |
| 198 | assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); |
| 199 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 200 | assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); |
| 201 | } |
| 202 | |
| 203 | { |
| 204 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f); |
| 205 | assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); |
| 206 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 207 | assertEquals(x, 1.0f, "failing compareAndExchangeRelease float 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, 1.0f, 2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 214 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 215 | assertEquals(success, true, "weakCompareAndSetPlain float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 216 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 217 | assertEquals(x, 2.0f, "weakCompareAndSetPlain float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [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, 2.0f, 1.0f); |
| 224 | } |
| 225 | assertEquals(success, true, "weakCompareAndSetAcquire float"); |
| 226 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 227 | assertEquals(x, 1.0f, "weakCompareAndSetAcquire float"); |
| 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, 1.0f, 2.0f); |
| 234 | } |
| 235 | assertEquals(success, true, "weakCompareAndSetRelease float"); |
| 236 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 237 | assertEquals(x, 2.0f, "weakCompareAndSetRelease float"); |
| 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, 2.0f, 1.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 244 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 245 | assertEquals(success, true, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 246 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 247 | assertEquals(x, 1.0f, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | // Compare set and get |
| 251 | { |
| 252 | float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0f); |
| 253 | assertEquals(o, 1.0f, "getAndSet float"); |
| 254 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 255 | assertEquals(x, 2.0f, "getAndSet float value"); |
| 256 | } |
| 257 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [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, 1.0f); |
| 261 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 262 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 263 | assertEquals(o, 1.0f, "getAndAdd float"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 264 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 265 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 266 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 267 | |
| 268 | { |
| 269 | hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); |
| 270 | |
| 271 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0f); |
| 272 | assertEquals(o, 1.0f, "getAndAddAcquire float"); |
| 273 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 274 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); |
| 275 | } |
| 276 | |
| 277 | { |
| 278 | hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); |
| 279 | |
| 280 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0f); |
| 281 | assertEquals(o, 1.0f, "getAndAddRelease float"); |
| 282 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); |
| 283 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); |
| 284 | } |
| 285 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable { |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 289 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 290 | |
| 291 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) { |
| 292 | checkUOE(am, () -> { |
| 293 | float r = (float) hs.get(am).invokeExact(recv, 1.0f); |
| 294 | }); |
| 295 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
| 299 | static void testStaticField(Handles hs) throws Throwable { |
| 300 | // Plain |
| 301 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 302 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 303 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 304 | assertEquals(x, 1.0f, "set float value"); |
| 305 | } |
| 306 | |
| 307 | |
| 308 | // Volatile |
| 309 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 310 | hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0f); |
| 311 | float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 312 | assertEquals(x, 2.0f, "setVolatile float value"); |
| 313 | } |
| 314 | |
| 315 | // Lazy |
| 316 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 317 | hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0f); |
| 318 | float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 319 | assertEquals(x, 1.0f, "setRelease float value"); |
| 320 | } |
| 321 | |
| 322 | // Opaque |
| 323 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 324 | hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0f); |
| 325 | float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 326 | assertEquals(x, 2.0f, "setOpaque float value"); |
| 327 | } |
| 328 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 329 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 330 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 331 | // Compare |
| 332 | { |
| 333 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f); |
| 334 | assertEquals(r, true, "success compareAndSet float"); |
| 335 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 336 | assertEquals(x, 2.0f, "success compareAndSet float value"); |
| 337 | } |
| 338 | |
| 339 | { |
| 340 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f); |
| 341 | assertEquals(r, false, "failing compareAndSet float"); |
| 342 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 343 | assertEquals(x, 2.0f, "failing compareAndSet float value"); |
| 344 | } |
| 345 | |
| 346 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 347 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f); |
| 348 | assertEquals(r, 2.0f, "success compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 349 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 350 | assertEquals(x, 1.0f, "success compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 354 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f); |
| 355 | assertEquals(r, 1.0f, "failing compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 356 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 357 | assertEquals(x, 1.0f, "failing compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | { |
| 361 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f); |
| 362 | assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); |
| 363 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 364 | assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); |
| 365 | } |
| 366 | |
| 367 | { |
| 368 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f); |
| 369 | assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); |
| 370 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 371 | assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); |
| 372 | } |
| 373 | |
| 374 | { |
| 375 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f); |
| 376 | assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); |
| 377 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 378 | assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); |
| 379 | } |
| 380 | |
| 381 | { |
| 382 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f); |
| 383 | assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); |
| 384 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 385 | assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); |
| 386 | } |
| 387 | |
| 388 | { |
| 389 | boolean success = false; |
| 390 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 391 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0f, 2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 392 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 393 | assertEquals(success, true, "weakCompareAndSetPlain float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 394 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 395 | assertEquals(x, 2.0f, "weakCompareAndSetPlain float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | { |
| 399 | boolean success = false; |
| 400 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
| 401 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2.0f, 1.0f); |
| 402 | } |
| 403 | assertEquals(success, true, "weakCompareAndSetAcquire float"); |
| 404 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 405 | assertEquals(x, 1.0f, "weakCompareAndSetAcquire float"); |
| 406 | } |
| 407 | |
| 408 | { |
| 409 | boolean success = false; |
| 410 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
| 411 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0f, 2.0f); |
| 412 | } |
| 413 | assertEquals(success, true, "weakCompareAndSetRelease float"); |
| 414 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 415 | assertEquals(x, 2.0f, "weakCompareAndSetRelease float"); |
| 416 | } |
| 417 | |
| 418 | { |
| 419 | boolean success = false; |
| 420 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 421 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0f, 1.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 422 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 423 | assertEquals(success, true, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 424 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 425 | assertEquals(x, 1.0f, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // Compare set and get |
| 429 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 430 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 431 | |
| 432 | float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 433 | assertEquals(o, 1.0f, "getAndSet float"); |
| 434 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 435 | assertEquals(x, 2.0f, "getAndSet float value"); |
| 436 | } |
| 437 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 438 | // Compare set and get |
| 439 | { |
| 440 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 441 | |
| 442 | float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0f); |
| 443 | assertEquals(o, 1.0f, "getAndSetAcquire float"); |
| 444 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 445 | assertEquals(x, 2.0f, "getAndSetAcquire float value"); |
| 446 | } |
| 447 | |
| 448 | // Compare set and get |
| 449 | { |
| 450 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 451 | |
| 452 | float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0f); |
| 453 | assertEquals(o, 1.0f, "getAndSetRelease float"); |
| 454 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 455 | assertEquals(x, 2.0f, "getAndSetRelease float value"); |
| 456 | } |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 457 | |
| 458 | // get and add, add and get |
| 459 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 460 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 461 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 462 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 463 | assertEquals(o, 1.0f, "getAndAdd float"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 464 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 465 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 466 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 467 | |
| 468 | { |
| 469 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 470 | |
| 471 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0f); |
| 472 | assertEquals(o, 1.0f, "getAndAddAcquire float"); |
| 473 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 474 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); |
| 475 | } |
| 476 | |
| 477 | { |
| 478 | hs.get(TestAccessMode.SET).invokeExact(1.0f); |
| 479 | |
| 480 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0f); |
| 481 | assertEquals(o, 1.0f, "getAndAddRelease float"); |
| 482 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(); |
| 483 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); |
| 484 | } |
| 485 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 489 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 490 | |
| 491 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) { |
| 492 | checkUOE(am, () -> { |
| 493 | float r = (float) hs.get(am).invokeExact(1.0f); |
| 494 | }); |
| 495 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
| 499 | static void testArray(Handles hs) throws Throwable { |
| 500 | float[] array = new float[10]; |
| 501 | |
| 502 | for (int i = 0; i < array.length; i++) { |
| 503 | // Plain |
| 504 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 505 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 506 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 507 | assertEquals(x, 1.0f, "get float value"); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | // Volatile |
| 512 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 513 | hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0f); |
| 514 | float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 515 | assertEquals(x, 2.0f, "setVolatile float value"); |
| 516 | } |
| 517 | |
| 518 | // Lazy |
| 519 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 520 | hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0f); |
| 521 | float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 522 | assertEquals(x, 1.0f, "setRelease float value"); |
| 523 | } |
| 524 | |
| 525 | // Opaque |
| 526 | { |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 527 | hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0f); |
| 528 | float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 529 | assertEquals(x, 2.0f, "setOpaque float value"); |
| 530 | } |
| 531 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 532 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 533 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 534 | // Compare |
| 535 | { |
| 536 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f); |
| 537 | assertEquals(r, true, "success compareAndSet float"); |
| 538 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 539 | assertEquals(x, 2.0f, "success compareAndSet float value"); |
| 540 | } |
| 541 | |
| 542 | { |
| 543 | boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f); |
| 544 | assertEquals(r, false, "failing compareAndSet float"); |
| 545 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 546 | assertEquals(x, 2.0f, "failing compareAndSet float value"); |
| 547 | } |
| 548 | |
| 549 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 550 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f); |
| 551 | assertEquals(r, 2.0f, "success compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 552 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 553 | assertEquals(x, 1.0f, "success compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | { |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 557 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f); |
| 558 | assertEquals(r, 1.0f, "failing compareAndExchange float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 559 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3f0273a | 2016-06-23 13:46:48 +0200 | [diff] [blame] | 560 | assertEquals(x, 1.0f, "failing compareAndExchange float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | { |
| 564 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f); |
| 565 | assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); |
| 566 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 567 | assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); |
| 568 | } |
| 569 | |
| 570 | { |
| 571 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f); |
| 572 | assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); |
| 573 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 574 | assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); |
| 575 | } |
| 576 | |
| 577 | { |
| 578 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f); |
| 579 | assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); |
| 580 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 581 | assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); |
| 582 | } |
| 583 | |
| 584 | { |
| 585 | float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f); |
| 586 | assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); |
| 587 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 588 | assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); |
| 589 | } |
| 590 | |
| 591 | { |
| 592 | boolean success = false; |
| 593 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 594 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0f, 2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 595 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 596 | assertEquals(success, true, "weakCompareAndSetPlain float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 597 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 598 | assertEquals(x, 2.0f, "weakCompareAndSetPlain float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | { |
| 602 | boolean success = false; |
| 603 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
| 604 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f, 1.0f); |
| 605 | } |
| 606 | assertEquals(success, true, "weakCompareAndSetAcquire float"); |
| 607 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 608 | assertEquals(x, 1.0f, "weakCompareAndSetAcquire float"); |
| 609 | } |
| 610 | |
| 611 | { |
| 612 | boolean success = false; |
| 613 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
| 614 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1.0f, 2.0f); |
| 615 | } |
| 616 | assertEquals(success, true, "weakCompareAndSetRelease float"); |
| 617 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 618 | assertEquals(x, 2.0f, "weakCompareAndSetRelease float"); |
| 619 | } |
| 620 | |
| 621 | { |
| 622 | boolean success = false; |
| 623 | for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 624 | success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0f, 1.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 625 | } |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 626 | assertEquals(success, true, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 627 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
Paul Sandoz | 3bd5ebe | 2016-09-01 13:56:13 -0700 | [diff] [blame] | 628 | assertEquals(x, 1.0f, "weakCompareAndSet float"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // Compare set and get |
| 632 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 633 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 634 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 635 | float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0f); |
| 636 | assertEquals(o, 1.0f, "getAndSet float"); |
| 637 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 638 | assertEquals(x, 2.0f, "getAndSet float value"); |
| 639 | } |
| 640 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 641 | { |
| 642 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 643 | |
| 644 | float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f); |
| 645 | assertEquals(o, 1.0f, "getAndSetAcquire float"); |
| 646 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 647 | assertEquals(x, 2.0f, "getAndSetAcquire float value"); |
| 648 | } |
| 649 | |
| 650 | { |
| 651 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 652 | |
| 653 | float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0f); |
| 654 | assertEquals(o, 1.0f, "getAndSetRelease float"); |
| 655 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 656 | assertEquals(x, 2.0f, "getAndSetRelease float value"); |
| 657 | } |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 658 | |
| 659 | // get and add, add and get |
| 660 | { |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 661 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 662 | |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 663 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0f); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 664 | assertEquals(o, 1.0f, "getAndAdd float"); |
Paul Sandoz | c073edc | 2016-09-01 10:17:01 -0700 | [diff] [blame] | 665 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 666 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 667 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 668 | |
| 669 | { |
| 670 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 671 | |
| 672 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0f); |
| 673 | assertEquals(o, 1.0f, "getAndAddAcquire float"); |
| 674 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 675 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); |
| 676 | } |
| 677 | |
| 678 | { |
| 679 | hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); |
| 680 | |
| 681 | float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0f); |
| 682 | assertEquals(o, 1.0f, "getAndAddRelease float"); |
| 683 | float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); |
| 684 | assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); |
| 685 | } |
| 686 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | static void testArrayUnsupported(Handles hs) throws Throwable { |
| 691 | float[] array = new float[10]; |
| 692 | |
| 693 | final int i = 0; |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 694 | |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 695 | |
| 696 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_BITWISE)) { |
| 697 | checkUOE(am, () -> { |
| 698 | float o = (float) hs.get(am).invokeExact(array, i, 1.0f); |
| 699 | }); |
| 700 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
| 704 | float[] array = new float[10]; |
| 705 | |
| 706 | for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
| 707 | final int ci = i; |
| 708 | |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 709 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 710 | checkIOOBE(am, () -> { |
| 711 | float x = (float) hs.get(am).invokeExact(array, ci); |
| 712 | }); |
| 713 | } |
| 714 | |
Paul Sandoz | a7aff44 | 2016-04-13 15:05:48 +0200 | [diff] [blame] | 715 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 716 | checkIOOBE(am, () -> { |
| 717 | hs.get(am).invokeExact(array, ci, 1.0f); |
| 718 | }); |
| 719 | } |
| 720 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 721 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
| 722 | checkIOOBE(am, () -> { |
| 723 | boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1.0f, 2.0f); |
| 724 | }); |
| 725 | } |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 726 | |
Paul Sandoz | 734dbe4 | 2016-06-20 17:57:19 +0200 | [diff] [blame] | 727 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
| 728 | checkIOOBE(am, () -> { |
| 729 | float r = (float) hs.get(am).invokeExact(array, ci, 2.0f, 1.0f); |
| 730 | }); |
| 731 | } |
| 732 | |
| 733 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
| 734 | checkIOOBE(am, () -> { |
| 735 | float o = (float) hs.get(am).invokeExact(array, ci, 1.0f); |
| 736 | }); |
| 737 | } |
| 738 | |
| 739 | for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
| 740 | checkIOOBE(am, () -> { |
| 741 | float o = (float) hs.get(am).invokeExact(array, ci, 3.0f); |
| 742 | }); |
| 743 | } |
Paul Sandoz | 82d4891 | 2016-09-01 10:16:57 -0700 | [diff] [blame] | 744 | |
Paul Sandoz | 9fb30a3 | 2016-03-24 11:21:21 +0100 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |