author | psandoz |
Tue, 17 May 2016 12:06:41 +0200 | |
changeset 38328 | 40435a469d25 |
parent 37719 | add11bc0e6e2 |
child 38368 | c8eb5d6812c5 |
permissions | -rw-r--r-- |
36934 | 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 VarHandleTestMethodHandleAccess$Type$ |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
27 |
* @run testng/othervm -Diters=20000 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodHandleAccess$Type$ |
36934 | 28 |
*/ |
29 |
||
30 |
import org.testng.annotations.BeforeClass; |
|
31 |
import org.testng.annotations.DataProvider; |
|
32 |
import org.testng.annotations.Test; |
|
33 |
||
34 |
import java.lang.invoke.MethodHandles; |
|
35 |
import java.lang.invoke.VarHandle; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.Arrays; |
|
38 |
import java.util.List; |
|
39 |
||
40 |
import static org.testng.Assert.*; |
|
41 |
||
42 |
public 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 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
125 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
126 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 127 |
assertEquals(x, $value1$, "set $type$ value"); |
128 |
} |
|
129 |
||
130 |
||
131 |
// Volatile |
|
132 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
133 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
134 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
36934 | 135 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
136 |
} |
|
137 |
||
138 |
// Lazy |
|
139 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
140 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
141 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
36934 | 142 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
143 |
} |
|
144 |
||
145 |
// Opaque |
|
146 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
147 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
148 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
36934 | 149 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
150 |
} |
|
151 |
||
152 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
153 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 154 |
|
155 |
// Compare |
|
156 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
157 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$); |
36934 | 158 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
159 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 160 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
161 |
} |
|
162 |
||
163 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
164 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$); |
36934 | 165 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
166 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 167 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
168 |
} |
|
169 |
||
170 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
171 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$); |
36934 | 172 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
173 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 174 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
175 |
} |
|
176 |
||
177 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
178 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$); |
36934 | 179 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
180 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 181 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
182 |
} |
|
183 |
||
184 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
185 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$); |
36934 | 186 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
187 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 188 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
189 |
} |
|
190 |
||
191 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
192 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$); |
36934 | 193 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
194 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 195 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
196 |
} |
|
197 |
||
198 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
199 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$); |
36934 | 200 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
201 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 202 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
203 |
} |
|
204 |
||
205 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
206 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$); |
36934 | 207 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
208 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 209 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
210 |
} |
|
211 |
||
212 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
213 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$); |
36934 | 214 |
assertEquals(r, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
215 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 216 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
217 |
} |
|
218 |
||
219 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
220 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$); |
36934 | 221 |
assertEquals(r, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
222 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 223 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
224 |
} |
|
225 |
||
226 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
227 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$); |
36934 | 228 |
assertEquals(r, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
229 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 230 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
231 |
} |
|
232 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
233 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
234 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
235 |
assertEquals(r, true, "weakCompareAndSetVolatile $type$"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
236 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
237 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
238 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
239 |
|
36934 | 240 |
// Compare set and get |
241 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
242 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
243 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
244 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
245 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 246 |
} |
247 |
#end[CAS] |
|
248 |
||
249 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
250 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 251 |
|
252 |
// get and add, add and get |
|
253 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
254 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$); |
36934 | 255 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
256 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$); |
36934 | 257 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
258 |
} |
|
259 |
#end[AtomicAdd] |
|
260 |
} |
|
261 |
||
262 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { |
|
263 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
264 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 265 |
checkUOE(am, () -> { |
266 |
boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
267 |
}); |
|
268 |
} |
|
269 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
270 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 271 |
checkUOE(am, () -> { |
272 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
273 |
}); |
|
274 |
} |
|
275 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
276 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 277 |
checkUOE(am, () -> { |
278 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
279 |
}); |
|
280 |
} |
|
281 |
#end[CAS] |
|
282 |
||
283 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
284 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 285 |
checkUOE(am, () -> { |
286 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
287 |
}); |
|
288 |
} |
|
289 |
#end[AtomicAdd] |
|
290 |
} |
|
291 |
||
292 |
||
293 |
static void testStaticField(Handles hs) throws Throwable { |
|
294 |
// Plain |
|
295 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
296 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
297 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 298 |
assertEquals(x, $value1$, "set $type$ value"); |
299 |
} |
|
300 |
||
301 |
||
302 |
// Volatile |
|
303 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
304 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
305 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 306 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
307 |
} |
|
308 |
||
309 |
// Lazy |
|
310 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
311 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
312 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 313 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
314 |
} |
|
315 |
||
316 |
// Opaque |
|
317 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
318 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
319 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 320 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
321 |
} |
|
322 |
||
323 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
324 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 325 |
|
326 |
// Compare |
|
327 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
328 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$); |
36934 | 329 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
330 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 331 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
332 |
} |
|
333 |
||
334 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
335 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$); |
36934 | 336 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
337 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 338 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
339 |
} |
|
340 |
||
341 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
342 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$); |
36934 | 343 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
344 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 345 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
346 |
} |
|
347 |
||
348 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
349 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$); |
36934 | 350 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
351 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 352 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
353 |
} |
|
354 |
||
355 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
356 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$); |
36934 | 357 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
358 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 359 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
360 |
} |
|
361 |
||
362 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
363 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$); |
36934 | 364 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
365 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 366 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
367 |
} |
|
368 |
||
369 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
370 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$); |
36934 | 371 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
372 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 373 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
374 |
} |
|
375 |
||
376 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
377 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$); |
36934 | 378 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
379 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 380 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
381 |
} |
|
382 |
||
383 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
384 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$); |
36934 | 385 |
assertEquals(r, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
386 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 387 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
388 |
} |
|
389 |
||
390 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
391 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$); |
36934 | 392 |
assertEquals(r, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
393 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 394 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
395 |
} |
|
396 |
||
397 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
398 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$); |
36934 | 399 |
assertEquals(r, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
400 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 401 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
402 |
} |
|
403 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
404 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
405 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact($value2$, $value1$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
406 |
assertEquals(r, true, "weakCompareAndSetVolatile $type$"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
407 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
408 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
409 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
410 |
|
36934 | 411 |
// Compare set and get |
412 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
413 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact($value2$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
414 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
415 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
416 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 417 |
} |
418 |
#end[CAS] |
|
419 |
||
420 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
421 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 422 |
|
423 |
// get and add, add and get |
|
424 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
425 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$); |
36934 | 426 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
427 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$); |
36934 | 428 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
429 |
} |
|
430 |
#end[AtomicAdd] |
|
431 |
} |
|
432 |
||
433 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
434 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
435 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 436 |
checkUOE(am, () -> { |
437 |
boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$); |
|
438 |
}); |
|
439 |
} |
|
440 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
441 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 442 |
checkUOE(am, () -> { |
443 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$); |
|
444 |
}); |
|
445 |
} |
|
446 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
447 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 448 |
checkUOE(am, () -> { |
449 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
450 |
}); |
|
451 |
} |
|
452 |
#end[CAS] |
|
453 |
||
454 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
455 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 456 |
checkUOE(am, () -> { |
457 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
458 |
}); |
|
459 |
} |
|
460 |
#end[AtomicAdd] |
|
461 |
} |
|
462 |
||
463 |
||
464 |
static void testArray(Handles hs) throws Throwable { |
|
465 |
$type$[] array = new $type$[10]; |
|
466 |
||
467 |
for (int i = 0; i < array.length; i++) { |
|
468 |
// Plain |
|
469 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
470 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
471 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 472 |
assertEquals(x, $value1$, "get $type$ value"); |
473 |
} |
|
474 |
||
475 |
||
476 |
// Volatile |
|
477 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
478 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
479 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 480 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
481 |
} |
|
482 |
||
483 |
// Lazy |
|
484 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
485 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
486 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 487 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
488 |
} |
|
489 |
||
490 |
// Opaque |
|
491 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
492 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
493 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 494 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
495 |
} |
|
496 |
||
497 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
498 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 499 |
|
500 |
// Compare |
|
501 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
502 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
36934 | 503 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
504 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 505 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
506 |
} |
|
507 |
||
508 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
509 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$); |
36934 | 510 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
511 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 512 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
513 |
} |
|
514 |
||
515 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
516 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
36934 | 517 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
518 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 519 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
520 |
} |
|
521 |
||
522 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
523 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$); |
36934 | 524 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
525 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 526 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
527 |
} |
|
528 |
||
529 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
530 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$); |
36934 | 531 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
532 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 533 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
534 |
} |
|
535 |
||
536 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
537 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$); |
36934 | 538 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
539 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 540 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
541 |
} |
|
542 |
||
543 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
544 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$); |
36934 | 545 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
546 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 547 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
548 |
} |
|
549 |
||
550 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
551 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$); |
36934 | 552 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
553 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 554 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
555 |
} |
|
556 |
||
557 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
558 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
36934 | 559 |
assertEquals(r, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
560 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 561 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
562 |
} |
|
563 |
||
564 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
565 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$); |
36934 | 566 |
assertEquals(r, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
567 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 568 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
569 |
} |
|
570 |
||
571 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
572 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$); |
36934 | 573 |
assertEquals(r, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
574 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 575 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
576 |
} |
|
577 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
578 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
579 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
580 |
assertEquals(r, true, "weakCompareAndSetVolatile $type$"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
581 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
582 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$ value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
583 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
584 |
|
36934 | 585 |
// Compare set and get |
586 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
587 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
588 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
589 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
590 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 591 |
} |
592 |
#end[CAS] |
|
593 |
||
594 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
595 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 596 |
|
597 |
// get and add, add and get |
|
598 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
599 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$); |
36934 | 600 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
601 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$); |
36934 | 602 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
603 |
} |
|
604 |
#end[AtomicAdd] |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
609 |
$type$[] array = new $type$[10]; |
|
610 |
||
611 |
final int i = 0; |
|
612 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
613 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 614 |
checkUOE(am, () -> { |
615 |
boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
616 |
}); |
|
617 |
} |
|
618 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
619 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 620 |
checkUOE(am, () -> { |
621 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
622 |
}); |
|
623 |
} |
|
624 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
625 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 626 |
checkUOE(am, () -> { |
627 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
628 |
}); |
|
629 |
} |
|
630 |
#end[CAS] |
|
631 |
||
632 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
633 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 634 |
checkUOE(am, () -> { |
635 |
$type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
636 |
}); |
|
637 |
} |
|
638 |
#end[AtomicAdd] |
|
639 |
} |
|
640 |
||
641 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
642 |
$type$[] array = new $type$[10]; |
|
643 |
||
644 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
645 |
final int ci = i; |
|
646 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
647 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 648 |
checkIOOBE(am, () -> { |
649 |
$type$ x = ($type$) hs.get(am).invokeExact(array, ci); |
|
650 |
}); |
|
651 |
} |
|
652 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
653 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 654 |
checkIOOBE(am, () -> { |
655 |
hs.get(am).invokeExact(array, ci, $value1$); |
|
656 |
}); |
|
657 |
} |
|
658 |
||
659 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
660 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 661 |
checkIOOBE(am, () -> { |
662 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$); |
|
663 |
}); |
|
664 |
} |
|
665 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
666 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 667 |
checkIOOBE(am, () -> { |
668 |
$type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$); |
|
669 |
}); |
|
670 |
} |
|
671 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
672 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 673 |
checkIOOBE(am, () -> { |
674 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$); |
|
675 |
}); |
|
676 |
} |
|
677 |
#end[CAS] |
|
678 |
||
679 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
680 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 681 |
checkIOOBE(am, () -> { |
682 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$); |
|
683 |
}); |
|
684 |
} |
|
685 |
#end[AtomicAdd] |
|
686 |
} |
|
687 |
} |
|
688 |
} |
|
689 |