author | psandoz |
Thu, 23 Jun 2016 13:46:48 +0200 | |
changeset 39472 | 6df82f4c63ac |
parent 38429 | 0fd11baf20c3 |
child 40732 | 2fd9cf42bb3c |
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 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
169 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "foo"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
170 |
assertEquals(r, "bar", "success compareAndExchange 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); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
172 |
assertEquals(x, "foo", "success compareAndExchange String value"); |
36934 | 173 |
} |
174 |
||
175 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
176 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "baz"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
177 |
assertEquals(r, "foo", "failing compareAndExchange 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); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
179 |
assertEquals(x, "foo", "failing compareAndExchange String value"); |
36934 | 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 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
240 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
241 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
242 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
243 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, "bar", "foo"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
244 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
245 |
assertEquals(success, true, "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
246 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
247 |
assertEquals(x, "foo", "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
248 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
249 |
|
36934 | 250 |
// Compare set and get |
251 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
252 |
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "bar"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
253 |
assertEquals(o, "foo", "getAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
254 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
255 |
assertEquals(x, "bar", "getAndSet String value"); |
36934 | 256 |
} |
257 |
||
258 |
} |
|
259 |
||
260 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessString recv, Handles hs) throws Throwable { |
|
261 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
262 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 263 |
checkUOE(am, () -> { |
264 |
String r = (String) hs.get(am).invokeExact(recv, "foo"); |
|
265 |
}); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
||
270 |
static void testStaticField(Handles hs) throws Throwable { |
|
271 |
// Plain |
|
272 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
273 |
hs.get(TestAccessMode.SET).invokeExact("foo"); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
274 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 275 |
assertEquals(x, "foo", "set String value"); |
276 |
} |
|
277 |
||
278 |
||
279 |
// Volatile |
|
280 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
281 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact("bar"); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
282 |
String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 283 |
assertEquals(x, "bar", "setVolatile String value"); |
284 |
} |
|
285 |
||
286 |
// Lazy |
|
287 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
288 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact("foo"); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
289 |
String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 290 |
assertEquals(x, "foo", "setRelease String value"); |
291 |
} |
|
292 |
||
293 |
// Opaque |
|
294 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
295 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact("bar"); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
296 |
String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 297 |
assertEquals(x, "bar", "setOpaque String value"); |
298 |
} |
|
299 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
300 |
hs.get(TestAccessMode.SET).invokeExact("foo"); |
36934 | 301 |
|
302 |
// Compare |
|
303 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
304 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "bar"); |
36934 | 305 |
assertEquals(r, true, "success compareAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
306 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 307 |
assertEquals(x, "bar", "success compareAndSet String value"); |
308 |
} |
|
309 |
||
310 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
311 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "baz"); |
36934 | 312 |
assertEquals(r, false, "failing compareAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
313 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 314 |
assertEquals(x, "bar", "failing compareAndSet String value"); |
315 |
} |
|
316 |
||
317 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
318 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "foo"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
319 |
assertEquals(r, "bar", "success compareAndExchange String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
320 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
321 |
assertEquals(x, "foo", "success compareAndExchange String value"); |
36934 | 322 |
} |
323 |
||
324 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
325 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "baz"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
326 |
assertEquals(r, "foo", "failing compareAndExchange String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
327 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
328 |
assertEquals(x, "foo", "failing compareAndExchange String value"); |
36934 | 329 |
} |
330 |
||
331 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
332 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "bar"); |
36934 | 333 |
assertEquals(r, "foo", "success compareAndExchangeAcquire String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
334 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 335 |
assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); |
336 |
} |
|
337 |
||
338 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
339 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "baz"); |
36934 | 340 |
assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
341 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 342 |
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); |
343 |
} |
|
344 |
||
345 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
346 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "foo"); |
36934 | 347 |
assertEquals(r, "bar", "success compareAndExchangeRelease String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
348 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 349 |
assertEquals(x, "foo", "success compareAndExchangeRelease String value"); |
350 |
} |
|
351 |
||
352 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
353 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "baz"); |
36934 | 354 |
assertEquals(r, "foo", "failing compareAndExchangeRelease 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, "foo", "failing compareAndExchangeRelease 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).invokeExact("foo", "bar"); |
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, "weakCompareAndSet 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", "weakCompareAndSet String value"); |
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_ACQUIRE).invokeExact("bar", "foo"); |
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, "weakCompareAndSetAcquire 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, "foo", "weakCompareAndSetAcquire String"); |
377 |
} |
|
378 |
||
379 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
380 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
381 |
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
|
382 |
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
|
383 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
384 |
assertEquals(success, true, "weakCompareAndSetRelease String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
385 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 386 |
assertEquals(x, "bar", "weakCompareAndSetRelease String"); |
387 |
} |
|
388 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
389 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
390 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
391 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
392 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact("bar", "foo"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
393 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
394 |
assertEquals(success, true, "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
395 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
396 |
assertEquals(x, "foo", "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
397 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
398 |
|
36934 | 399 |
// Compare set and get |
400 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
401 |
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact( "bar"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
402 |
assertEquals(o, "foo", "getAndSet String"); |
37343
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(); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
404 |
assertEquals(x, "bar", "getAndSet String value"); |
36934 | 405 |
} |
406 |
||
407 |
} |
|
408 |
||
409 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
410 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
411 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 412 |
checkUOE(am, () -> { |
413 |
String r = (String) hs.get(am).invokeExact("foo"); |
|
414 |
}); |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
||
419 |
static void testArray(Handles hs) throws Throwable { |
|
420 |
String[] array = new String[10]; |
|
421 |
||
422 |
for (int i = 0; i < array.length; i++) { |
|
423 |
// Plain |
|
424 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
425 |
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
426 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 427 |
assertEquals(x, "foo", "get String value"); |
428 |
} |
|
429 |
||
430 |
||
431 |
// Volatile |
|
432 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
433 |
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
|
434 |
String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 435 |
assertEquals(x, "bar", "setVolatile String value"); |
436 |
} |
|
437 |
||
438 |
// Lazy |
|
439 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
440 |
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
|
441 |
String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 442 |
assertEquals(x, "foo", "setRelease String value"); |
443 |
} |
|
444 |
||
445 |
// Opaque |
|
446 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
447 |
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
|
448 |
String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 449 |
assertEquals(x, "bar", "setOpaque String value"); |
450 |
} |
|
451 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
452 |
hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); |
36934 | 453 |
|
454 |
// Compare |
|
455 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
456 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "bar"); |
36934 | 457 |
assertEquals(r, true, "success compareAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
458 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 459 |
assertEquals(x, "bar", "success compareAndSet String value"); |
460 |
} |
|
461 |
||
462 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
463 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "baz"); |
36934 | 464 |
assertEquals(r, false, "failing compareAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
465 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 466 |
assertEquals(x, "bar", "failing compareAndSet String value"); |
467 |
} |
|
468 |
||
469 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
470 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "foo"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
471 |
assertEquals(r, "bar", "success compareAndExchange String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
472 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
473 |
assertEquals(x, "foo", "success compareAndExchange String value"); |
36934 | 474 |
} |
475 |
||
476 |
{ |
|
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
477 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "baz"); |
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
478 |
assertEquals(r, "foo", "failing compareAndExchange String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
479 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
39472
6df82f4c63ac
8154737: Rename VarHandle.compareAndExchangeVolatile to VarHandle.compareAndExchange
psandoz
parents:
38429
diff
changeset
|
480 |
assertEquals(x, "foo", "failing compareAndExchange String value"); |
36934 | 481 |
} |
482 |
||
483 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
484 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "bar"); |
36934 | 485 |
assertEquals(r, "foo", "success compareAndExchangeAcquire String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
486 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 487 |
assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); |
488 |
} |
|
489 |
||
490 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
491 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "baz"); |
36934 | 492 |
assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
493 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 494 |
assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); |
495 |
} |
|
496 |
||
497 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
498 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "foo"); |
36934 | 499 |
assertEquals(r, "bar", "success compareAndExchangeRelease String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
500 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 501 |
assertEquals(x, "foo", "success compareAndExchangeRelease String value"); |
502 |
} |
|
503 |
||
504 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
505 |
String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "baz"); |
36934 | 506 |
assertEquals(r, "foo", "failing compareAndExchangeRelease 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", "failing compareAndExchangeRelease String value"); |
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).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, "weakCompareAndSet 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", "weakCompareAndSet String value"); |
519 |
} |
|
520 |
||
521 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
522 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
523 |
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
|
524 |
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
|
525 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
526 |
assertEquals(success, true, "weakCompareAndSetAcquire String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
527 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 528 |
assertEquals(x, "foo", "weakCompareAndSetAcquire String"); |
529 |
} |
|
530 |
||
531 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
532 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
533 |
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
|
534 |
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
|
535 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
536 |
assertEquals(success, true, "weakCompareAndSetRelease String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
537 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 538 |
assertEquals(x, "bar", "weakCompareAndSetRelease String"); |
539 |
} |
|
540 |
||
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
541 |
{ |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
542 |
boolean success = false; |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
543 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
544 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, "bar", "foo"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
545 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
546 |
assertEquals(success, true, "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
547 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
548 |
assertEquals(x, "foo", "weakCompareAndSetVolatile String"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
549 |
} |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
550 |
|
36934 | 551 |
// Compare set and get |
552 |
{ |
|
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
553 |
String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "bar"); |
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
554 |
assertEquals(o, "foo", "getAndSet String"); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
555 |
String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); |
38372
017d7578731c
8157171: Hook up Unsafe.weakCompareAndSetVolatile to VarHandles
shade
parents:
38368
diff
changeset
|
556 |
assertEquals(x, "bar", "getAndSet String value"); |
36934 | 557 |
} |
558 |
||
559 |
} |
|
560 |
} |
|
561 |
||
562 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
563 |
String[] array = new String[10]; |
|
564 |
||
565 |
final int i = 0; |
|
566 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
567 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 568 |
checkUOE(am, () -> { |
569 |
String o = (String) hs.get(am).invokeExact(array, i, "foo"); |
|
570 |
}); |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
575 |
String[] array = new String[10]; |
|
576 |
||
577 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
578 |
final int ci = i; |
|
579 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
580 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 581 |
checkIOOBE(am, () -> { |
582 |
String x = (String) hs.get(am).invokeExact(array, ci); |
|
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.SET)) { |
36934 | 587 |
checkIOOBE(am, () -> { |
588 |
hs.get(am).invokeExact(array, ci, "foo"); |
|
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.COMPARE_AND_SET)) { |
36934 | 593 |
checkIOOBE(am, () -> { |
594 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, "foo", "bar"); |
|
595 |
}); |
|
596 |
} |
|
597 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
598 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
36934 | 599 |
checkIOOBE(am, () -> { |
600 |
String r = (String) hs.get(am).invokeExact(array, ci, "bar", "foo"); |
|
601 |
}); |
|
602 |
} |
|
603 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
604 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
36934 | 605 |
checkIOOBE(am, () -> { |
606 |
String o = (String) hs.get(am).invokeExact(array, ci, "foo"); |
|
607 |
}); |
|
608 |
} |
|
609 |
||
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |