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