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