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