author | amurillo |
Tue, 17 May 2016 05:38:15 -0700 | |
changeset 38368 | c8eb5d6812c5 |
parent 38358 | cb99c6d2af1b |
parent 38328 | 40435a469d25 |
child 38372 | 017d7578731c |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @run testng/othervm -Diters=20000 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 |
{ |
|
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, 1L, 2L); |
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 long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
217 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 218 |
assertEquals(x, 2L, "weakCompareAndSet long 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, 2L, 1L); |
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 long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
227 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 228 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
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, 1L, 2L); |
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 long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
237 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 238 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
239 |
} |
|
240 |
||
241 |
// Compare set and get |
|
242 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
243 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 1L); |
36934 | 244 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
245 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 246 |
assertEquals(x, 1L, "getAndSet long value"); |
247 |
} |
|
248 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
249 |
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); |
36934 | 250 |
|
251 |
// get and add, add and get |
|
252 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
253 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3L); |
36934 | 254 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
255 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3L); |
36934 | 256 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
257 |
} |
|
258 |
} |
|
259 |
||
260 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable { |
|
261 |
||
262 |
} |
|
263 |
||
264 |
||
265 |
static void testStaticField(Handles hs) throws Throwable { |
|
266 |
// Plain |
|
267 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
268 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
269 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 270 |
assertEquals(x, 1L, "set long value"); |
271 |
} |
|
272 |
||
273 |
||
274 |
// Volatile |
|
275 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
276 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
277 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 278 |
assertEquals(x, 2L, "setVolatile long value"); |
279 |
} |
|
280 |
||
281 |
// Lazy |
|
282 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
283 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
284 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 285 |
assertEquals(x, 1L, "setRelease long value"); |
286 |
} |
|
287 |
||
288 |
// Opaque |
|
289 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
290 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
291 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 292 |
assertEquals(x, 2L, "setOpaque long value"); |
293 |
} |
|
294 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
295 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 296 |
|
297 |
// Compare |
|
298 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
299 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 2L); |
36934 | 300 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
301 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 302 |
assertEquals(x, 2L, "success compareAndSet long value"); |
303 |
} |
|
304 |
||
305 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
306 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 3L); |
36934 | 307 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
308 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 309 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
310 |
} |
|
311 |
||
312 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
313 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 1L); |
36934 | 314 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
315 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 316 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
317 |
} |
|
318 |
||
319 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
320 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 3L); |
36934 | 321 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
322 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 323 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
324 |
} |
|
325 |
||
326 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
327 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 2L); |
36934 | 328 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
329 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 330 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
331 |
} |
|
332 |
||
333 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
334 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 3L); |
36934 | 335 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
336 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 337 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
338 |
} |
|
339 |
||
340 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
341 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 1L); |
36934 | 342 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
343 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 344 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
345 |
} |
|
346 |
||
347 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
348 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 3L); |
36934 | 349 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
350 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 351 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
352 |
} |
|
353 |
||
354 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
355 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
356 |
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
|
357 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(1L, 2L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
358 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
359 |
assertEquals(success, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
360 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 361 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
362 |
} |
|
363 |
||
364 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
365 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
366 |
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
|
367 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(2L, 1L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
368 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
369 |
assertEquals(success, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
370 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 371 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
372 |
} |
|
373 |
||
374 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
375 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
376 |
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
|
377 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1L, 2L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
378 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
379 |
assertEquals(success, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
380 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 381 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
382 |
} |
|
383 |
||
384 |
// Compare set and get |
|
385 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
386 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 1L); |
36934 | 387 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
388 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 389 |
assertEquals(x, 1L, "getAndSet long value"); |
390 |
} |
|
391 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
392 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 393 |
|
394 |
// get and add, add and get |
|
395 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
396 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3L); |
36934 | 397 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
398 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3L); |
36934 | 399 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
400 |
} |
|
401 |
} |
|
402 |
||
403 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
404 |
||
405 |
} |
|
406 |
||
407 |
||
408 |
static void testArray(Handles hs) throws Throwable { |
|
409 |
long[] array = new long[10]; |
|
410 |
||
411 |
for (int i = 0; i < array.length; i++) { |
|
412 |
// Plain |
|
413 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
414 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
415 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 416 |
assertEquals(x, 1L, "get long value"); |
417 |
} |
|
418 |
||
419 |
||
420 |
// Volatile |
|
421 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
422 |
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
|
423 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 424 |
assertEquals(x, 2L, "setVolatile long value"); |
425 |
} |
|
426 |
||
427 |
// Lazy |
|
428 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
429 |
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
|
430 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 431 |
assertEquals(x, 1L, "setRelease long value"); |
432 |
} |
|
433 |
||
434 |
// Opaque |
|
435 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
436 |
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
|
437 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 438 |
assertEquals(x, 2L, "setOpaque long value"); |
439 |
} |
|
440 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
441 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 442 |
|
443 |
// Compare |
|
444 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
445 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); |
36934 | 446 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
447 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 448 |
assertEquals(x, 2L, "success compareAndSet long value"); |
449 |
} |
|
450 |
||
451 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
452 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 3L); |
36934 | 453 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
454 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 455 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
456 |
} |
|
457 |
||
458 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
459 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 1L); |
36934 | 460 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
461 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 462 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
463 |
} |
|
464 |
||
465 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
466 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 3L); |
36934 | 467 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
468 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 469 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
470 |
} |
|
471 |
||
472 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
473 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 2L); |
36934 | 474 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
475 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 476 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
477 |
} |
|
478 |
||
479 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
480 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 3L); |
36934 | 481 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
482 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 483 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
484 |
} |
|
485 |
||
486 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
487 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 1L); |
36934 | 488 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
489 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 490 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
491 |
} |
|
492 |
||
493 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
494 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 3L); |
36934 | 495 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
496 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 497 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
498 |
} |
|
499 |
||
500 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
501 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
502 |
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
|
503 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
504 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
505 |
assertEquals(success, true, "weakCompareAndSet 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, 2L, "weakCompareAndSet long value"); |
508 |
} |
|
509 |
||
510 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
511 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
512 |
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
|
513 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2L, 1L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
514 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
515 |
assertEquals(success, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
516 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 517 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
518 |
} |
|
519 |
||
520 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
521 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
522 |
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
|
523 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, 1L, 2L); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
524 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
525 |
assertEquals(success, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
526 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 527 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
528 |
} |
|
529 |
||
530 |
// Compare set and get |
|
531 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
532 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 1L); |
36934 | 533 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
534 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 535 |
assertEquals(x, 1L, "getAndSet long value"); |
536 |
} |
|
537 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
538 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 539 |
|
540 |
// get and add, add and get |
|
541 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
542 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3L); |
36934 | 543 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
544 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3L); |
36934 | 545 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
||
550 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
551 |
long[] array = new long[10]; |
|
552 |
||
553 |
final int i = 0; |
|
554 |
||
555 |
} |
|
556 |
||
557 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
558 |
long[] array = new long[10]; |
|
559 |
||
560 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
561 |
final int ci = i; |
|
562 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
563 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 564 |
checkIOOBE(am, () -> { |
565 |
long x = (long) hs.get(am).invokeExact(array, ci); |
|
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.SET)) { |
36934 | 570 |
checkIOOBE(am, () -> { |
571 |
hs.get(am).invokeExact(array, ci, 1L); |
|
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_SET)) { |
36934 | 576 |
checkIOOBE(am, () -> { |
577 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1L, 2L); |
|
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.COMPARE_AND_EXCHANGE)) { |
36934 | 582 |
checkIOOBE(am, () -> { |
583 |
long r = (long) hs.get(am).invokeExact(array, ci, 2L, 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_SET)) { |
36934 | 588 |
checkIOOBE(am, () -> { |
589 |
long o = (long) hs.get(am).invokeExact(array, ci, 1L); |
|
590 |
}); |
|
591 |
} |
|
592 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
593 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 594 |
checkIOOBE(am, () -> { |
595 |
long o = (long) hs.get(am).invokeExact(array, ci, 3L); |
|
596 |
}); |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
} |
|
601 |