author | shade |
Wed, 15 Jun 2016 11:20:15 +0300 | |
changeset 39470 | d6f8b4a85fb0 |
parent 38429 | 0fd11baf20c3 |
child 39472 | 6df82f4c63ac |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 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=10 -Xint VarHandleTestAccessByte |
|
27 |
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte |
|
28 |
* @run testng/othervm -Diters=20000 VarHandleTestAccessByte |
|
29 |
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestAccessByte |
|
30 |
*/ |
|
31 |
||
32 |
import org.testng.annotations.BeforeClass; |
|
33 |
import org.testng.annotations.DataProvider; |
|
34 |
import org.testng.annotations.Test; |
|
35 |
||
36 |
import java.lang.invoke.MethodHandles; |
|
37 |
import java.lang.invoke.VarHandle; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.Arrays; |
|
40 |
import java.util.List; |
|
41 |
||
42 |
import static org.testng.Assert.*; |
|
43 |
||
44 |
public class VarHandleTestAccessByte extends VarHandleBaseTest { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
45 |
static final byte static_final_v = (byte)0x01; |
36934 | 46 |
|
47 |
static byte static_v; |
|
48 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
49 |
final byte final_v = (byte)0x01; |
36934 | 50 |
|
51 |
byte v; |
|
52 |
||
53 |
VarHandle vhFinalField; |
|
54 |
||
55 |
VarHandle vhField; |
|
56 |
||
57 |
VarHandle vhStaticField; |
|
58 |
||
59 |
VarHandle vhStaticFinalField; |
|
60 |
||
61 |
VarHandle vhArray; |
|
62 |
||
63 |
@BeforeClass |
|
64 |
public void setup() throws Exception { |
|
65 |
vhFinalField = MethodHandles.lookup().findVarHandle( |
|
66 |
VarHandleTestAccessByte.class, "final_v", byte.class); |
|
67 |
||
68 |
vhField = MethodHandles.lookup().findVarHandle( |
|
69 |
VarHandleTestAccessByte.class, "v", byte.class); |
|
70 |
||
71 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
72 |
VarHandleTestAccessByte.class, "static_final_v", byte.class); |
|
73 |
||
74 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
75 |
VarHandleTestAccessByte.class, "static_v", byte.class); |
|
76 |
||
77 |
vhArray = MethodHandles.arrayElementVarHandle(byte[].class); |
|
78 |
} |
|
79 |
||
80 |
||
81 |
@DataProvider |
|
82 |
public Object[][] varHandlesProvider() throws Exception { |
|
83 |
List<VarHandle> vhs = new ArrayList<>(); |
|
84 |
vhs.add(vhField); |
|
85 |
vhs.add(vhStaticField); |
|
86 |
vhs.add(vhArray); |
|
87 |
||
88 |
return vhs.stream().map(tc -> new Object[]{tc}).toArray(Object[][]::new); |
|
89 |
} |
|
90 |
||
91 |
@Test(dataProvider = "varHandlesProvider") |
|
92 |
public void testIsAccessModeSupported(VarHandle vh) { |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
93 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
94 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
95 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
96 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
97 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
98 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
99 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
100 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); |
36934 | 101 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
102 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
103 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
104 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
105 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
106 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
107 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
108 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
109 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
110 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); |
36934 | 111 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
112 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
113 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); |
36934 | 114 |
} |
115 |
||
116 |
||
117 |
@DataProvider |
|
118 |
public Object[][] typesProvider() throws Exception { |
|
119 |
List<Object[]> types = new ArrayList<>(); |
|
120 |
types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessByte.class)}); |
|
121 |
types.add(new Object[] {vhStaticField, Arrays.asList()}); |
|
122 |
types.add(new Object[] {vhArray, Arrays.asList(byte[].class, int.class)}); |
|
123 |
||
124 |
return types.stream().toArray(Object[][]::new); |
|
125 |
} |
|
126 |
||
127 |
@Test(dataProvider = "typesProvider") |
|
128 |
public void testTypes(VarHandle vh, List<Class<?>> pts) { |
|
129 |
assertEquals(vh.varType(), byte.class); |
|
130 |
||
131 |
assertEquals(vh.coordinateTypes(), pts); |
|
132 |
||
133 |
testTypes(vh); |
|
134 |
} |
|
135 |
||
136 |
||
137 |
@Test |
|
138 |
public void testLookupInstanceToStatic() { |
|
139 |
checkIAE("Lookup of static final field to instance final field", () -> { |
|
140 |
MethodHandles.lookup().findStaticVarHandle( |
|
141 |
VarHandleTestAccessByte.class, "final_v", byte.class); |
|
142 |
}); |
|
143 |
||
144 |
checkIAE("Lookup of static field to instance field", () -> { |
|
145 |
MethodHandles.lookup().findStaticVarHandle( |
|
146 |
VarHandleTestAccessByte.class, "v", byte.class); |
|
147 |
}); |
|
148 |
} |
|
149 |
||
150 |
@Test |
|
151 |
public void testLookupStaticToInstance() { |
|
152 |
checkIAE("Lookup of instance final field to static final field", () -> { |
|
153 |
MethodHandles.lookup().findVarHandle( |
|
154 |
VarHandleTestAccessByte.class, "static_final_v", byte.class); |
|
155 |
}); |
|
156 |
||
157 |
checkIAE("Lookup of instance field to static field", () -> { |
|
158 |
vhStaticField = MethodHandles.lookup().findVarHandle( |
|
159 |
VarHandleTestAccessByte.class, "static_v", byte.class); |
|
160 |
}); |
|
161 |
} |
|
162 |
||
163 |
||
164 |
@DataProvider |
|
165 |
public Object[][] accessTestCaseProvider() throws Exception { |
|
166 |
List<AccessTestCase<?>> cases = new ArrayList<>(); |
|
167 |
||
168 |
cases.add(new VarHandleAccessTestCase("Instance final field", |
|
169 |
vhFinalField, vh -> testInstanceFinalField(this, vh))); |
|
170 |
cases.add(new VarHandleAccessTestCase("Instance final field unsupported", |
|
171 |
vhFinalField, vh -> testInstanceFinalFieldUnsupported(this, vh), |
|
172 |
false)); |
|
173 |
||
174 |
cases.add(new VarHandleAccessTestCase("Static final field", |
|
175 |
vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalField)); |
|
176 |
cases.add(new VarHandleAccessTestCase("Static final field unsupported", |
|
177 |
vhStaticFinalField, VarHandleTestAccessByte::testStaticFinalFieldUnsupported, |
|
178 |
false)); |
|
179 |
||
180 |
cases.add(new VarHandleAccessTestCase("Instance field", |
|
181 |
vhField, vh -> testInstanceField(this, vh))); |
|
182 |
cases.add(new VarHandleAccessTestCase("Instance field unsupported", |
|
183 |
vhField, vh -> testInstanceFieldUnsupported(this, vh), |
|
184 |
false)); |
|
185 |
||
186 |
cases.add(new VarHandleAccessTestCase("Static field", |
|
187 |
vhStaticField, VarHandleTestAccessByte::testStaticField)); |
|
188 |
cases.add(new VarHandleAccessTestCase("Static field unsupported", |
|
189 |
vhStaticField, VarHandleTestAccessByte::testStaticFieldUnsupported, |
|
190 |
false)); |
|
191 |
||
192 |
cases.add(new VarHandleAccessTestCase("Array", |
|
193 |
vhArray, VarHandleTestAccessByte::testArray)); |
|
194 |
cases.add(new VarHandleAccessTestCase("Array unsupported", |
|
195 |
vhArray, VarHandleTestAccessByte::testArrayUnsupported, |
|
196 |
false)); |
|
197 |
cases.add(new VarHandleAccessTestCase("Array index out of bounds", |
|
198 |
vhArray, VarHandleTestAccessByte::testArrayIndexOutOfBounds, |
|
199 |
false)); |
|
200 |
||
201 |
// Work around issue with jtreg summary reporting which truncates |
|
202 |
// the String result of Object.toString to 30 characters, hence |
|
203 |
// the first dummy argument |
|
204 |
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
|
205 |
} |
|
206 |
||
207 |
@Test(dataProvider = "accessTestCaseProvider") |
|
208 |
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { |
|
209 |
T t = atc.get(); |
|
210 |
int iters = atc.requiresLoop() ? ITERS : 1; |
|
211 |
for (int c = 0; c < iters; c++) { |
|
212 |
atc.testAccess(t); |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
||
217 |
||
218 |
||
219 |
static void testInstanceFinalField(VarHandleTestAccessByte recv, VarHandle vh) { |
|
220 |
// Plain |
|
221 |
{ |
|
222 |
byte x = (byte) vh.get(recv); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
223 |
assertEquals(x, (byte)0x01, "get byte value"); |
36934 | 224 |
} |
225 |
||
226 |
||
227 |
// Volatile |
|
228 |
{ |
|
229 |
byte x = (byte) vh.getVolatile(recv); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
230 |
assertEquals(x, (byte)0x01, "getVolatile byte value"); |
36934 | 231 |
} |
232 |
||
233 |
// Lazy |
|
234 |
{ |
|
235 |
byte x = (byte) vh.getAcquire(recv); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
236 |
assertEquals(x, (byte)0x01, "getRelease byte value"); |
36934 | 237 |
} |
238 |
||
239 |
// Opaque |
|
240 |
{ |
|
241 |
byte x = (byte) vh.getOpaque(recv); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
242 |
assertEquals(x, (byte)0x01, "getOpaque byte value"); |
36934 | 243 |
} |
244 |
} |
|
245 |
||
246 |
static void testInstanceFinalFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { |
|
247 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
248 |
vh.set(recv, (byte)0x23); |
36934 | 249 |
}); |
250 |
||
251 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
252 |
vh.setVolatile(recv, (byte)0x23); |
36934 | 253 |
}); |
254 |
||
255 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
256 |
vh.setRelease(recv, (byte)0x23); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
257 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
258 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
259 |
checkUOE(() -> { |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
260 |
vh.setOpaque(recv, (byte)0x23); |
36934 | 261 |
}); |
262 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
263 |
|
36934 | 264 |
} |
265 |
||
266 |
||
267 |
static void testStaticFinalField(VarHandle vh) { |
|
268 |
// Plain |
|
269 |
{ |
|
270 |
byte x = (byte) vh.get(); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
271 |
assertEquals(x, (byte)0x01, "get byte value"); |
36934 | 272 |
} |
273 |
||
274 |
||
275 |
// Volatile |
|
276 |
{ |
|
277 |
byte x = (byte) vh.getVolatile(); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
278 |
assertEquals(x, (byte)0x01, "getVolatile byte value"); |
36934 | 279 |
} |
280 |
||
281 |
// Lazy |
|
282 |
{ |
|
283 |
byte x = (byte) vh.getAcquire(); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
284 |
assertEquals(x, (byte)0x01, "getRelease byte value"); |
36934 | 285 |
} |
286 |
||
287 |
// Opaque |
|
288 |
{ |
|
289 |
byte x = (byte) vh.getOpaque(); |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
290 |
assertEquals(x, (byte)0x01, "getOpaque byte value"); |
36934 | 291 |
} |
292 |
} |
|
293 |
||
294 |
static void testStaticFinalFieldUnsupported(VarHandle vh) { |
|
295 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
296 |
vh.set((byte)0x23); |
36934 | 297 |
}); |
298 |
||
299 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
300 |
vh.setVolatile((byte)0x23); |
36934 | 301 |
}); |
302 |
||
303 |
checkUOE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
304 |
vh.setRelease((byte)0x23); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
305 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
306 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
307 |
checkUOE(() -> { |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
308 |
vh.setOpaque((byte)0x23); |
36934 | 309 |
}); |
310 |
||
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
311 |
|
36934 | 312 |
} |
313 |
||
314 |
||
315 |
static void testInstanceField(VarHandleTestAccessByte recv, VarHandle vh) { |
|
316 |
// Plain |
|
317 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
318 |
vh.set(recv, (byte)0x01); |
36934 | 319 |
byte x = (byte) vh.get(recv); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
320 |
assertEquals(x, (byte)0x01, "set byte value"); |
36934 | 321 |
} |
322 |
||
323 |
||
324 |
// Volatile |
|
325 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
326 |
vh.setVolatile(recv, (byte)0x23); |
36934 | 327 |
byte x = (byte) vh.getVolatile(recv); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
328 |
assertEquals(x, (byte)0x23, "setVolatile byte value"); |
36934 | 329 |
} |
330 |
||
331 |
// Lazy |
|
332 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
333 |
vh.setRelease(recv, (byte)0x01); |
36934 | 334 |
byte x = (byte) vh.getAcquire(recv); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
335 |
assertEquals(x, (byte)0x01, "setRelease byte value"); |
36934 | 336 |
} |
337 |
||
338 |
// Opaque |
|
339 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
340 |
vh.setOpaque(recv, (byte)0x23); |
36934 | 341 |
byte x = (byte) vh.getOpaque(recv); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
342 |
assertEquals(x, (byte)0x23, "setOpaque byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
343 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
344 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
345 |
vh.set(recv, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
346 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
347 |
// Compare |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
348 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
349 |
boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
350 |
assertEquals(r, true, "success compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
351 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
352 |
assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
353 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
354 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
355 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
356 |
boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
357 |
assertEquals(r, false, "failing compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
358 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
359 |
assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
360 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
361 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
362 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
363 |
byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
364 |
assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
365 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
366 |
assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
367 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
368 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
369 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
370 |
byte r = (byte) vh.compareAndExchangeVolatile(recv, (byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
371 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
372 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
373 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
374 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
375 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
376 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
377 |
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
378 |
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
379 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
380 |
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
381 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
382 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
383 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
384 |
byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
385 |
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
386 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
387 |
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
388 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
389 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
390 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
391 |
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
392 |
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
393 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
394 |
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
36934 | 395 |
} |
396 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
397 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
398 |
byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
399 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
400 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
401 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
402 |
} |
36934 | 403 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
404 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
405 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
406 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
407 |
success = vh.weakCompareAndSet(recv, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
408 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
409 |
assertEquals(success, true, "weakCompareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
410 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
411 |
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
412 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
413 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
414 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
415 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
416 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
417 |
success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
418 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
419 |
assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
420 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
421 |
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
422 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
423 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
424 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
425 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
426 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
427 |
success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
428 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
429 |
assertEquals(success, true, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
430 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
431 |
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
432 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
433 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
434 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
435 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
436 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
437 |
success = vh.weakCompareAndSetVolatile(recv, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
438 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
439 |
assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
440 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
441 |
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
442 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
443 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
444 |
// Compare set and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
445 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
446 |
byte o = (byte) vh.getAndSet(recv, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
447 |
assertEquals(o, (byte)0x01, "getAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
448 |
byte x = (byte) vh.get(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
449 |
assertEquals(x, (byte)0x23, "getAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
450 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
451 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
452 |
vh.set(recv, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
453 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
454 |
// get and add, add and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
455 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
456 |
byte o = (byte) vh.getAndAdd(recv, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
457 |
assertEquals(o, (byte)0x01, "getAndAdd byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
458 |
byte c = (byte) vh.addAndGet(recv, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
459 |
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
460 |
} |
36934 | 461 |
} |
462 |
||
463 |
static void testInstanceFieldUnsupported(VarHandleTestAccessByte recv, VarHandle vh) { |
|
464 |
||
465 |
} |
|
466 |
||
467 |
||
468 |
static void testStaticField(VarHandle vh) { |
|
469 |
// Plain |
|
470 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
471 |
vh.set((byte)0x01); |
36934 | 472 |
byte x = (byte) vh.get(); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
473 |
assertEquals(x, (byte)0x01, "set byte value"); |
36934 | 474 |
} |
475 |
||
476 |
||
477 |
// Volatile |
|
478 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
479 |
vh.setVolatile((byte)0x23); |
36934 | 480 |
byte x = (byte) vh.getVolatile(); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
481 |
assertEquals(x, (byte)0x23, "setVolatile byte value"); |
36934 | 482 |
} |
483 |
||
484 |
// Lazy |
|
485 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
486 |
vh.setRelease((byte)0x01); |
36934 | 487 |
byte x = (byte) vh.getAcquire(); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
488 |
assertEquals(x, (byte)0x01, "setRelease byte value"); |
36934 | 489 |
} |
490 |
||
491 |
// Opaque |
|
492 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
493 |
vh.setOpaque((byte)0x23); |
36934 | 494 |
byte x = (byte) vh.getOpaque(); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
495 |
assertEquals(x, (byte)0x23, "setOpaque byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
496 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
497 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
498 |
vh.set((byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
499 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
500 |
// Compare |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
501 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
502 |
boolean r = vh.compareAndSet((byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
503 |
assertEquals(r, true, "success compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
504 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
505 |
assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
506 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
507 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
508 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
509 |
boolean r = vh.compareAndSet((byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
510 |
assertEquals(r, false, "failing compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
511 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
512 |
assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
513 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
514 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
515 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
516 |
byte r = (byte) vh.compareAndExchangeVolatile((byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
517 |
assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
518 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
519 |
assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
520 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
521 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
522 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
523 |
byte r = (byte) vh.compareAndExchangeVolatile((byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
524 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
525 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
526 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
527 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
528 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
529 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
530 |
byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
531 |
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
532 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
533 |
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
534 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
535 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
536 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
537 |
byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
538 |
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
539 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
540 |
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
541 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
542 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
543 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
544 |
byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
545 |
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
546 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
547 |
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
36934 | 548 |
} |
549 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
550 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
551 |
byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
552 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
553 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
554 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
555 |
} |
36934 | 556 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
557 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
558 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
559 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
560 |
success = vh.weakCompareAndSet((byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
561 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
562 |
assertEquals(success, true, "weakCompareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
563 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
564 |
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
565 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
566 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
567 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
568 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
569 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
570 |
success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
571 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
572 |
assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
573 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
574 |
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
575 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
576 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
577 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
578 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
579 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
580 |
success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
581 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
582 |
assertEquals(success, true, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
583 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
584 |
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
585 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
586 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
587 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
588 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
589 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
590 |
success = vh.weakCompareAndSetRelease((byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
591 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
592 |
assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
593 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
594 |
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
595 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
596 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
597 |
// Compare set and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
598 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
599 |
byte o = (byte) vh.getAndSet((byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
600 |
assertEquals(o, (byte)0x01, "getAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
601 |
byte x = (byte) vh.get(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
602 |
assertEquals(x, (byte)0x23, "getAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
603 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
604 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
605 |
vh.set((byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
606 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
607 |
// get and add, add and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
608 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
609 |
byte o = (byte) vh.getAndAdd( (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
610 |
assertEquals(o, (byte)0x01, "getAndAdd byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
611 |
byte c = (byte) vh.addAndGet((byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
612 |
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
613 |
} |
36934 | 614 |
} |
615 |
||
616 |
static void testStaticFieldUnsupported(VarHandle vh) { |
|
617 |
||
618 |
} |
|
619 |
||
620 |
||
621 |
static void testArray(VarHandle vh) { |
|
622 |
byte[] array = new byte[10]; |
|
623 |
||
624 |
for (int i = 0; i < array.length; i++) { |
|
625 |
// Plain |
|
626 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
627 |
vh.set(array, i, (byte)0x01); |
36934 | 628 |
byte x = (byte) vh.get(array, i); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
629 |
assertEquals(x, (byte)0x01, "get byte value"); |
36934 | 630 |
} |
631 |
||
632 |
||
633 |
// Volatile |
|
634 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
635 |
vh.setVolatile(array, i, (byte)0x23); |
36934 | 636 |
byte x = (byte) vh.getVolatile(array, i); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
637 |
assertEquals(x, (byte)0x23, "setVolatile byte value"); |
36934 | 638 |
} |
639 |
||
640 |
// Lazy |
|
641 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
642 |
vh.setRelease(array, i, (byte)0x01); |
36934 | 643 |
byte x = (byte) vh.getAcquire(array, i); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
644 |
assertEquals(x, (byte)0x01, "setRelease byte value"); |
36934 | 645 |
} |
646 |
||
647 |
// Opaque |
|
648 |
{ |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
649 |
vh.setOpaque(array, i, (byte)0x23); |
36934 | 650 |
byte x = (byte) vh.getOpaque(array, i); |
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
651 |
assertEquals(x, (byte)0x23, "setOpaque byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
652 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
653 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
654 |
vh.set(array, i, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
655 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
656 |
// Compare |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
657 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
658 |
boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
659 |
assertEquals(r, true, "success compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
660 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
661 |
assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
662 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
663 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
664 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
665 |
boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
666 |
assertEquals(r, false, "failing compareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
667 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
668 |
assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
669 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
670 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
671 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
672 |
byte r = (byte) vh.compareAndExchangeVolatile(array, i, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
673 |
assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
674 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
675 |
assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
676 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
677 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
678 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
679 |
byte r = (byte) vh.compareAndExchangeVolatile(array, i, (byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
680 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
681 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
682 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
683 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
684 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
685 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
686 |
byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
687 |
assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
688 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
689 |
assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
690 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
691 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
692 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
693 |
byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
694 |
assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
695 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
696 |
assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
697 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
698 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
699 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
700 |
byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
701 |
assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
702 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
703 |
assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
36934 | 704 |
} |
705 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
706 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
707 |
byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
708 |
assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
709 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
710 |
assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
711 |
} |
36934 | 712 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
713 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
714 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
715 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
716 |
success = vh.weakCompareAndSet(array, i, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
717 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
718 |
assertEquals(success, true, "weakCompareAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
719 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
720 |
assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
721 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
722 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
723 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
724 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
725 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
726 |
success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
727 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
728 |
assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
729 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
730 |
assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
731 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
732 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
733 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
734 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
735 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
736 |
success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
737 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
738 |
assertEquals(success, true, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
739 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
740 |
assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
741 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
742 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
743 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
744 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
745 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
746 |
success = vh.weakCompareAndSetVolatile(array, i, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
747 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
748 |
assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
749 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
750 |
assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
751 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
752 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
753 |
// Compare set and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
754 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
755 |
byte o = (byte) vh.getAndSet(array, i, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
756 |
assertEquals(o, (byte)0x01, "getAndSet byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
757 |
byte x = (byte) vh.get(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
758 |
assertEquals(x, (byte)0x23, "getAndSet byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
759 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
760 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
761 |
vh.set(array, i, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
762 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
763 |
// get and add, add and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
764 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
765 |
byte o = (byte) vh.getAndAdd(array, i, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
766 |
assertEquals(o, (byte)0x01, "getAndAdd byte"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
767 |
byte c = (byte) vh.addAndGet(array, i, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
768 |
assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
769 |
} |
36934 | 770 |
} |
771 |
} |
|
772 |
||
773 |
static void testArrayUnsupported(VarHandle vh) { |
|
774 |
byte[] array = new byte[10]; |
|
775 |
||
776 |
int i = 0; |
|
777 |
||
778 |
} |
|
779 |
||
780 |
static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable { |
|
781 |
byte[] array = new byte[10]; |
|
782 |
||
783 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
784 |
final int ci = i; |
|
785 |
||
786 |
checkIOOBE(() -> { |
|
787 |
byte x = (byte) vh.get(array, ci); |
|
788 |
}); |
|
789 |
||
790 |
checkIOOBE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
791 |
vh.set(array, ci, (byte)0x01); |
36934 | 792 |
}); |
793 |
||
794 |
checkIOOBE(() -> { |
|
795 |
byte x = (byte) vh.getVolatile(array, ci); |
|
796 |
}); |
|
797 |
||
798 |
checkIOOBE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
799 |
vh.setVolatile(array, ci, (byte)0x01); |
36934 | 800 |
}); |
801 |
||
802 |
checkIOOBE(() -> { |
|
803 |
byte x = (byte) vh.getAcquire(array, ci); |
|
804 |
}); |
|
805 |
||
806 |
checkIOOBE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
807 |
vh.setRelease(array, ci, (byte)0x01); |
36934 | 808 |
}); |
809 |
||
810 |
checkIOOBE(() -> { |
|
811 |
byte x = (byte) vh.getOpaque(array, ci); |
|
812 |
}); |
|
813 |
||
814 |
checkIOOBE(() -> { |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
815 |
vh.setOpaque(array, ci, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
816 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
817 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
818 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
819 |
boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
820 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
821 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
822 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
823 |
byte r = (byte) vh.compareAndExchangeVolatile(array, ci, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
824 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
825 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
826 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
827 |
byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
828 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
829 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
830 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
831 |
byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
832 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
833 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
834 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
835 |
boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23); |
36934 | 836 |
}); |
837 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
838 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
839 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
840 |
}); |
36934 | 841 |
|
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
842 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
843 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
844 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
845 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
846 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
847 |
boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
848 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
849 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
850 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
851 |
byte o = (byte) vh.getAndSet(array, ci, (byte)0x01); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
852 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
853 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
854 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
855 |
byte o = (byte) vh.getAndAdd(array, ci, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
856 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
857 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
858 |
checkIOOBE(() -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
859 |
byte o = (byte) vh.addAndGet(array, ci, (byte)0x45); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
860 |
}); |
36934 | 861 |
} |
862 |
} |
|
863 |
} |
|
864 |