author | shade |
Wed, 04 May 2016 17:17:28 +0300 | |
changeset 38355 | 674cfd9b90cf |
parent 37343 | 35a2231828a7 |
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 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
212 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
213 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
214 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
215 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
216 |
assertEquals(success, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
217 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 218 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
219 |
} |
|
220 |
||
221 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
222 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
223 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
224 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value1$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
225 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
226 |
assertEquals(success, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
227 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 228 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
229 |
} |
|
230 |
||
231 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
232 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
233 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
234 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
235 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
236 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
237 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 238 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
239 |
} |
|
240 |
||
241 |
// Compare set and get |
|
242 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
243 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$); |
36934 | 244 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
245 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 246 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
247 |
} |
|
248 |
#end[CAS] |
|
249 |
||
250 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
251 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 252 |
|
253 |
// get and add, add and get |
|
254 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
255 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$); |
36934 | 256 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
257 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$); |
36934 | 258 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
259 |
} |
|
260 |
#end[AtomicAdd] |
|
261 |
} |
|
262 |
||
263 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { |
|
264 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
265 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 266 |
checkUOE(am, () -> { |
267 |
boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
268 |
}); |
|
269 |
} |
|
270 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
271 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 272 |
checkUOE(am, () -> { |
273 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
274 |
}); |
|
275 |
} |
|
276 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
277 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 278 |
checkUOE(am, () -> { |
279 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
280 |
}); |
|
281 |
} |
|
282 |
#end[CAS] |
|
283 |
||
284 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
285 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 286 |
checkUOE(am, () -> { |
287 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
288 |
}); |
|
289 |
} |
|
290 |
#end[AtomicAdd] |
|
291 |
} |
|
292 |
||
293 |
||
294 |
static void testStaticField(Handles hs) throws Throwable { |
|
295 |
// Plain |
|
296 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
297 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
298 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 299 |
assertEquals(x, $value1$, "set $type$ value"); |
300 |
} |
|
301 |
||
302 |
||
303 |
// Volatile |
|
304 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
305 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
306 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 307 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
308 |
} |
|
309 |
||
310 |
// Lazy |
|
311 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
312 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
313 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 314 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
315 |
} |
|
316 |
||
317 |
// Opaque |
|
318 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
319 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
320 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 321 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
322 |
} |
|
323 |
||
324 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
325 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 326 |
|
327 |
// Compare |
|
328 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
329 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$); |
36934 | 330 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
331 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 332 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
333 |
} |
|
334 |
||
335 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
336 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$); |
36934 | 337 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
338 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 339 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
340 |
} |
|
341 |
||
342 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
343 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$); |
36934 | 344 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
345 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 346 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
347 |
} |
|
348 |
||
349 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
350 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$); |
36934 | 351 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
352 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 353 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
354 |
} |
|
355 |
||
356 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
357 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$); |
36934 | 358 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
359 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 360 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
361 |
} |
|
362 |
||
363 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
364 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$); |
36934 | 365 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
366 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 367 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
368 |
} |
|
369 |
||
370 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
371 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$); |
36934 | 372 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
373 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 374 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
375 |
} |
|
376 |
||
377 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
378 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$); |
36934 | 379 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
380 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 381 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
382 |
} |
|
383 |
||
384 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
385 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
386 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
387 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
388 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
389 |
assertEquals(success, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
390 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 391 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
392 |
} |
|
393 |
||
394 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
395 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
396 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
397 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact($value2$, $value1$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
398 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
399 |
assertEquals(success, true, "weakCompareAndSetAcquire $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, $value1$, "weakCompareAndSetAcquire $type$"); |
402 |
} |
|
403 |
||
404 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
405 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
406 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
407 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
408 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
409 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
410 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 411 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
412 |
} |
|
413 |
||
414 |
// Compare set and get |
|
415 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
416 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$); |
36934 | 417 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
418 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 419 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
420 |
} |
|
421 |
#end[CAS] |
|
422 |
||
423 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
424 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 425 |
|
426 |
// get and add, add and get |
|
427 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
428 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$); |
36934 | 429 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
430 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$); |
36934 | 431 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
432 |
} |
|
433 |
#end[AtomicAdd] |
|
434 |
} |
|
435 |
||
436 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
437 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
438 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 439 |
checkUOE(am, () -> { |
440 |
boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$); |
|
441 |
}); |
|
442 |
} |
|
443 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
444 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 445 |
checkUOE(am, () -> { |
446 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$); |
|
447 |
}); |
|
448 |
} |
|
449 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
450 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 451 |
checkUOE(am, () -> { |
452 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
453 |
}); |
|
454 |
} |
|
455 |
#end[CAS] |
|
456 |
||
457 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
458 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 459 |
checkUOE(am, () -> { |
460 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
461 |
}); |
|
462 |
} |
|
463 |
#end[AtomicAdd] |
|
464 |
} |
|
465 |
||
466 |
||
467 |
static void testArray(Handles hs) throws Throwable { |
|
468 |
$type$[] array = new $type$[10]; |
|
469 |
||
470 |
for (int i = 0; i < array.length; i++) { |
|
471 |
// Plain |
|
472 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
473 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
474 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 475 |
assertEquals(x, $value1$, "get $type$ value"); |
476 |
} |
|
477 |
||
478 |
||
479 |
// Volatile |
|
480 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
481 |
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
|
482 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 483 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
484 |
} |
|
485 |
||
486 |
// Lazy |
|
487 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
488 |
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
|
489 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 490 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
491 |
} |
|
492 |
||
493 |
// Opaque |
|
494 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
495 |
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
|
496 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 497 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
498 |
} |
|
499 |
||
500 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
501 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 502 |
|
503 |
// Compare |
|
504 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
505 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
36934 | 506 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
507 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 508 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
509 |
} |
|
510 |
||
511 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
512 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$); |
36934 | 513 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
514 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 515 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
516 |
} |
|
517 |
||
518 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
519 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
36934 | 520 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
521 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 522 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
523 |
} |
|
524 |
||
525 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
526 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$); |
36934 | 527 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
528 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 529 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
530 |
} |
|
531 |
||
532 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
533 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$); |
36934 | 534 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
535 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 536 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
537 |
} |
|
538 |
||
539 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
540 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$); |
36934 | 541 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
542 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 543 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
544 |
} |
|
545 |
||
546 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
547 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$); |
36934 | 548 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
549 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 550 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
551 |
} |
|
552 |
||
553 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
554 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$); |
36934 | 555 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
556 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 557 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
558 |
} |
|
559 |
||
560 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
561 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
562 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
563 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
564 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
565 |
assertEquals(success, true, "weakCompareAndSet $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, $value2$, "weakCompareAndSet $type$ value"); |
568 |
} |
|
569 |
||
570 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
571 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
572 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
573 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value1$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
574 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
575 |
assertEquals(success, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
576 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 577 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
578 |
} |
|
579 |
||
580 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
581 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
582 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
583 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, $value1$, $value2$); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
584 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
585 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
586 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 587 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
588 |
} |
|
589 |
||
590 |
// Compare set and get |
|
591 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
592 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$); |
36934 | 593 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
594 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 595 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
596 |
} |
|
597 |
#end[CAS] |
|
598 |
||
599 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
600 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 601 |
|
602 |
// get and add, add and get |
|
603 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
604 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$); |
36934 | 605 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
606 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$); |
36934 | 607 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
608 |
} |
|
609 |
#end[AtomicAdd] |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
614 |
$type$[] array = new $type$[10]; |
|
615 |
||
616 |
final int i = 0; |
|
617 |
#if[!CAS] |
|
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_SET)) { |
36934 | 619 |
checkUOE(am, () -> { |
620 |
boolean r = (boolean) 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.COMPARE_AND_EXCHANGE)) { |
36934 | 625 |
checkUOE(am, () -> { |
626 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
627 |
}); |
|
628 |
} |
|
629 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
630 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 631 |
checkUOE(am, () -> { |
632 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
633 |
}); |
|
634 |
} |
|
635 |
#end[CAS] |
|
636 |
||
637 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
638 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 639 |
checkUOE(am, () -> { |
640 |
$type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
641 |
}); |
|
642 |
} |
|
643 |
#end[AtomicAdd] |
|
644 |
} |
|
645 |
||
646 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
647 |
$type$[] array = new $type$[10]; |
|
648 |
||
649 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
650 |
final int ci = i; |
|
651 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
652 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 653 |
checkIOOBE(am, () -> { |
654 |
$type$ x = ($type$) hs.get(am).invokeExact(array, ci); |
|
655 |
}); |
|
656 |
} |
|
657 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
658 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 659 |
checkIOOBE(am, () -> { |
660 |
hs.get(am).invokeExact(array, ci, $value1$); |
|
661 |
}); |
|
662 |
} |
|
663 |
||
664 |
#if[CAS] |
|
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_SET)) { |
36934 | 666 |
checkIOOBE(am, () -> { |
667 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$); |
|
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.COMPARE_AND_EXCHANGE)) { |
36934 | 672 |
checkIOOBE(am, () -> { |
673 |
$type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$); |
|
674 |
}); |
|
675 |
} |
|
676 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
677 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 678 |
checkIOOBE(am, () -> { |
679 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$); |
|
680 |
}); |
|
681 |
} |
|
682 |
#end[CAS] |
|
683 |
||
684 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
685 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 686 |
checkIOOBE(am, () -> { |
687 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$); |
|
688 |
}); |
|
689 |
} |
|
690 |
#end[AtomicAdd] |
|
691 |
} |
|
692 |
} |
|
693 |
} |
|
694 |