author | psandoz |
Mon, 20 Jun 2016 17:57:19 +0200 | |
changeset 39471 | 6622892a347a |
parent 39470 | d6f8b4a85fb0 |
child 39472 | 6df82f4c63ac |
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 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
241 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
242 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
243 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
244 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, $value2$, $value1$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
245 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
246 |
assertEquals(success, true, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
247 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
248 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
249 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
250 |
|
36934 | 251 |
// Compare set and get |
252 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
253 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
254 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
255 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
256 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 257 |
} |
258 |
#end[CAS] |
|
259 |
||
260 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
261 |
hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); |
36934 | 262 |
|
263 |
// get and add, add and get |
|
264 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
265 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value3$); |
36934 | 266 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
267 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, $value3$); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
268 |
assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value"); |
36934 | 269 |
} |
270 |
#end[AtomicAdd] |
|
271 |
} |
|
272 |
||
273 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { |
|
274 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
275 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 276 |
checkUOE(am, () -> { |
277 |
boolean r = (boolean) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
278 |
}); |
|
279 |
} |
|
280 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
281 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 282 |
checkUOE(am, () -> { |
283 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$, $value2$); |
|
284 |
}); |
|
285 |
} |
|
286 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
287 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 288 |
checkUOE(am, () -> { |
289 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
290 |
}); |
|
291 |
} |
|
292 |
#end[CAS] |
|
293 |
||
294 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
295 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 296 |
checkUOE(am, () -> { |
297 |
$type$ r = ($type$) hs.get(am).invokeExact(recv, $value1$); |
|
298 |
}); |
|
299 |
} |
|
300 |
#end[AtomicAdd] |
|
301 |
} |
|
302 |
||
303 |
||
304 |
static void testStaticField(Handles hs) throws Throwable { |
|
305 |
// Plain |
|
306 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
307 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
308 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 309 |
assertEquals(x, $value1$, "set $type$ value"); |
310 |
} |
|
311 |
||
312 |
||
313 |
// Volatile |
|
314 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
315 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
316 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 317 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
318 |
} |
|
319 |
||
320 |
// Lazy |
|
321 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
322 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
323 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 324 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
325 |
} |
|
326 |
||
327 |
// Opaque |
|
328 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
329 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
330 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 331 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
332 |
} |
|
333 |
||
334 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
335 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 336 |
|
337 |
// Compare |
|
338 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
339 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$); |
36934 | 340 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
341 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 342 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
343 |
} |
|
344 |
||
345 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
346 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$); |
36934 | 347 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
348 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 349 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
350 |
} |
|
351 |
||
352 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
353 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value1$); |
36934 | 354 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
355 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 356 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
357 |
} |
|
358 |
||
359 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
360 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact($value2$, $value3$); |
36934 | 361 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
362 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 363 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
364 |
} |
|
365 |
||
366 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
367 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$); |
36934 | 368 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
369 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 370 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
371 |
} |
|
372 |
||
373 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
374 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$); |
36934 | 375 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
376 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 377 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
378 |
} |
|
379 |
||
380 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
381 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$); |
36934 | 382 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
383 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 384 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
385 |
} |
|
386 |
||
387 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
388 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$); |
36934 | 389 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $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, $value1$, "failing compareAndExchangeRelease $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).invokeExact($value1$, $value2$); |
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, "weakCompareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
400 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 401 |
assertEquals(x, $value2$, "weakCompareAndSet $type$ value"); |
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_ACQUIRE).invokeExact($value2$, $value1$); |
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, "weakCompareAndSetAcquire $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, $value1$, "weakCompareAndSetAcquire $type$"); |
412 |
} |
|
413 |
||
414 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
415 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
416 |
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
|
417 |
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
|
418 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
419 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
420 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 421 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
422 |
} |
|
423 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
424 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
425 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
426 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
427 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact($value2$, $value1$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
428 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
429 |
assertEquals(success, true, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
430 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
431 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
432 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
433 |
|
36934 | 434 |
// Compare set and get |
435 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
436 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact( $value2$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
437 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
438 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
439 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 440 |
} |
441 |
#end[CAS] |
|
442 |
||
443 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
444 |
hs.get(TestAccessMode.SET).invokeExact($value1$); |
36934 | 445 |
|
446 |
// get and add, add and get |
|
447 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
448 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( $value3$); |
36934 | 449 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
450 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact($value3$); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
451 |
assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value"); |
36934 | 452 |
} |
453 |
#end[AtomicAdd] |
|
454 |
} |
|
455 |
||
456 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
457 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
458 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 459 |
checkUOE(am, () -> { |
460 |
boolean r = (boolean) hs.get(am).invokeExact($value1$, $value2$); |
|
461 |
}); |
|
462 |
} |
|
463 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
464 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 465 |
checkUOE(am, () -> { |
466 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$, $value2$); |
|
467 |
}); |
|
468 |
} |
|
469 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
470 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 471 |
checkUOE(am, () -> { |
472 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
473 |
}); |
|
474 |
} |
|
475 |
#end[CAS] |
|
476 |
||
477 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
478 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 479 |
checkUOE(am, () -> { |
480 |
$type$ r = ($type$) hs.get(am).invokeExact($value1$); |
|
481 |
}); |
|
482 |
} |
|
483 |
#end[AtomicAdd] |
|
484 |
} |
|
485 |
||
486 |
||
487 |
static void testArray(Handles hs) throws Throwable { |
|
488 |
$type$[] array = new $type$[10]; |
|
489 |
||
490 |
for (int i = 0; i < array.length; i++) { |
|
491 |
// Plain |
|
492 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
493 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
494 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 495 |
assertEquals(x, $value1$, "get $type$ value"); |
496 |
} |
|
497 |
||
498 |
||
499 |
// Volatile |
|
500 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
501 |
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
|
502 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 503 |
assertEquals(x, $value2$, "setVolatile $type$ value"); |
504 |
} |
|
505 |
||
506 |
// Lazy |
|
507 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
508 |
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
|
509 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 510 |
assertEquals(x, $value1$, "setRelease $type$ value"); |
511 |
} |
|
512 |
||
513 |
// Opaque |
|
514 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
515 |
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
|
516 |
$type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 517 |
assertEquals(x, $value2$, "setOpaque $type$ value"); |
518 |
} |
|
519 |
||
520 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
521 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 522 |
|
523 |
// Compare |
|
524 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
525 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); |
36934 | 526 |
assertEquals(r, true, "success compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
527 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 528 |
assertEquals(x, $value2$, "success compareAndSet $type$ value"); |
529 |
} |
|
530 |
||
531 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
532 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$); |
36934 | 533 |
assertEquals(r, false, "failing compareAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
534 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 535 |
assertEquals(x, $value2$, "failing compareAndSet $type$ value"); |
536 |
} |
|
537 |
||
538 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
539 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
36934 | 540 |
assertEquals(r, $value2$, "success compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
541 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 542 |
assertEquals(x, $value1$, "success compareAndExchangeVolatile $type$ value"); |
543 |
} |
|
544 |
||
545 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
546 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, $value2$, $value3$); |
36934 | 547 |
assertEquals(r, $value1$, "failing compareAndExchangeVolatile $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
548 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 549 |
assertEquals(x, $value1$, "failing compareAndExchangeVolatile $type$ value"); |
550 |
} |
|
551 |
||
552 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
553 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$); |
36934 | 554 |
assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
555 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 556 |
assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); |
557 |
} |
|
558 |
||
559 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
560 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$); |
36934 | 561 |
assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
562 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 563 |
assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); |
564 |
} |
|
565 |
||
566 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
567 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$); |
36934 | 568 |
assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
569 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 570 |
assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); |
571 |
} |
|
572 |
||
573 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
574 |
$type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$); |
36934 | 575 |
assertEquals(r, $value1$, "failing compareAndExchangeRelease $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$, "failing compareAndExchangeRelease $type$ value"); |
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).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, "weakCompareAndSet $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$, "weakCompareAndSet $type$ value"); |
588 |
} |
|
589 |
||
590 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
591 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
592 |
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
|
593 |
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
|
594 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
595 |
assertEquals(success, true, "weakCompareAndSetAcquire $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
596 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 597 |
assertEquals(x, $value1$, "weakCompareAndSetAcquire $type$"); |
598 |
} |
|
599 |
||
600 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
601 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
602 |
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
|
603 |
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
|
604 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
605 |
assertEquals(success, true, "weakCompareAndSetRelease $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
606 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 607 |
assertEquals(x, $value2$, "weakCompareAndSetRelease $type$"); |
608 |
} |
|
609 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
610 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
611 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
612 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
613 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, $value2$, $value1$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
614 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
615 |
assertEquals(success, true, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
616 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
617 |
assertEquals(x, $value1$, "weakCompareAndSetVolatile $type$"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
618 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
619 |
|
36934 | 620 |
// Compare set and get |
621 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
622 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
623 |
assertEquals(o, $value1$, "getAndSet $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
624 |
$type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
625 |
assertEquals(x, $value2$, "getAndSet $type$ value"); |
36934 | 626 |
} |
627 |
#end[CAS] |
|
628 |
||
629 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
630 |
hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); |
36934 | 631 |
|
632 |
// get and add, add and get |
|
633 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
634 |
$type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value3$); |
36934 | 635 |
assertEquals(o, $value1$, "getAndAdd $type$"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
636 |
$type$ c = ($type$) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, $value3$); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
637 |
assertEquals(c, ($type$)($value1$ + $value3$ + $value3$), "getAndAdd $type$ value"); |
36934 | 638 |
} |
639 |
#end[AtomicAdd] |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
644 |
$type$[] array = new $type$[10]; |
|
645 |
||
646 |
final int i = 0; |
|
647 |
#if[!CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
648 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 649 |
checkUOE(am, () -> { |
650 |
boolean r = (boolean) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
651 |
}); |
|
652 |
} |
|
653 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
654 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 655 |
checkUOE(am, () -> { |
656 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$, $value2$); |
|
657 |
}); |
|
658 |
} |
|
659 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
660 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 661 |
checkUOE(am, () -> { |
662 |
$type$ r = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
663 |
}); |
|
664 |
} |
|
665 |
#end[CAS] |
|
666 |
||
667 |
#if[!AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
668 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 669 |
checkUOE(am, () -> { |
670 |
$type$ o = ($type$) hs.get(am).invokeExact(array, i, $value1$); |
|
671 |
}); |
|
672 |
} |
|
673 |
#end[AtomicAdd] |
|
674 |
} |
|
675 |
||
676 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
677 |
$type$[] array = new $type$[10]; |
|
678 |
||
679 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
680 |
final int ci = i; |
|
681 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
682 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 683 |
checkIOOBE(am, () -> { |
684 |
$type$ x = ($type$) hs.get(am).invokeExact(array, ci); |
|
685 |
}); |
|
686 |
} |
|
687 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
688 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 689 |
checkIOOBE(am, () -> { |
690 |
hs.get(am).invokeExact(array, ci, $value1$); |
|
691 |
}); |
|
692 |
} |
|
693 |
||
694 |
#if[CAS] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
695 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 696 |
checkIOOBE(am, () -> { |
697 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, $value1$, $value2$); |
|
698 |
}); |
|
699 |
} |
|
700 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
701 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 702 |
checkIOOBE(am, () -> { |
703 |
$type$ r = ($type$) hs.get(am).invokeExact(array, ci, $value2$, $value1$); |
|
704 |
}); |
|
705 |
} |
|
706 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
707 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 708 |
checkIOOBE(am, () -> { |
709 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value1$); |
|
710 |
}); |
|
711 |
} |
|
712 |
#end[CAS] |
|
713 |
||
714 |
#if[AtomicAdd] |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
715 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 716 |
checkIOOBE(am, () -> { |
717 |
$type$ o = ($type$) hs.get(am).invokeExact(array, ci, $value3$); |
|
718 |
}); |
|
719 |
} |
|
720 |
#end[AtomicAdd] |
|
721 |
} |
|
722 |
} |
|
723 |
} |
|
724 |