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 VarHandleTestMethodHandleAccessBoolean |
|
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 VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { |
|
42 |
static final boolean static_final_v = true; |
|
43 |
||
44 |
static boolean static_v; |
|
45 |
||
46 |
final boolean final_v = true; |
|
47 |
||
48 |
boolean 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 |
VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class); |
|
64 |
||
65 |
vhField = MethodHandles.lookup().findVarHandle( |
|
66 |
VarHandleTestMethodHandleAccessBoolean.class, "v", boolean.class); |
|
67 |
||
68 |
vhStaticFinalField = MethodHandles.lookup().findStaticVarHandle( |
|
69 |
VarHandleTestMethodHandleAccessBoolean.class, "static_final_v", boolean.class); |
|
70 |
||
71 |
vhStaticField = MethodHandles.lookup().findStaticVarHandle( |
|
72 |
VarHandleTestMethodHandleAccessBoolean.class, "static_v", boolean.class); |
|
73 |
||
74 |
vhArray = MethodHandles.arrayElementVarHandle(boolean[].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, VarHandleTestMethodHandleAccessBoolean::testStaticField)); |
|
91 |
cases.add(new MethodHandleAccessTestCase("Static field unsupported", |
|
92 |
vhStaticField, f, VarHandleTestMethodHandleAccessBoolean::testStaticFieldUnsupported, |
|
93 |
false)); |
|
94 |
||
95 |
cases.add(new MethodHandleAccessTestCase("Array", |
|
96 |
vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArray)); |
|
97 |
cases.add(new MethodHandleAccessTestCase("Array unsupported", |
|
98 |
vhArray, f, VarHandleTestMethodHandleAccessBoolean::testArrayUnsupported, |
|
99 |
false)); |
|
100 |
cases.add(new MethodHandleAccessTestCase("Array index out of bounds", |
|
101 |
vhArray, f, VarHandleTestMethodHandleAccessBoolean::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(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable { |
|
122 |
// Plain |
|
123 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
124 |
hs.get(TestAccessMode.SET).invokeExact(recv, true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
125 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
36934 | 126 |
assertEquals(x, true, "set boolean value"); |
127 |
} |
|
128 |
||
129 |
||
130 |
// Volatile |
|
131 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
132 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
133 |
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
36934 | 134 |
assertEquals(x, false, "setVolatile boolean value"); |
135 |
} |
|
136 |
||
137 |
// Lazy |
|
138 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
139 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
140 |
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
36934 | 141 |
assertEquals(x, true, "setRelease boolean value"); |
142 |
} |
|
143 |
||
144 |
// Opaque |
|
145 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
146 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
147 |
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
36934 | 148 |
assertEquals(x, false, "setOpaque boolean value"); |
149 |
} |
|
150 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
151 |
hs.get(TestAccessMode.SET).invokeExact(recv, true); |
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, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
156 |
assertEquals(r, true, "success compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
157 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
158 |
assertEquals(x, false, "success compareAndSet boolean 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, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
163 |
assertEquals(r, false, "failing compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
164 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
165 |
assertEquals(x, false, "failing compareAndSet boolean 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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
170 |
assertEquals(r, false, "success compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
171 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
172 |
assertEquals(x, true, "success compareAndExchangeVolatile boolean 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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
177 |
assertEquals(r, true, "failing compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
178 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
179 |
assertEquals(x, true, "failing compareAndExchangeVolatile boolean 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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
184 |
assertEquals(r, true, "success compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
185 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
186 |
assertEquals(x, false, "success compareAndExchangeAcquire boolean 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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
191 |
assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
192 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
193 |
assertEquals(x, false, "failing compareAndExchangeAcquire boolean 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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
198 |
assertEquals(r, false, "success compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
199 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
200 |
assertEquals(x, true, "success compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
201 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
202 |
|
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
205 |
assertEquals(r, true, "failing compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
206 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
207 |
assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
208 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
209 |
|
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, true, false); |
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 boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
216 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
217 |
assertEquals(x, false, "weakCompareAndSet boolean 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, false, true); |
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 boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
226 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
227 |
assertEquals(x, true, "weakCompareAndSetAcquire boolean"); |
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, true, false); |
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 boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
236 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
237 |
assertEquals(x, false, "weakCompareAndSetRelease boolean"); |
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, false, true); |
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 boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
246 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
247 |
assertEquals(x, true, "weakCompareAndSetVolatile boolean"); |
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 |
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
253 |
assertEquals(o, true, "getAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
254 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
255 |
assertEquals(x, false, "getAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
256 |
} |
36934 | 257 |
|
258 |
} |
|
259 |
||
260 |
static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable { |
|
261 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
262 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 263 |
checkUOE(am, () -> { |
264 |
boolean r = (boolean) hs.get(am).invokeExact(recv, true); |
|
265 |
}); |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
||
270 |
static void testStaticField(Handles hs) throws Throwable { |
|
271 |
// Plain |
|
272 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
273 |
hs.get(TestAccessMode.SET).invokeExact(true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
274 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
36934 | 275 |
assertEquals(x, true, "set boolean value"); |
276 |
} |
|
277 |
||
278 |
||
279 |
// Volatile |
|
280 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
281 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
282 |
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
36934 | 283 |
assertEquals(x, false, "setVolatile boolean value"); |
284 |
} |
|
285 |
||
286 |
// Lazy |
|
287 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
288 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
289 |
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
36934 | 290 |
assertEquals(x, true, "setRelease boolean value"); |
291 |
} |
|
292 |
||
293 |
// Opaque |
|
294 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
295 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
296 |
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
36934 | 297 |
assertEquals(x, false, "setOpaque boolean value"); |
298 |
} |
|
299 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
300 |
hs.get(TestAccessMode.SET).invokeExact(true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
301 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
302 |
// Compare |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
305 |
assertEquals(r, true, "success compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
306 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
307 |
assertEquals(x, false, "success compareAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
308 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
309 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
310 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
311 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
312 |
assertEquals(r, false, "failing compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
313 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
314 |
assertEquals(x, false, "failing compareAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
315 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
316 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
317 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
318 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
319 |
assertEquals(r, false, "success compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
320 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
321 |
assertEquals(x, true, "success compareAndExchangeVolatile boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
322 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
323 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
324 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
325 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
326 |
assertEquals(r, true, "failing compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
327 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
328 |
assertEquals(x, true, "failing compareAndExchangeVolatile boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
329 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
330 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
331 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
332 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
333 |
assertEquals(r, true, "success compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
334 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
335 |
assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
336 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
337 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
338 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
339 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
340 |
assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
341 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
342 |
assertEquals(x, false, "failing compareAndExchangeAcquire boolean 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 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
346 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
347 |
assertEquals(r, false, "success compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
348 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
349 |
assertEquals(x, true, "success compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
350 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
351 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
352 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
353 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
354 |
assertEquals(r, true, "failing compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
355 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
356 |
assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
357 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
358 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
359 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
360 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
361 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
362 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(true, false); |
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 |
assertEquals(success, true, "weakCompareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
365 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
366 |
assertEquals(x, false, "weakCompareAndSet boolean 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 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
371 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
372 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(false, true); |
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 |
assertEquals(success, true, "weakCompareAndSetAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
375 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
376 |
assertEquals(x, true, "weakCompareAndSetAcquire boolean"); |
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 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
379 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
380 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
381 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
382 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false); |
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 |
assertEquals(success, true, "weakCompareAndSetRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
385 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
386 |
assertEquals(x, false, "weakCompareAndSetRelease boolean"); |
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 |
|
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 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
391 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
392 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(false, true); |
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 |
assertEquals(success, true, "weakCompareAndSetVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
395 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
396 |
assertEquals(x, true, "weakCompareAndSetVolatile boolean"); |
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 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
399 |
// Compare set and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
400 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
401 |
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact( false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
402 |
assertEquals(o, true, "getAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
403 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
404 |
assertEquals(x, false, "getAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
405 |
} |
36934 | 406 |
|
407 |
} |
|
408 |
||
409 |
static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
|
410 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
411 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 412 |
checkUOE(am, () -> { |
413 |
boolean r = (boolean) hs.get(am).invokeExact(true); |
|
414 |
}); |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
||
419 |
static void testArray(Handles hs) throws Throwable { |
|
420 |
boolean[] array = new boolean[10]; |
|
421 |
||
422 |
for (int i = 0; i < array.length; i++) { |
|
423 |
// Plain |
|
424 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
425 |
hs.get(TestAccessMode.SET).invokeExact(array, i, true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
426 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
36934 | 427 |
assertEquals(x, true, "get boolean value"); |
428 |
} |
|
429 |
||
430 |
||
431 |
// Volatile |
|
432 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
433 |
hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
434 |
boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
36934 | 435 |
assertEquals(x, false, "setVolatile boolean value"); |
436 |
} |
|
437 |
||
438 |
// Lazy |
|
439 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
440 |
hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, true); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
441 |
boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
36934 | 442 |
assertEquals(x, true, "setRelease boolean value"); |
443 |
} |
|
444 |
||
445 |
// Opaque |
|
446 |
{ |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
447 |
hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, false); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
448 |
boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
36934 | 449 |
assertEquals(x, false, "setOpaque boolean value"); |
450 |
} |
|
451 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
452 |
hs.get(TestAccessMode.SET).invokeExact(array, i, true); |
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 |
// Compare |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
457 |
assertEquals(r, true, "success compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
458 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
459 |
assertEquals(x, false, "success compareAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
460 |
} |
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 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
463 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
464 |
assertEquals(r, false, "failing compareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
465 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
466 |
assertEquals(x, false, "failing compareAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
467 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
471 |
assertEquals(r, false, "success compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
472 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
473 |
assertEquals(x, true, "success compareAndExchangeVolatile boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
474 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
478 |
assertEquals(r, true, "failing compareAndExchangeVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
479 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
480 |
assertEquals(x, true, "failing compareAndExchangeVolatile boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
481 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
485 |
assertEquals(r, true, "success compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
486 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
487 |
assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
488 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
492 |
assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
493 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
494 |
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
495 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
499 |
assertEquals(r, false, "success compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
500 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
501 |
assertEquals(x, true, "success compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
502 |
} |
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 |
boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
506 |
assertEquals(r, true, "failing compareAndExchangeRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
507 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
508 |
assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
509 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
510 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
511 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
512 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
513 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
514 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, true, false); |
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 |
assertEquals(success, true, "weakCompareAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
517 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
518 |
assertEquals(x, false, "weakCompareAndSet boolean value"); |
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 |
|
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 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
523 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
524 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
525 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
526 |
assertEquals(success, true, "weakCompareAndSetAcquire boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
527 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
528 |
assertEquals(x, true, "weakCompareAndSetAcquire boolean"); |
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 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
531 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
532 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
533 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
534 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, true, false); |
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 |
assertEquals(success, true, "weakCompareAndSetRelease boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
537 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
538 |
assertEquals(x, false, "weakCompareAndSetRelease boolean"); |
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 |
|
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 |
boolean success = false; |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
543 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
544 |
success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, false, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
545 |
} |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
546 |
assertEquals(success, true, "weakCompareAndSetVolatile boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
547 |
boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
548 |
assertEquals(x, true, "weakCompareAndSetVolatile boolean"); |
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 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
551 |
// Compare set and get |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
552 |
{ |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
553 |
boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, false); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
554 |
assertEquals(o, true, "getAndSet boolean"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
555 |
boolean x = (boolean) 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, false, "getAndSet boolean value"); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
557 |
} |
36934 | 558 |
|
559 |
} |
|
560 |
} |
|
561 |
||
562 |
static void testArrayUnsupported(Handles hs) throws Throwable { |
|
563 |
boolean[] array = new boolean[10]; |
|
564 |
||
565 |
final int i = 0; |
|
566 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
567 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
36934 | 568 |
checkUOE(am, () -> { |
569 |
boolean o = (boolean) hs.get(am).invokeExact(array, i, true); |
|
570 |
}); |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
|
575 |
boolean[] array = new boolean[10]; |
|
576 |
||
577 |
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) { |
|
578 |
final int ci = i; |
|
579 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
580 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET)) { |
36934 | 581 |
checkIOOBE(am, () -> { |
582 |
boolean x = (boolean) hs.get(am).invokeExact(array, ci); |
|
583 |
}); |
|
584 |
} |
|
585 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
586 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.SET)) { |
36934 | 587 |
checkIOOBE(am, () -> { |
588 |
hs.get(am).invokeExact(array, ci, true); |
|
589 |
}); |
|
590 |
} |
|
591 |
||
39470
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
592 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
593 |
checkIOOBE(am, () -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
594 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, true, false); |
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 |
|
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
598 |
for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
599 |
checkIOOBE(am, () -> { |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
600 |
boolean r = (boolean) hs.get(am).invokeExact(array, ci, false, true); |
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.GET_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 o = (boolean) hs.get(am).invokeExact(array, ci, true); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
607 |
}); |
d6f8b4a85fb0
8157726: VarHandles/Unsafe should support sub-word atomic ops
shade
parents:
38429
diff
changeset
|
608 |
} |
36934 | 609 |
|
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |