author | amurillo |
Tue, 17 May 2016 05:38:15 -0700 | |
changeset 38368 | c8eb5d6812c5 |
parent 38358 | cb99c6d2af1b |
parent 38328 | 40435a469d25 |
child 38372 | 017d7578731c |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccess$Type$ |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
27 |
* @run testng/othervm -Diters=20000 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestMethodHandleAccess$Type$ |
36934 | 28 |
*/ |
29 |
||
30 |
import org.testng.annotations.BeforeClass; |
|
31 |
import org.testng.annotations.DataProvider; |
|
32 |
import org.testng.annotations.Test; |
|
33 |
||
34 |
import java.lang.invoke.MethodHandles; |
|
35 |
import java.lang.invoke.VarHandle; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.Arrays; |
|
38 |
import java.util.List; |
|
39 |
||
40 |
import static org.testng.Assert.*; |
|
41 |
||
42 |
public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { |
|
43 |
static final $type$ static_final_v = $value1$; |
|
44 |
||
45 |
static $type$ static_v; |
|
46 |
||
47 |
final $type$ final_v = $value1$; |
|
48 |
||
49 |
$type$ v; |
|
50 |
||
51 |
VarHandle vhFinalField; |
|
52 |
||
53 |
VarHandle vhField; |
|
54 |
||
55 |
VarHandle vhStaticField; |
|
56 |
||
57 |
VarHandle vhStaticFinalField; |
|
58 |
||
59 |
VarHandle vhArray; |
|
60 |
||
61 |
@BeforeClass |
|
62 |
public void setup() throws Exception { |
|
63 |
vhFinalField = MethodHandles.lookup().findVarHandle( |
|
64 |
VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.class); |
|
65 |
||
66 |
vhField = MethodHandles.lookup().findVarHandle( |
|
67 |
VarHandleTestMethodHandleAccess$Type$.class, "v", $type$.class); |
|
68 |
||
69 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
70 |
VarHandleTestMethodHandleAccess$Type$.class, "static_final_v", $type$.class); |
|
71 |
||
72 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
73 |
VarHandleTestMethodHandleAccess$Type$.class, "static_v", $type$.class); |
|
74 |
||
75 |
vhArray = MethodHandles.arrayElementVarHandle($type$[].class); |
|
76 |
} |
|
77 |
||
78 |
||
79 |
@DataProvider |
|
80 |
public Object[][] accessTestCaseProvider() throws Exception { |
|
81 |
List<AccessTestCase<?>> cases = new ArrayList<>(); |
|
82 |
||
83 |
for (VarHandleToMethodHandle f : VarHandleToMethodHandle.values()) { |
|
84 |
cases.add(new MethodHandleAccessTestCase("Instance field", |
|
85 |
vhField, f, hs -> testInstanceField(this, hs))); |
|
86 |
cases.add(new MethodHandleAccessTestCase("Instance field unsupported", |
|
87 |
vhField, f, hs -> testInstanceFieldUnsupported(this, hs), |
|
88 |
false)); |
|
89 |
||
90 |
cases.add(new MethodHandleAccessTestCase("Static field", |
|
91 |
vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticField)); |
|
92 |
cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
|
93 |
vhStaticField, f, VarHandleTestMethodHandleAccess$Type$::testStaticFieldUnsupported, |
|
94 |
false)); |
|
95 |
||
96 |
cases.add(new MethodHandleAccessTestCase("Array", |
|
97 |
vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArray)); |
|
98 |
cases.add(new MethodHandleAccessTestCase("Array unsupported", |
|
99 |
vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayUnsupported, |
|
100 |
false)); |
|
101 |
cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
|
102 |
vhArray, f, VarHandleTestMethodHandleAccess$Type$::testArrayIndexOutOfBounds, |
|
103 |
false)); |
|
104 |
} |
|
105 |
||
106 |
// Work around issue with jtreg summary reporting which truncates |
|
107 |
// the String result of Object.toString to 30 characters, hence |
|
108 |
// the first dummy argument |
|
109 |
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
|
110 |
} |
|
111 |
||
112 |
@Test(dataProvider = "accessTestCaseProvider") |
|
113 |
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { |
|
114 |
T t = atc.get(); |
|
115 |
int iters = atc.requiresLoop() ? ITERS : 1; |
|
116 |
for (int c = 0; c < iters; c++) { |
|
117 |
atc.testAccess(t); |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
||
122 |
static void testInstanceField(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { |
|
123 |
// Plain |
|
124 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
125 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
126 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 127 |
assertEquals(x, $value1$, "set $type$ value"); |
128 |
} |
|
129 |
||
130 |
||
131 |
// Volatile |
|
132 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
133 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
134 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
36934 | 135 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
136 |
} |
|
137 |
||
138 |
// Lazy |
|
139 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
140 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
141 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
36934 | 142 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
143 |
} |
|
144 |
||
145 |
// Opaque |
|
146 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
147 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
148 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
36934 | 149 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
150 |
} |
|
151 |
||
152 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
153 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 154 |
|
155 |
// Compare |
|
156 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
157 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$); |
36934 | 158 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
159 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 160 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
161 |
} |
|
162 |
||
163 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
164 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$); |
36934 | 165 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
166 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 167 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
168 |
} |
|
169 |
||
170 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
171 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value1$); |
36934 | 172 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
173 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 174 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
175 |
} |
|
176 |
||
177 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
178 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, $value2$, $value3$); |
36934 | 179 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
180 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 181 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
182 |
} |
|
183 |
||
184 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
185 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$); |
36934 | 186 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
187 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 188 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
189 |
} |
|
190 |
||
191 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
192 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$); |
36934 | 193 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
194 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 195 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
196 |
} |
|
197 |
||
198 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
199 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$); |
36934 | 200 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
201 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 202 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
203 |
} |
|
204 |
||
205 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
206 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$); |
36934 | 207 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
208 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 209 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
210 |
} |
|
211 |
||
212 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
213 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
217 |
assertEquals(success, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
218 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 219 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
220 |
} |
|
221 |
||
222 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
223 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
227 |
assertEquals(success, true, "weakCompareAndSetAcquire $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, $value1$, "weakCompareAndSetAcquire $type$"); |
230 |
} |
|
231 |
||
232 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
233 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
234 |
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
|
235 |
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
|
236 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
237 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
238 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 239 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
240 |
} |
|
241 |
||
242 |
// Compare set and get |
|
243 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
244 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value1$); |
36934 | 245 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
246 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 247 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
248 |
} |
|
249 |
#end[CAS] |
|
250 |
||
251 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
252 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 253 |
|
254 |
// get and add, add and get |
|
255 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
256 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$); |
36934 | 257 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
258 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$); |
36934 | 259 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
260 |
} |
|
261 |
#end[AtomicAdd] |
|
262 |
} |
|
263 |
||
264 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { |
|
265 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
266 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 267 |
checkUOE(am, () -> { |
268 |
boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
269 |
}); |
|
270 |
} |
|
271 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
272 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 273 |
checkUOE(am, () -> { |
274 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
275 |
}); |
|
276 |
} |
|
277 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
278 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 279 |
checkUOE(am, () -> { |
280 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
281 |
}); |
|
282 |
} |
|
283 |
#end[CAS] |
|
284 |
||
285 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
286 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 287 |
checkUOE(am, () -> { |
288 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
289 |
}); |
|
290 |
} |
|
291 |
#end[AtomicAdd] |
|
292 |
} |
|
293 |
||
294 |
||
295 |
static void testStaticField(Handles hs) throws Throwable { |
|
296 |
// Plain |
|
297 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
298 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
299 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 300 |
assertEquals(x, $value1$, "set $type$ value"); |
301 |
} |
|
302 |
||
303 |
||
304 |
// Volatile |
|
305 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
306 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
307 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 308 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
309 |
} |
|
310 |
||
311 |
// Lazy |
|
312 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
313 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
314 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 315 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
316 |
} |
|
317 |
||
318 |
// Opaque |
|
319 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
320 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
321 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 322 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
323 |
} |
|
324 |
||
325 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
326 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 327 |
|
328 |
// Compare |
|
329 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
330 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$); |
36934 | 331 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
332 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 333 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
334 |
} |
|
335 |
||
336 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
337 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$); |
36934 | 338 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
339 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 340 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
341 |
} |
|
342 |
||
343 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
344 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$); |
36934 | 345 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
346 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 347 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
348 |
} |
|
349 |
||
350 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
351 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$); |
36934 | 352 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
353 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 354 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
355 |
} |
|
356 |
||
357 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
358 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$); |
36934 | 359 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
360 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 361 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
362 |
} |
|
363 |
||
364 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
365 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$); |
36934 | 366 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
367 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 368 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
369 |
} |
|
370 |
||
371 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
372 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$); |
36934 | 373 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
374 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 375 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
376 |
} |
|
377 |
||
378 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
379 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$); |
36934 | 380 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
381 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 382 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
383 |
} |
|
384 |
||
385 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
386 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
390 |
assertEquals(success, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
391 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 392 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
393 |
} |
|
394 |
||
395 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
396 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
397 |
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
|
398 |
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
|
399 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
400 |
assertEquals(success, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
401 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 402 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
403 |
} |
|
404 |
||
405 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
406 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
407 |
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
|
408 |
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
|
409 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
410 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
411 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 412 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
413 |
} |
|
414 |
||
415 |
// Compare set and get |
|
416 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
417 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value1$); |
36934 | 418 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
419 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 420 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
421 |
} |
|
422 |
#end[CAS] |
|
423 |
||
424 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
425 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 426 |
|
427 |
// get and add, add and get |
|
428 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
429 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$); |
36934 | 430 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
431 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$); |
36934 | 432 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
433 |
} |
|
434 |
#end[AtomicAdd] |
|
435 |
} |
|
436 |
||
437 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
438 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
439 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 440 |
checkUOE(am, () -> { |
441 |
boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$); |
|
442 |
}); |
|
443 |
} |
|
444 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
445 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 446 |
checkUOE(am, () -> { |
447 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$); |
|
448 |
}); |
|
449 |
} |
|
450 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
451 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 452 |
checkUOE(am, () -> { |
453 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
454 |
}); |
|
455 |
} |
|
456 |
#end[CAS] |
|
457 |
||
458 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
459 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 460 |
checkUOE(am, () -> { |
461 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
462 |
}); |
|
463 |
} |
|
464 |
#end[AtomicAdd] |
|
465 |
} |
|
466 |
||
467 |
||
468 |
static void testArray(Handles hs) throws Throwable { |
|
469 |
$type$[] array = new $type$[10]; |
|
470 |
||
471 |
for (int i = 0; i < array.length; i++) { |
|
472 |
// Plain |
|
473 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
474 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
475 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 476 |
assertEquals(x, $value1$, "get $type$ value"); |
477 |
} |
|
478 |
||
479 |
||
480 |
// Volatile |
|
481 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
482 |
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
|
483 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 484 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
485 |
} |
|
486 |
||
487 |
// Lazy |
|
488 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
489 |
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
|
490 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 491 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
492 |
} |
|
493 |
||
494 |
// Opaque |
|
495 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
496 |
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
|
497 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 498 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
499 |
} |
|
500 |
||
501 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
502 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 503 |
|
504 |
// Compare |
|
505 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
506 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
36934 | 507 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
508 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 509 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
510 |
} |
|
511 |
||
512 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
513 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$); |
36934 | 514 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
515 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 516 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
517 |
} |
|
518 |
||
519 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
520 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
36934 | 521 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
522 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 523 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
524 |
} |
|
525 |
||
526 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
527 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$); |
36934 | 528 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
529 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 530 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
531 |
} |
|
532 |
||
533 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
534 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$); |
36934 | 535 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
536 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 537 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
538 |
} |
|
539 |
||
540 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
541 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$); |
36934 | 542 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
543 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 544 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
545 |
} |
|
546 |
||
547 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
548 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$); |
36934 | 549 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
550 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 551 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
552 |
} |
|
553 |
||
554 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
555 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$); |
36934 | 556 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
557 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 558 |
assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); |
559 |
} |
|
560 |
||
561 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
562 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
563 |
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
|
564 |
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
|
565 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
566 |
assertEquals(success, true, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
567 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 568 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
569 |
} |
|
570 |
||
571 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
572 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
573 |
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
|
574 |
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
|
575 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
576 |
assertEquals(success, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
577 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 578 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
579 |
} |
|
580 |
||
581 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
582 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
583 |
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
|
584 |
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
|
585 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
586 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
587 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 588 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
589 |
} |
|
590 |
||
591 |
// Compare set and get |
|
592 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
593 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value1$); |
36934 | 594 |
assertEquals(o, $value2$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
595 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 596 |
assertEquals(x, $value1$, "getAndSet $type$ value"); |
597 |
} |
|
598 |
#end[CAS] |
|
599 |
||
600 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
601 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 602 |
|
603 |
// get and add, add and get |
|
604 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
605 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$); |
36934 | 606 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
607 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$); |
36934 | 608 |
assertEquals(c, $value1$ + $value3$ + $value3$, "getAndAdd $type$ value"); |
609 |
} |
|
610 |
#end[AtomicAdd] |
|
611 |
} |
|
612 |
} |
|
613 |
||
614 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
615 |
$type$[] array = new $type$[10]; |
|
616 |
||
617 |
final int i = 0; |
|
618 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
619 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 620 |
checkUOE(am, () -> { |
621 |
boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
622 |
}); |
|
623 |
} |
|
624 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
625 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 626 |
checkUOE(am, () -> { |
627 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
628 |
}); |
|
629 |
} |
|
630 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
631 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 632 |
checkUOE(am, () -> { |
633 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
634 |
}); |
|
635 |
} |
|
636 |
#end[CAS] |
|
637 |
||
638 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
639 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 640 |
checkUOE(am, () -> { |
641 |
$type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
642 |
}); |
|
643 |
} |
|
644 |
#end[AtomicAdd] |
|
645 |
} |
|
646 |
||
647 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
648 |
$type$[] array = new $type$[10]; |
|
649 |
||
650 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
651 |
final int ci = i; |
|
652 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
653 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 654 |
checkIOOBE(am, () -> { |
655 |
$type$ x = ($type$) hs.get(am).invokeExact(array, ci); |
|
656 |
}); |
|
657 |
} |
|
658 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
659 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 660 |
checkIOOBE(am, () -> { |
661 |
hs.get(am).invokeExact(array, ci, $value1$); |
|
662 |
}); |
|
663 |
} |
|
664 |
||
665 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
666 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 667 |
checkIOOBE(am, () -> { |
668 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$); |
|
669 |
}); |
|
670 |
} |
|
671 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
672 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 673 |
checkIOOBE(am, () -> { |
674 |
$type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$); |
|
675 |
}); |
|
676 |
} |
|
677 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
678 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 679 |
checkIOOBE(am, () -> { |
680 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$); |
|
681 |
}); |
|
682 |
} |
|
683 |
#end[CAS] |
|
684 |
||
685 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
686 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 687 |
checkIOOBE(am, () -> { |
688 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$); |
|
689 |
}); |
|
690 |
} |
|
691 |
#end[AtomicAdd] |
|
692 |
} |
|
693 |
} |
|
694 |
} |
|
695 |