author | vlivanov |
Mon, 09 May 2016 12:39:41 +0300 | |
changeset 38358 | cb99c6d2af1b |
parent 37719 | add11bc0e6e2 |
parent 38355 | 674cfd9b90cf |
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 |
|
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 VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { |
|
42 |
static final long static_final_v = 1L; |
|
43 |
||
44 |
static long static_v; |
|
45 |
||
46 |
final long final_v = 1L; |
|
47 |
||
48 |
long 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 |
VarHandleTestMethodHandleAccessLong.class, "final_v", long.class); |
|
64 |
||
65 |
vhField = MethodHandles.lookup().findVarHandle( |
|
66 |
VarHandleTestMethodHandleAccessLong.class, "v", long.class); |
|
67 |
||
68 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
69 |
VarHandleTestMethodHandleAccessLong.class, "static_final_v", long.class); |
|
70 |
||
71 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
72 |
VarHandleTestMethodHandleAccessLong.class, "static_v", long.class); |
|
73 |
||
74 |
vhArray = MethodHandles.arrayElementVarHandle(long[].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, VarHandleTestMethodHandleAccessLong::testStaticField)); |
|
91 |
cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
|
92 |
vhStaticField, f, VarHandleTestMethodHandleAccessLong::testStaticFieldUnsupported, |
|
93 |
false)); |
|
94 |
||
95 |
cases.add(new MethodHandleAccessTestCase("Array", |
|
96 |
vhArray, f, VarHandleTestMethodHandleAccessLong::testArray)); |
|
97 |
cases.add(new MethodHandleAccessTestCase("Array unsupported", |
|
98 |
vhArray, f, VarHandleTestMethodHandleAccessLong::testArrayUnsupported, |
|
99 |
false)); |
|
100 |
cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
|
101 |
vhArray, f, VarHandleTestMethodHandleAccessLong::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(VarHandleTestMethodHandleAccessLong 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, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
125 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 126 |
assertEquals(x, 1L, "set long 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, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
133 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
36934 | 134 |
assertEquals(x, 2L, "setVolatile long 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, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
140 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
36934 | 141 |
assertEquals(x, 1L, "setRelease long 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, 2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
147 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
36934 | 148 |
assertEquals(x, 2L, "setOpaque long value"); |
149 |
} |
|
150 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
151 |
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); |
36934 | 152 |
|
153 |
// Compare |
|
154 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
155 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 2L); |
36934 | 156 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
157 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 158 |
assertEquals(x, 2L, "success compareAndSet long value"); |
159 |
} |
|
160 |
||
161 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
162 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1L, 3L); |
36934 | 163 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
164 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 165 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
166 |
} |
|
167 |
||
168 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
169 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 1L); |
36934 | 170 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
171 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 172 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
173 |
} |
|
174 |
||
175 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
176 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, 2L, 3L); |
36934 | 177 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
178 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 179 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
180 |
} |
|
181 |
||
182 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
183 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 2L); |
36934 | 184 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
185 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 186 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
187 |
} |
|
188 |
||
189 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
190 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1L, 3L); |
36934 | 191 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
192 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 193 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
194 |
} |
|
195 |
||
196 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
197 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 1L); |
36934 | 198 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
199 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 200 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
201 |
} |
|
202 |
||
203 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
204 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2L, 3L); |
36934 | 205 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
206 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 207 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
208 |
} |
|
209 |
||
210 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
211 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
212 |
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
|
213 |
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
|
214 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
215 |
assertEquals(success, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
216 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 217 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
218 |
} |
|
219 |
||
220 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
221 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
222 |
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
|
223 |
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
|
224 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
225 |
assertEquals(success, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
226 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 227 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
228 |
} |
|
229 |
||
230 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
231 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
235 |
assertEquals(success, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
236 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 237 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
238 |
} |
|
239 |
||
240 |
// Compare set and get |
|
241 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
242 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 1L); |
36934 | 243 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
244 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 245 |
assertEquals(x, 1L, "getAndSet long value"); |
246 |
} |
|
247 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
248 |
hs.get(TestAccessMode.SET).invokeExact(recv, 1L); |
36934 | 249 |
|
250 |
// get and add, add and get |
|
251 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
252 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 3L); |
36934 | 253 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
254 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, 3L); |
36934 | 255 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
256 |
} |
|
257 |
} |
|
258 |
||
259 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable { |
|
260 |
||
261 |
} |
|
262 |
||
263 |
||
264 |
static void testStaticField(Handles hs) throws Throwable { |
|
265 |
// Plain |
|
266 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
267 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
268 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 269 |
assertEquals(x, 1L, "set long value"); |
270 |
} |
|
271 |
||
272 |
||
273 |
// Volatile |
|
274 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
275 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
276 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 277 |
assertEquals(x, 2L, "setVolatile long value"); |
278 |
} |
|
279 |
||
280 |
// Lazy |
|
281 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
282 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
283 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 284 |
assertEquals(x, 1L, "setRelease long value"); |
285 |
} |
|
286 |
||
287 |
// Opaque |
|
288 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
289 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
290 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 291 |
assertEquals(x, 2L, "setOpaque long value"); |
292 |
} |
|
293 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
294 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 295 |
|
296 |
// Compare |
|
297 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
298 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 2L); |
36934 | 299 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
300 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 301 |
assertEquals(x, 2L, "success compareAndSet long value"); |
302 |
} |
|
303 |
||
304 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
305 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1L, 3L); |
36934 | 306 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
307 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 308 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
309 |
} |
|
310 |
||
311 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
312 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 1L); |
36934 | 313 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
314 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 315 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
316 |
} |
|
317 |
||
318 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
319 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(2L, 3L); |
36934 | 320 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
321 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 322 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
323 |
} |
|
324 |
||
325 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
326 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 2L); |
36934 | 327 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
328 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 329 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
330 |
} |
|
331 |
||
332 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
333 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1L, 3L); |
36934 | 334 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
335 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 336 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
337 |
} |
|
338 |
||
339 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
340 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 1L); |
36934 | 341 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
342 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 343 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
344 |
} |
|
345 |
||
346 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
347 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2L, 3L); |
36934 | 348 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
349 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 350 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
351 |
} |
|
352 |
||
353 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
354 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
358 |
assertEquals(success, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
359 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 360 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
361 |
} |
|
362 |
||
363 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
364 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
365 |
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
|
366 |
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
|
367 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
368 |
assertEquals(success, true, "weakCompareAndSetAcquire 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, 1L, "weakCompareAndSetAcquire long"); |
371 |
} |
|
372 |
||
373 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
374 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
375 |
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
|
376 |
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
|
377 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
378 |
assertEquals(success, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
379 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 380 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
381 |
} |
|
382 |
||
383 |
// Compare set and get |
|
384 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
385 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact( 1L); |
36934 | 386 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
387 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 388 |
assertEquals(x, 1L, "getAndSet long value"); |
389 |
} |
|
390 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
391 |
hs.get(TestAccessMode.SET).invokeExact(1L); |
36934 | 392 |
|
393 |
// get and add, add and get |
|
394 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
395 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( 3L); |
36934 | 396 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
397 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(3L); |
36934 | 398 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
399 |
} |
|
400 |
} |
|
401 |
||
402 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
403 |
||
404 |
} |
|
405 |
||
406 |
||
407 |
static void testArray(Handles hs) throws Throwable { |
|
408 |
long[] array = new long[10]; |
|
409 |
||
410 |
for (int i = 0; i < array.length; i++) { |
|
411 |
// Plain |
|
412 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
413 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
414 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 415 |
assertEquals(x, 1L, "get long value"); |
416 |
} |
|
417 |
||
418 |
||
419 |
// Volatile |
|
420 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
421 |
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
|
422 |
long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 423 |
assertEquals(x, 2L, "setVolatile long value"); |
424 |
} |
|
425 |
||
426 |
// Lazy |
|
427 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
428 |
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
|
429 |
long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 430 |
assertEquals(x, 1L, "setRelease long value"); |
431 |
} |
|
432 |
||
433 |
// Opaque |
|
434 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
435 |
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
|
436 |
long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 437 |
assertEquals(x, 2L, "setOpaque long value"); |
438 |
} |
|
439 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
440 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 441 |
|
442 |
// Compare |
|
443 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
444 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 2L); |
36934 | 445 |
assertEquals(r, true, "success compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
446 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 447 |
assertEquals(x, 2L, "success compareAndSet long value"); |
448 |
} |
|
449 |
||
450 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
451 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1L, 3L); |
36934 | 452 |
assertEquals(r, false, "failing compareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
453 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 454 |
assertEquals(x, 2L, "failing compareAndSet long value"); |
455 |
} |
|
456 |
||
457 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
458 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 1L); |
36934 | 459 |
assertEquals(r, 2L, "success compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
460 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 461 |
assertEquals(x, 1L, "success compareAndExchangeVolatile long value"); |
462 |
} |
|
463 |
||
464 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
465 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, 2L, 3L); |
36934 | 466 |
assertEquals(r, 1L, "failing compareAndExchangeVolatile long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
467 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 468 |
assertEquals(x, 1L, "failing compareAndExchangeVolatile long value"); |
469 |
} |
|
470 |
||
471 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
472 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 2L); |
36934 | 473 |
assertEquals(r, 1L, "success compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
474 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 475 |
assertEquals(x, 2L, "success compareAndExchangeAcquire long value"); |
476 |
} |
|
477 |
||
478 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
479 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1L, 3L); |
36934 | 480 |
assertEquals(r, 2L, "failing compareAndExchangeAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
481 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 482 |
assertEquals(x, 2L, "failing compareAndExchangeAcquire long value"); |
483 |
} |
|
484 |
||
485 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
486 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 1L); |
36934 | 487 |
assertEquals(r, 2L, "success compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
488 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 489 |
assertEquals(x, 1L, "success compareAndExchangeRelease long value"); |
490 |
} |
|
491 |
||
492 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
493 |
long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2L, 3L); |
36934 | 494 |
assertEquals(r, 1L, "failing compareAndExchangeRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
495 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 496 |
assertEquals(x, 1L, "failing compareAndExchangeRelease long value"); |
497 |
} |
|
498 |
||
499 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
500 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
504 |
assertEquals(success, true, "weakCompareAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
505 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 506 |
assertEquals(x, 2L, "weakCompareAndSet long value"); |
507 |
} |
|
508 |
||
509 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
510 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
514 |
assertEquals(success, true, "weakCompareAndSetAcquire long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
515 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 516 |
assertEquals(x, 1L, "weakCompareAndSetAcquire long"); |
517 |
} |
|
518 |
||
519 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
520 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
521 |
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
|
522 |
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
|
523 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
524 |
assertEquals(success, true, "weakCompareAndSetRelease long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
525 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 526 |
assertEquals(x, 2L, "weakCompareAndSetRelease long"); |
527 |
} |
|
528 |
||
529 |
// Compare set and get |
|
530 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
531 |
long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 1L); |
36934 | 532 |
assertEquals(o, 2L, "getAndSet long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
533 |
long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 534 |
assertEquals(x, 1L, "getAndSet long value"); |
535 |
} |
|
536 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
537 |
hs.get(TestAccessMode.SET).invokeExact(array, i, 1L); |
36934 | 538 |
|
539 |
// get and add, add and get |
|
540 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
541 |
long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 3L); |
36934 | 542 |
assertEquals(o, 1L, "getAndAdd long"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
543 |
long c = (long) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, 3L); |
36934 | 544 |
assertEquals(c, 1L + 3L + 3L, "getAndAdd long value"); |
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
550 |
long[] array = new long[10]; |
|
551 |
||
552 |
final int i = 0; |
|
553 |
||
554 |
} |
|
555 |
||
556 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
557 |
long[] array = new long[10]; |
|
558 |
||
559 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
560 |
final int ci = i; |
|
561 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
562 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 563 |
checkIOOBE(am, () -> { |
564 |
long x = (long) hs.get(am).invokeExact(array, ci); |
|
565 |
}); |
|
566 |
} |
|
567 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
568 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 569 |
checkIOOBE(am, () -> { |
570 |
hs.get(am).invokeExact(array, ci, 1L); |
|
571 |
}); |
|
572 |
} |
|
573 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
574 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
36934 | 575 |
checkIOOBE(am, () -> { |
576 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, 1L, 2L); |
|
577 |
}); |
|
578 |
} |
|
579 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
580 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 581 |
checkIOOBE(am, () -> { |
582 |
long r = (long) hs.get(am).invokeExact(array, ci, 2L, 1L); |
|
583 |
}); |
|
584 |
} |
|
585 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
586 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 587 |
checkIOOBE(am, () -> { |
588 |
long o = (long) hs.get(am).invokeExact(array, ci, 1L); |
|
589 |
}); |
|
590 |
} |
|
591 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
592 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 593 |
checkIOOBE(am, () -> { |
594 |
long o = (long) hs.get(am).invokeExact(array, ci, 3L); |
|
595 |
}); |
|
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |