blob: f943bf2611bd6720b1076f83ad6bdba046eaaa5c [file] [log] [blame]
Paul Sandoz9fb30a32016-03-24 11:21:21 +01001/*
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 VarHandleTestMethodHandleAccess$Type$
Paul Sandoz44afe202016-05-17 12:06:41 +020027 * @run testng/othervm -Diters=20000 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodHandleAccess$Type$
Paul Sandoz9fb30a32016-03-24 11:21:21 +010028 */
29
30import org.testng.annotations.BeforeClass;
31import org.testng.annotations.DataProvider;
32import org.testng.annotations.Test;
33
34import java.lang.invoke.MethodHandles;
35import java.lang.invoke.VarHandle;
36import java.util.ArrayList;
37import java.util.Arrays;
38import java.util.List;
39
40import static org.testng.Assert.*;
41
42public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest {
43 static final $type$ static_final_v = $value1$;
44
45 static $type$ static_v;
46
47 final $type$ final_v = $value1$;
48
49 $type$ v;
50
51 VarHandle vhFinalField;
52
53 VarHandle vhField;
54
55 VarHandle vhStaticField;
56
57 VarHandle vhStaticFinalField;
58
59 VarHandle vhArray;
60
61 @BeforeClass
62 public void setup() throws Exception {
63 vhFinalField = MethodHandles.lookup().findVarHandle(
64 VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.class);
65
66 vhField = MethodHandles.lookup().findVarHandle(
67 VarHandleTestMethodHandleAccess$Type$.class, "v", $type$.class);
68
69 vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle(
70 VarHandleTestMethodHandleAccess$Type$.class, "static_final_v", $type$.class);
71
72 vhStaticField = MethodHandles.lookup().findStaticVarHandle(
73 VarHandleTestMethodHandleAccess$Type$.class, "static_v", $type$.class);
74
75 vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
76 }
77
78
79 @DataProvider
80 public Object[][] accessTestCaseProvider() throws Exception {
81 List<AccessTestCase<?>> cases = new ArrayList<>();
82
83 for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) {
84 cases.add(new MethodHandleAccessTestCase("Instance field",
85 vhField, f, hs -> testInstanceField(this, hs)));
86 cases.add(new MethodHandleAccessTestCase("Instance field unsupported",
87 vhField, f, hs -> testInstanceFieldUnsupported(this, hs),
88 false));
89
90 cases.add(new MethodHandleAccessTestCase("Static field",
91 vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticField));
92 cases.add(new MethodHandleAccessTestCase("Static field unsupported",
93 vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticFieldUnsupported,
94 false));
95
96 cases.add(new MethodHandleAccessTestCase("Array",
97 vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArray));
98 cases.add(new MethodHandleAccessTestCase("Array unsupported",
99 vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayUnsupported,
100 false));
101 cases.add(new MethodHandleAccessTestCase("Array index out of bounds",
102 vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayIndexOutOfBounds,
103 false));
104 }
105
106 // Work around issue with jtreg summary reporting which truncates
107 // the String result of Object.toString to 30 characters, hence
108 // the first dummy argument
109 return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
110 }
111
112 @Test(dataProvider = "accessTestCaseProvider")
113 public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable {
114 T t = atc.get();
115 int iters = atc.requiresLoop() ? ITERS : 1;
116 for (int c = 0; c < iters; c++) {
117 atc.testAccess(t);
118 }
119 }
120
121
122 static void testInstanceField(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
123 // Plain
124 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200125 hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
126 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100127 assertEquals(x, $value1$, "set $type$ value");
128 }
129
130
131 // Volatile
132 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200133 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$);
134 $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100135 assertEquals(x, $value2$, "setVolatile $type$ value");
136 }
137
138 // Lazy
139 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200140 hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$);
141 $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100142 assertEquals(x, $value1$, "setRelease $type$ value");
143 }
144
145 // Opaque
146 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200147 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$);
148 $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100149 assertEquals(x, $value2$, "setOpaque $type$ value");
150 }
151
152#if[CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200153 hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100154
155 // Compare
156 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200157 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100158 assertEquals(r, true, "success compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200159 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100160 assertEquals(x, $value2$, "success compareAndSet $type$ value");
161 }
162
163 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200164 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100165 assertEquals(r, false, "failing compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200166 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100167 assertEquals(x, $value2$, "failing compareAndSet $type$ value");
168 }
169
170 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200171 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100172 assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200173 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100174 assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
175 }
176
177 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200178 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100179 assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200180 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100181 assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
182 }
183
184 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200185 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100186 assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200187 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100188 assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
189 }
190
191 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200192 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100193 assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200194 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100195 assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
196 }
197
198 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200199 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100200 assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200201 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100202 assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
203 }
204
205 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200206 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100207 assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200208 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100209 assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
210 }
211
212 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300213 boolean success = false;
214 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
215 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$);
216 }
217 assertEquals(success, true, "weakCompareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200218 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100219 assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
220 }
221
222 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300223 boolean success = false;
224 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
225 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$);
226 }
227 assertEquals(success, true, "weakCompareAndSetAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200228 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100229 assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
230 }
231
232 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300233 boolean success = false;
234 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
235 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$);
236 }
237 assertEquals(success, true, "weakCompareAndSetRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200238 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100239 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
240 }
241
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300242 {
243 boolean success = false;
244 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
245 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$);
246 }
247 assertEquals(success, true, "weakCompareAndSetVolatile $type$");
248 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
249 assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$");
250 }
251
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100252 // Compare set and get
253 {
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300254 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$);
255 assertEquals(o, $value1$, "getAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200256 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv);
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300257 assertEquals(x, $value2$, "getAndSet $type$ value");
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100258 }
259#end[CAS]
260
261#if[AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200262 hs.get(TestAccessMode.SET).invokeExact(recv, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100263
264 // get and add, add and get
265 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200266 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100267 assertEquals(o, $value1$, "getAndAdd $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200268 $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100269 assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
270 }
271#end[AtomicAdd]
272 }
273
274 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable {
275#if[!CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200276 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100277 checkUOE(am, () -> {
278 boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$);
279 });
280 }
281
Paul Sandoza7aff442016-04-13 15:05:48 +0200282 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100283 checkUOE(am, () -> {
284 $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$);
285 });
286 }
287
Paul Sandoza7aff442016-04-13 15:05:48 +0200288 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100289 checkUOE(am, () -> {
290 $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
291 });
292 }
293#end[CAS]
294
295#if[!AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200296 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100297 checkUOE(am, () -> {
298 $type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$);
299 });
300 }
301#end[AtomicAdd]
302 }
303
304
305 static void testStaticField(Handles hs) throws Throwable {
306 // Plain
307 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200308 hs.get(TestAccessMode.SET).invokeExact($value1$);
309 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100310 assertEquals(x, $value1$, "set $type$ value");
311 }
312
313
314 // Volatile
315 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200316 hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$);
317 $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100318 assertEquals(x, $value2$, "setVolatile $type$ value");
319 }
320
321 // Lazy
322 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200323 hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$);
324 $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100325 assertEquals(x, $value1$, "setRelease $type$ value");
326 }
327
328 // Opaque
329 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200330 hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$);
331 $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100332 assertEquals(x, $value2$, "setOpaque $type$ value");
333 }
334
335#if[CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200336 hs.get(TestAccessMode.SET).invokeExact($value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100337
338 // Compare
339 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200340 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100341 assertEquals(r, true, "success compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200342 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100343 assertEquals(x, $value2$, "success compareAndSet $type$ value");
344 }
345
346 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200347 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100348 assertEquals(r, false, "failing compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200349 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100350 assertEquals(x, $value2$, "failing compareAndSet $type$ value");
351 }
352
353 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200354 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100355 assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200356 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100357 assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
358 }
359
360 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200361 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100362 assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200363 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100364 assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
365 }
366
367 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200368 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100369 assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200370 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100371 assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
372 }
373
374 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200375 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100376 assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200377 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100378 assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
379 }
380
381 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200382 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100383 assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200384 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100385 assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
386 }
387
388 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200389 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100390 assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200391 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100392 assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
393 }
394
395 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300396 boolean success = false;
397 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
398 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$);
399 }
400 assertEquals(success, true, "weakCompareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200401 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100402 assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
403 }
404
405 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300406 boolean success = false;
407 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
408 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$);
409 }
410 assertEquals(success, true, "weakCompareAndSetAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200411 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100412 assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
413 }
414
415 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300416 boolean success = false;
417 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
418 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$);
419 }
420 assertEquals(success, true, "weakCompareAndSetRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200421 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100422 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
423 }
424
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300425 {
426 boolean success = false;
427 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
428 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact($value2$, $value1$);
429 }
430 assertEquals(success, true, "weakCompareAndSetVolatile $type$");
431 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
432 assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$");
433 }
434
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100435 // Compare set and get
436 {
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300437 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value2$);
438 assertEquals(o, $value1$, "getAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200439 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact();
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300440 assertEquals(x, $value2$, "getAndSet $type$ value");
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100441 }
442#end[CAS]
443
444#if[AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200445 hs.get(TestAccessMode.SET).invokeExact($value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100446
447 // get and add, add and get
448 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200449 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100450 assertEquals(o, $value1$, "getAndAdd $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200451 $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100452 assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
453 }
454#end[AtomicAdd]
455 }
456
457 static void testStaticFieldUnsupported(Handles hs) throws Throwable {
458#if[!CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200459 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100460 checkUOE(am, () -> {
461 boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$);
462 });
463 }
464
Paul Sandoza7aff442016-04-13 15:05:48 +0200465 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100466 checkUOE(am, () -> {
467 $type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$);
468 });
469 }
470
Paul Sandoza7aff442016-04-13 15:05:48 +0200471 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100472 checkUOE(am, () -> {
473 $type$ r = ($type$) hs.get(am).invokeExact($value1$);
474 });
475 }
476#end[CAS]
477
478#if[!AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200479 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100480 checkUOE(am, () -> {
481 $type$ r = ($type$) hs.get(am).invokeExact($value1$);
482 });
483 }
484#end[AtomicAdd]
485 }
486
487
488 static void testArray(Handles hs) throws Throwable {
489 $type$[] array = new $type$[10];
490
491 for (int i = 0; i < array.length; i++) {
492 // Plain
493 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200494 hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
495 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100496 assertEquals(x, $value1$, "get $type$ value");
497 }
498
499
500 // Volatile
501 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200502 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, $value2$);
503 $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100504 assertEquals(x, $value2$, "setVolatile $type$ value");
505 }
506
507 // Lazy
508 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200509 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, $value1$);
510 $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100511 assertEquals(x, $value1$, "setRelease $type$ value");
512 }
513
514 // Opaque
515 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200516 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, $value2$);
517 $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100518 assertEquals(x, $value2$, "setOpaque $type$ value");
519 }
520
521#if[CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200522 hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100523
524 // Compare
525 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200526 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100527 assertEquals(r, true, "success compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200528 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100529 assertEquals(x, $value2$, "success compareAndSet $type$ value");
530 }
531
532 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200533 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100534 assertEquals(r, false, "failing compareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200535 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100536 assertEquals(x, $value2$, "failing compareAndSet $type$ value");
537 }
538
539 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200540 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100541 assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200542 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100543 assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value");
544 }
545
546 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200547 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100548 assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200549 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100550 assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value");
551 }
552
553 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200554 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100555 assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200556 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100557 assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value");
558 }
559
560 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200561 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100562 assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200563 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100564 assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value");
565 }
566
567 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200568 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100569 assertEquals(r, $value2$, "success compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200570 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100571 assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value");
572 }
573
574 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200575 $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100576 assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200577 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100578 assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value");
579 }
580
581 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300582 boolean success = false;
583 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
584 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$);
585 }
586 assertEquals(success, true, "weakCompareAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200587 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100588 assertEquals(x, $value2$, "weakCompareAndSet $type$ value");
589 }
590
591 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300592 boolean success = false;
593 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
594 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$);
595 }
596 assertEquals(success, true, "weakCompareAndSetAcquire $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200597 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100598 assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$");
599 }
600
601 {
Aleksey Shipilev4f538852016-05-04 17:17:28 +0300602 boolean success = false;
603 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
604 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$);
605 }
606 assertEquals(success, true, "weakCompareAndSetRelease $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200607 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100608 assertEquals(x, $value2$, "weakCompareAndSetRelease $type$");
609 }
610
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300611 {
612 boolean success = false;
613 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
614 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, $value2$, $value1$);
615 }
616 assertEquals(success, true, "weakCompareAndSetVolatile $type$");
617 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
618 assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$");
619 }
620
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100621 // Compare set and get
622 {
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300623 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$);
624 assertEquals(o, $value1$, "getAndSet $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200625 $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i);
Aleksey Shipilev33bb9222016-05-17 22:28:00 +0300626 assertEquals(x, $value2$, "getAndSet $type$ value");
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100627 }
628#end[CAS]
629
630#if[AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200631 hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100632
633 // get and add, add and get
634 {
Paul Sandoza7aff442016-04-13 15:05:48 +0200635 $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100636 assertEquals(o, $value1$, "getAndAdd $type$");
Paul Sandoza7aff442016-04-13 15:05:48 +0200637 $type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$);
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100638 assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value");
639 }
640#end[AtomicAdd]
641 }
642 }
643
644 static void testArrayUnsupported(Handles hs) throws Throwable {
645 $type$[] array = new $type$[10];
646
647 final int i = 0;
648#if[!CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200649 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100650 checkUOE(am, () -> {
651 boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$);
652 });
653 }
654
Paul Sandoza7aff442016-04-13 15:05:48 +0200655 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100656 checkUOE(am, () -> {
657 $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$);
658 });
659 }
660
Paul Sandoza7aff442016-04-13 15:05:48 +0200661 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100662 checkUOE(am, () -> {
663 $type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$);
664 });
665 }
666#end[CAS]
667
668#if[!AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200669 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100670 checkUOE(am, () -> {
671 $type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$);
672 });
673 }
674#end[AtomicAdd]
675 }
676
677 static void testArrayIndexOutOfBounds(Handles hs) throws Throwable {
678 $type$[] array = new $type$[10];
679
680 for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
681 final int ci = i;
682
Paul Sandoza7aff442016-04-13 15:05:48 +0200683 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100684 checkIOOBE(am, () -> {
685 $type$ x = ($type$) hs.get(am).invokeExact(array, ci);
686 });
687 }
688
Paul Sandoza7aff442016-04-13 15:05:48 +0200689 for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100690 checkIOOBE(am, () -> {
691 hs.get(am).invokeExact(array, ci, $value1$);
692 });
693 }
694
695#if[CAS]
Paul Sandoza7aff442016-04-13 15:05:48 +0200696 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100697 checkIOOBE(am, () -> {
698 boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$);
699 });
700 }
701
Paul Sandoza7aff442016-04-13 15:05:48 +0200702 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100703 checkIOOBE(am, () -> {
704 $type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$);
705 });
706 }
707
Paul Sandoza7aff442016-04-13 15:05:48 +0200708 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100709 checkIOOBE(am, () -> {
710 $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$);
711 });
712 }
713#end[CAS]
714
715#if[AtomicAdd]
Paul Sandoza7aff442016-04-13 15:05:48 +0200716 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) {
Paul Sandoz9fb30a32016-03-24 11:21:21 +0100717 checkIOOBE(am, () -> {
718 $type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$);
719 });
720 }
721#end[AtomicAdd]
722 }
723 }
724}
725