author | psandoz |
Tue, 17 May 2016 12:06:41 +0200 | |
changeset 38328 | 40435a469d25 |
parent 37719 | add11bc0e6e2 |
child 38368 | c8eb5d6812c5 |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @run testng/othervm -Diters=20000 VarHandleTestMethodHandleAccessLong |
|
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 VarHandleTestMethodHandleAccessLong |
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 VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { |
|
43 |
static final long static_final_v = 1L; |
|
44 |
||
45 |
static long static_v; |
|
46 |
||
47 |
final long final_v = 1L; |
|
48 |
||
49 |
long 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 |
VarHandleTestMethodHandleAccessLong.class, "final_v", long.class); |
|
65 |
||
66 |
vhField = MethodHandles.lookup().findVarHandle( |
|
67 |
VarHandleTestMethodHandleAccessLong.class, "v", long.class); |
|
68 |
||
69 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
70 |
VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class); |
|
71 |
||
72 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
73 |
VarHandleTestMethodHandleAccessLong.class, "static_v", long.class); |
|
74 |
||
75 |
vhArray = MethodHandles.arrayElementVarHandle(long[].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, VarHandleTestMethodHandleAccessLong::testStaticField)); |
|
92 |
cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
|
93 |
vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported, |
|
94 |
false)); |
|
95 |
||
96 |
cases.add(new MethodHandleAccessTestCase("Array", |
|
97 |
vhArray, f, VarHandleTestMethodHandleAccessLong::testArray)); |
|
98 |
cases.add(new MethodHandleAccessTestCase("Array unsupported", |
|
99 |
vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported, |
|
100 |
false)); |
|
101 |
cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
|
102 |
vhArray, f, VarHandleTestMethodHandleAccessLong::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(VarHandleTestMethodHandleAccessLong 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, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
126 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 127 |
assertEquals(x, 1L, "set long 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, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
134 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
36934 | 135 |
assertEquals(x, 2L, "setVolatile long 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, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
141 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
36934 | 142 |
assertEquals(x, 1L, "setRelease long 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, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
148 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
36934 | 149 |
assertEquals(x, 2L, "setOpaque long value"); |
150 |
} |
|
151 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
152 |
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); |
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, 1L, 2L); |
36934 | 157 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
158 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 159 |
assertEquals(x, 2L, "success compareAndSet long 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, 1L, 3L); |
36934 | 164 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
165 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 166 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
167 |
} |
|
168 |
||
169 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
170 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 1L); |
36934 | 171 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
172 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 173 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
174 |
} |
|
175 |
||
176 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
177 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 3L); |
36934 | 178 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
179 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 180 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
181 |
} |
|
182 |
||
183 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
184 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 2L); |
36934 | 185 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
186 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 187 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
188 |
} |
|
189 |
||
190 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
191 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 3L); |
36934 | 192 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
193 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 194 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
195 |
} |
|
196 |
||
197 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
198 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 1L); |
36934 | 199 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
200 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 201 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
202 |
} |
|
203 |
||
204 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
205 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 3L); |
36934 | 206 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
207 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 208 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
209 |
} |
|
210 |
||
211 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
212 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 1L, 2L); |
36934 | 213 |
assertEquals(r, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
214 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 215 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
216 |
} |
|
217 |
||
218 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
219 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2L, 1L); |
36934 | 220 |
assertEquals(r, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
221 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 222 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
223 |
} |
|
224 |
||
225 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
226 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1L, 2L); |
36934 | 227 |
assertEquals(r, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
228 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 229 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
230 |
} |
|
231 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
232 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
233 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, 2L, 1L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
234 |
assertEquals(r, true, "weakCompareAndSetVolatile long"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
235 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
236 |
assertEquals(x, 1L, "weakCompareAndSetVolatile long value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
237 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
238 |
|
36934 | 239 |
// Compare set and get |
240 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
241 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
242 |
assertEquals(o, 1L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
243 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
244 |
assertEquals(x, 2L, "getAndSet long value"); |
36934 | 245 |
} |
246 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
247 |
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); |
36934 | 248 |
|
249 |
// get and add, add and get |
|
250 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
251 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3L); |
36934 | 252 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
253 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3L); |
36934 | 254 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
255 |
} |
|
256 |
} |
|
257 |
||
258 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable { |
|
259 |
||
260 |
} |
|
261 |
||
262 |
||
263 |
static void testStaticField(Handles hs) throws Throwable { |
|
264 |
// Plain |
|
265 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
266 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
267 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 268 |
assertEquals(x, 1L, "set long value"); |
269 |
} |
|
270 |
||
271 |
||
272 |
// Volatile |
|
273 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
274 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
275 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 276 |
assertEquals(x, 2L, "setVolatile long value"); |
277 |
} |
|
278 |
||
279 |
// Lazy |
|
280 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
281 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
282 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 283 |
assertEquals(x, 1L, "setRelease long value"); |
284 |
} |
|
285 |
||
286 |
// Opaque |
|
287 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
288 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
289 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 290 |
assertEquals(x, 2L, "setOpaque long value"); |
291 |
} |
|
292 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
293 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 294 |
|
295 |
// Compare |
|
296 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
297 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 2L); |
36934 | 298 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
299 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 300 |
assertEquals(x, 2L, "success compareAndSet long value"); |
301 |
} |
|
302 |
||
303 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
304 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 3L); |
36934 | 305 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
306 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 307 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
308 |
} |
|
309 |
||
310 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
311 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 1L); |
36934 | 312 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
313 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 314 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
315 |
} |
|
316 |
||
317 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
318 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 3L); |
36934 | 319 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
320 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 321 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
322 |
} |
|
323 |
||
324 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
325 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 2L); |
36934 | 326 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
327 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 328 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
329 |
} |
|
330 |
||
331 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
332 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 3L); |
36934 | 333 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
334 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 335 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
336 |
} |
|
337 |
||
338 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
339 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 1L); |
36934 | 340 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
341 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 342 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
343 |
} |
|
344 |
||
345 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
346 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 3L); |
36934 | 347 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
348 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 349 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
350 |
} |
|
351 |
||
352 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
353 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L); |
36934 | 354 |
assertEquals(r, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
355 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 356 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
357 |
} |
|
358 |
||
359 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
360 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L); |
36934 | 361 |
assertEquals(r, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
362 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 363 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
364 |
} |
|
365 |
||
366 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
367 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L); |
36934 | 368 |
assertEquals(r, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
369 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 370 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
371 |
} |
|
372 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
373 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
374 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(2L, 1L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
375 |
assertEquals(r, true, "weakCompareAndSetVolatile long"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
376 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
377 |
assertEquals(x, 1L, "weakCompareAndSetVolatile long value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
378 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
379 |
|
36934 | 380 |
// Compare set and get |
381 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
382 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
383 |
assertEquals(o, 1L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
384 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
385 |
assertEquals(x, 2L, "getAndSet long value"); |
36934 | 386 |
} |
387 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
388 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 389 |
|
390 |
// get and add, add and get |
|
391 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
392 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3L); |
36934 | 393 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
394 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3L); |
36934 | 395 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
396 |
} |
|
397 |
} |
|
398 |
||
399 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
400 |
||
401 |
} |
|
402 |
||
403 |
||
404 |
static void testArray(Handles hs) throws Throwable { |
|
405 |
long[] array = new long[10]; |
|
406 |
||
407 |
for (int i = 0; i < array.length; i++) { |
|
408 |
// Plain |
|
409 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
410 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
411 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 412 |
assertEquals(x, 1L, "get long value"); |
413 |
} |
|
414 |
||
415 |
||
416 |
// Volatile |
|
417 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
418 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
419 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 420 |
assertEquals(x, 2L, "setVolatile long value"); |
421 |
} |
|
422 |
||
423 |
// Lazy |
|
424 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
425 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
426 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 427 |
assertEquals(x, 1L, "setRelease long value"); |
428 |
} |
|
429 |
||
430 |
// Opaque |
|
431 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
432 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
433 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 434 |
assertEquals(x, 2L, "setOpaque long value"); |
435 |
} |
|
436 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
437 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 438 |
|
439 |
// Compare |
|
440 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
441 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); |
36934 | 442 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
443 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 444 |
assertEquals(x, 2L, "success compareAndSet long value"); |
445 |
} |
|
446 |
||
447 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
448 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 3L); |
36934 | 449 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
450 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 451 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
452 |
} |
|
453 |
||
454 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
455 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 1L); |
36934 | 456 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
457 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 458 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
459 |
} |
|
460 |
||
461 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
462 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 3L); |
36934 | 463 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
464 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 465 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
466 |
} |
|
467 |
||
468 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
469 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 2L); |
36934 | 470 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
471 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 472 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
473 |
} |
|
474 |
||
475 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
476 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 3L); |
36934 | 477 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
478 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 479 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
480 |
} |
|
481 |
||
482 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
483 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 1L); |
36934 | 484 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
485 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 486 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
487 |
} |
|
488 |
||
489 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
490 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 3L); |
36934 | 491 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
492 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 493 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
494 |
} |
|
495 |
||
496 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
497 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); |
36934 | 498 |
assertEquals(r, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
499 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 500 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
501 |
} |
|
502 |
||
503 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
504 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L); |
36934 | 505 |
assertEquals(r, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
506 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 507 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
508 |
} |
|
509 |
||
510 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
511 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L); |
36934 | 512 |
assertEquals(r, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
513 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 514 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
515 |
} |
|
516 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
517 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
518 |
boolean r = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, 2L, 1L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
519 |
assertEquals(r, true, "weakCompareAndSetVolatile long"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
520 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
521 |
assertEquals(x, 1L, "weakCompareAndSetVolatile long value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
522 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
523 |
|
36934 | 524 |
// Compare set and get |
525 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
526 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2L); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
527 |
assertEquals(o, 1L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
528 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37343
diff
changeset
|
529 |
assertEquals(x, 2L, "getAndSet long value"); |
36934 | 530 |
} |
531 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
532 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 533 |
|
534 |
// get and add, add and get |
|
535 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
536 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3L); |
36934 | 537 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
538 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3L); |
36934 | 539 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
||
544 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
545 |
long[] array = new long[10]; |
|
546 |
||
547 |
final int i = 0; |
|
548 |
||
549 |
} |
|
550 |
||
551 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
552 |
long[] array = new long[10]; |
|
553 |
||
554 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
555 |
final int ci = i; |
|
556 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
557 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 558 |
checkIOOBE(am, () -> { |
559 |
long x = (long) hs.get(am).invokeExact(array, ci); |
|
560 |
}); |
|
561 |
} |
|
562 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
563 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 564 |
checkIOOBE(am, () -> { |
565 |
hs.get(am).invokeExact(array, ci, 1L); |
|
566 |
}); |
|
567 |
} |
|
568 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
569 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 570 |
checkIOOBE(am, () -> { |
571 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1L, 2L); |
|
572 |
}); |
|
573 |
} |
|
574 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
575 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 576 |
checkIOOBE(am, () -> { |
577 |
long r = (long) hs.get(am).invokeExact(array, ci, 2L, 1L); |
|
578 |
}); |
|
579 |
} |
|
580 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
581 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 582 |
checkIOOBE(am, () -> { |
583 |
long o = (long) hs.get(am).invokeExact(array, ci, 1L); |
|
584 |
}); |
|
585 |
} |
|
586 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
587 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 588 |
checkIOOBE(am, () -> { |
589 |
long o = (long) hs.get(am).invokeExact(array, ci, 3L); |
|
590 |
}); |
|
591 |
} |
|
592 |
} |
|
593 |
} |
|
594 |
} |
|
595 |