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