50330
|
1 |
/*
|
|
2 |
* Copyright (c) 2018, 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 |
package org.graalvm.compiler.replacements.jdk9;
|
|
24 |
|
|
25 |
import jdk.vm.ci.amd64.AMD64;
|
|
26 |
import jdk.vm.ci.code.TargetDescription;
|
|
27 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
|
28 |
import org.graalvm.compiler.api.test.Graal;
|
50431
|
29 |
import org.graalvm.compiler.core.phases.HighTier;
|
|
30 |
import org.graalvm.compiler.options.OptionValues;
|
50330
|
31 |
import org.graalvm.compiler.replacements.test.MethodSubstitutionTest;
|
|
32 |
import org.graalvm.compiler.runtime.RuntimeProvider;
|
|
33 |
import org.graalvm.compiler.test.AddExports;
|
|
34 |
import org.junit.Test;
|
|
35 |
|
50431
|
36 |
import java.lang.reflect.Field;
|
|
37 |
|
50330
|
38 |
@AddExports("java.base/jdk.internal.misc")
|
|
39 |
public class UnsafeReplacementsTest extends MethodSubstitutionTest {
|
|
40 |
|
|
41 |
// See GR-9819.
|
|
42 |
@SuppressWarnings("unused") ResolvedJavaMethod method = null;
|
|
43 |
|
|
44 |
static class Container {
|
|
45 |
public volatile boolean booleanField;
|
|
46 |
public volatile byte byteField = 17;
|
|
47 |
public volatile char charField = 1025;
|
|
48 |
public volatile short shortField = 2232;
|
|
49 |
public volatile int intField = 0xcafebabe;
|
|
50 |
public volatile long longField = 0xdedababafafaL;
|
|
51 |
public volatile float floatField = 0.125f;
|
|
52 |
public volatile double doubleField = 0.125;
|
|
53 |
public volatile Object objectField = dummyValue;
|
|
54 |
}
|
|
55 |
|
|
56 |
static jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
|
|
57 |
static Container dummyValue = new Container();
|
|
58 |
static Container newDummyValue = new Container();
|
|
59 |
static long booleanOffset;
|
|
60 |
static long byteOffset;
|
|
61 |
static long charOffset;
|
|
62 |
static long shortOffset;
|
|
63 |
static long intOffset;
|
|
64 |
static long longOffset;
|
|
65 |
static long floatOffset;
|
|
66 |
static long doubleOffset;
|
|
67 |
static long objectOffset;
|
|
68 |
|
|
69 |
static {
|
|
70 |
try {
|
|
71 |
booleanOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("booleanField"));
|
|
72 |
byteOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("byteField"));
|
|
73 |
charOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("charField"));
|
|
74 |
shortOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("shortField"));
|
|
75 |
intOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("intField"));
|
|
76 |
longOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("longField"));
|
|
77 |
floatOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("floatField"));
|
|
78 |
doubleOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("doubleField"));
|
|
79 |
objectOffset = unsafe.objectFieldOffset(Container.class.getDeclaredField("objectField"));
|
|
80 |
} catch (NoSuchFieldException e) {
|
|
81 |
throw new RuntimeException(e);
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
public static boolean unsafeCompareAndSetBoolean() {
|
|
86 |
Container container = new Container();
|
|
87 |
return unsafe.compareAndSetBoolean(container, booleanOffset, false, true);
|
|
88 |
}
|
|
89 |
|
|
90 |
public static boolean unsafeCompareAndSetByte() {
|
|
91 |
Container container = new Container();
|
|
92 |
return unsafe.compareAndSetByte(container, byteOffset, (byte) 17, (byte) 121);
|
|
93 |
}
|
|
94 |
|
|
95 |
public static boolean unsafeCompareAndSetChar() {
|
|
96 |
Container container = new Container();
|
|
97 |
return unsafe.compareAndSetChar(container, charOffset, (char) 1025, (char) 1777);
|
|
98 |
}
|
|
99 |
|
|
100 |
public static boolean unsafeCompareAndSetShort() {
|
|
101 |
Container container = new Container();
|
|
102 |
return unsafe.compareAndSetShort(container, shortOffset, (short) 2232, (short) 12111);
|
|
103 |
}
|
|
104 |
|
|
105 |
public static boolean unsafeCompareAndSetInt() {
|
|
106 |
Container container = new Container();
|
|
107 |
return unsafe.compareAndSetInt(container, intOffset, 0xcafebabe, 0xbabefafa);
|
|
108 |
}
|
|
109 |
|
|
110 |
public static boolean unsafeCompareAndSetLong() {
|
|
111 |
Container container = new Container();
|
|
112 |
return unsafe.compareAndSetLong(container, longOffset, 0xdedababafafaL, 0xfafacecafafadedaL);
|
|
113 |
}
|
|
114 |
|
|
115 |
public static boolean unsafeCompareAndSetFloat() {
|
|
116 |
Container container = new Container();
|
|
117 |
return unsafe.compareAndSetFloat(container, floatOffset, 0.125f, 0.25f);
|
|
118 |
}
|
|
119 |
|
|
120 |
public static boolean unsafeCompareAndSetDouble() {
|
|
121 |
Container container = new Container();
|
|
122 |
return unsafe.compareAndSetDouble(container, doubleOffset, 0.125, 0.25);
|
|
123 |
}
|
|
124 |
|
|
125 |
public static boolean unsafeCompareAndSetObject() {
|
|
126 |
Container container = new Container();
|
|
127 |
return unsafe.compareAndSetObject(container, objectOffset, dummyValue, newDummyValue);
|
|
128 |
}
|
|
129 |
|
|
130 |
public static boolean unsafeCompareAndExchangeBoolean() {
|
|
131 |
Container container = new Container();
|
|
132 |
return unsafe.compareAndExchangeBoolean(container, booleanOffset, false, true);
|
|
133 |
}
|
|
134 |
|
|
135 |
public static byte unsafeCompareAndExchangeByte() {
|
|
136 |
Container container = new Container();
|
|
137 |
return unsafe.compareAndExchangeByte(container, byteOffset, (byte) 17, (byte) 31);
|
|
138 |
}
|
|
139 |
|
|
140 |
public static char unsafeCompareAndExchangeChar() {
|
|
141 |
Container container = new Container();
|
|
142 |
return unsafe.compareAndExchangeChar(container, charOffset, (char) 1025, (char) 4502);
|
|
143 |
}
|
|
144 |
|
|
145 |
public static short unsafeCompareAndExchangeShort() {
|
|
146 |
Container container = new Container();
|
|
147 |
return unsafe.compareAndExchangeShort(container, shortOffset, (short) 2232, (short) 8121);
|
|
148 |
}
|
|
149 |
|
|
150 |
public static int unsafeCompareAndExchangeInt() {
|
|
151 |
Container container = new Container();
|
|
152 |
return unsafe.compareAndExchangeInt(container, intOffset, 0xcafebabe, 0xbabefafa);
|
|
153 |
}
|
|
154 |
|
|
155 |
public static long unsafeCompareAndExchangeLong() {
|
|
156 |
Container container = new Container();
|
|
157 |
return unsafe.compareAndExchangeLong(container, longOffset, 0xdedababafafaL, 0xfafacecafafadedaL);
|
|
158 |
}
|
|
159 |
|
|
160 |
public static float unsafeCompareAndExchangeFloat() {
|
|
161 |
Container container = new Container();
|
|
162 |
return unsafe.compareAndExchangeFloat(container, floatOffset, 0.125f, 0.25f);
|
|
163 |
}
|
|
164 |
|
|
165 |
public static double unsafeCompareAndExchangeDouble() {
|
|
166 |
Container container = new Container();
|
|
167 |
return unsafe.compareAndExchangeDouble(container, doubleOffset, 0.125, 0.25);
|
|
168 |
}
|
|
169 |
|
|
170 |
public static Object unsafeCompareAndExchangeObject() {
|
|
171 |
Container container = new Container();
|
|
172 |
return unsafe.compareAndExchangeObject(container, objectOffset, dummyValue, newDummyValue);
|
|
173 |
}
|
|
174 |
|
|
175 |
@Test
|
|
176 |
public void testCompareAndSet() {
|
|
177 |
TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
|
|
178 |
if (target.arch instanceof AMD64) {
|
|
179 |
testGraph("unsafeCompareAndSetBoolean");
|
|
180 |
testGraph("unsafeCompareAndSetByte");
|
|
181 |
testGraph("unsafeCompareAndSetChar");
|
|
182 |
testGraph("unsafeCompareAndSetShort");
|
|
183 |
testGraph("unsafeCompareAndSetInt");
|
|
184 |
testGraph("unsafeCompareAndSetLong");
|
|
185 |
testGraph("unsafeCompareAndSetFloat");
|
|
186 |
testGraph("unsafeCompareAndSetDouble");
|
|
187 |
testGraph("unsafeCompareAndSetObject");
|
|
188 |
testGraph("unsafeCompareAndExchangeBoolean");
|
|
189 |
testGraph("unsafeCompareAndExchangeByte");
|
|
190 |
testGraph("unsafeCompareAndExchangeChar");
|
|
191 |
testGraph("unsafeCompareAndExchangeShort");
|
|
192 |
testGraph("unsafeCompareAndExchangeInt");
|
|
193 |
testGraph("unsafeCompareAndExchangeLong");
|
|
194 |
testGraph("unsafeCompareAndExchangeFloat");
|
|
195 |
testGraph("unsafeCompareAndExchangeDouble");
|
|
196 |
testGraph("unsafeCompareAndExchangeObject");
|
|
197 |
}
|
|
198 |
test("unsafeCompareAndSetBoolean");
|
|
199 |
test("unsafeCompareAndSetByte");
|
|
200 |
test("unsafeCompareAndSetChar");
|
|
201 |
test("unsafeCompareAndSetShort");
|
|
202 |
test("unsafeCompareAndSetInt");
|
|
203 |
test("unsafeCompareAndSetLong");
|
|
204 |
test("unsafeCompareAndSetFloat");
|
|
205 |
test("unsafeCompareAndSetDouble");
|
|
206 |
test("unsafeCompareAndSetObject");
|
|
207 |
test("unsafeCompareAndExchangeBoolean");
|
|
208 |
test("unsafeCompareAndExchangeByte");
|
|
209 |
test("unsafeCompareAndExchangeChar");
|
|
210 |
test("unsafeCompareAndExchangeShort");
|
|
211 |
test("unsafeCompareAndExchangeInt");
|
|
212 |
test("unsafeCompareAndExchangeLong");
|
|
213 |
test("unsafeCompareAndExchangeFloat");
|
|
214 |
test("unsafeCompareAndExchangeDouble");
|
|
215 |
test("unsafeCompareAndExchangeObject");
|
|
216 |
}
|
|
217 |
|
|
218 |
public static int unsafeGetAndAddByte() {
|
|
219 |
Container container = new Container();
|
|
220 |
return unsafe.getAndAddByte(container, byteOffset, (byte) 2);
|
|
221 |
}
|
|
222 |
|
|
223 |
public static int unsafeGetAndAddChar() {
|
|
224 |
Container container = new Container();
|
|
225 |
return unsafe.getAndAddChar(container, charOffset, (char) 250);
|
|
226 |
}
|
|
227 |
|
|
228 |
public static int unsafeGetAndAddShort() {
|
|
229 |
Container container = new Container();
|
|
230 |
return unsafe.getAndAddShort(container, shortOffset, (short) 1250);
|
|
231 |
}
|
|
232 |
|
|
233 |
public static int unsafeGetAndAddInt() {
|
|
234 |
Container container = new Container();
|
|
235 |
return unsafe.getAndAddInt(container, intOffset, 104501);
|
|
236 |
}
|
|
237 |
|
|
238 |
public static long unsafeGetAndAddLong() {
|
|
239 |
Container container = new Container();
|
|
240 |
return unsafe.getAndAddLong(container, longOffset, 0x123456abcdL);
|
|
241 |
}
|
|
242 |
|
|
243 |
@Test
|
|
244 |
public void testGetAndAdd() {
|
|
245 |
TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
|
|
246 |
if (target.arch instanceof AMD64) {
|
|
247 |
testGraph("unsafeGetAndAddByte");
|
|
248 |
testGraph("unsafeGetAndAddChar");
|
|
249 |
testGraph("unsafeGetAndAddShort");
|
|
250 |
testGraph("unsafeGetAndAddInt");
|
|
251 |
testGraph("unsafeGetAndAddLong");
|
|
252 |
}
|
|
253 |
test("unsafeGetAndAddByte");
|
|
254 |
test("unsafeGetAndAddChar");
|
|
255 |
test("unsafeGetAndAddShort");
|
|
256 |
test("unsafeGetAndAddInt");
|
|
257 |
test("unsafeGetAndAddLong");
|
|
258 |
}
|
|
259 |
|
|
260 |
public static boolean unsafeGetAndSetBoolean() {
|
|
261 |
Container container = new Container();
|
|
262 |
return unsafe.getAndSetBoolean(container, booleanOffset, true);
|
|
263 |
}
|
|
264 |
|
|
265 |
public static byte unsafeGetAndSetByte() {
|
|
266 |
Container container = new Container();
|
|
267 |
return unsafe.getAndSetByte(container, byteOffset, (byte) 129);
|
|
268 |
}
|
|
269 |
|
|
270 |
public static char unsafeGetAndSetChar() {
|
|
271 |
Container container = new Container();
|
|
272 |
return unsafe.getAndSetChar(container, charOffset, (char) 21111);
|
|
273 |
}
|
|
274 |
|
|
275 |
public static short unsafeGetAndSetShort() {
|
|
276 |
Container container = new Container();
|
|
277 |
return unsafe.getAndSetShort(container, shortOffset, (short) 21111);
|
|
278 |
}
|
|
279 |
|
|
280 |
public static int unsafeGetAndSetInt() {
|
|
281 |
Container container = new Container();
|
|
282 |
return unsafe.getAndSetInt(container, intOffset, 0x1234af);
|
|
283 |
}
|
|
284 |
|
|
285 |
public static long unsafeGetAndSetLong() {
|
|
286 |
Container container = new Container();
|
|
287 |
return unsafe.getAndSetLong(container, longOffset, 0x12345678abL);
|
|
288 |
}
|
|
289 |
|
|
290 |
public static Object unsafeGetAndSetObject() {
|
|
291 |
Container container = new Container();
|
|
292 |
container.objectField = null;
|
|
293 |
Container other = new Container();
|
|
294 |
return unsafe.getAndSetObject(container, objectOffset, other);
|
|
295 |
}
|
|
296 |
|
|
297 |
@Test
|
|
298 |
public void testGetAndSet() {
|
|
299 |
TargetDescription target = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getTarget();
|
|
300 |
if (target.arch instanceof AMD64) {
|
|
301 |
testGraph("unsafeGetAndSetBoolean");
|
|
302 |
testGraph("unsafeGetAndSetByte");
|
|
303 |
testGraph("unsafeGetAndSetChar");
|
|
304 |
testGraph("unsafeGetAndSetShort");
|
|
305 |
testGraph("unsafeGetAndSetInt");
|
|
306 |
testGraph("unsafeGetAndSetLong");
|
|
307 |
testGraph("unsafeGetAndSetObject");
|
|
308 |
}
|
|
309 |
test("unsafeGetAndSetBoolean");
|
|
310 |
test("unsafeGetAndSetByte");
|
|
311 |
test("unsafeGetAndSetChar");
|
|
312 |
test("unsafeGetAndSetShort");
|
|
313 |
test("unsafeGetAndSetInt");
|
|
314 |
test("unsafeGetAndSetLong");
|
|
315 |
test("unsafeGetAndSetObject");
|
|
316 |
}
|
50431
|
317 |
|
|
318 |
public static void fieldInstance() {
|
|
319 |
JdkInternalMiscUnsafeAccessTestBoolean.testFieldInstance();
|
|
320 |
}
|
|
321 |
|
|
322 |
@Test
|
|
323 |
public void testFieldInstance() {
|
|
324 |
test(new OptionValues(getInitialOptions(), HighTier.Options.Inline, false), "fieldInstance");
|
|
325 |
}
|
|
326 |
|
|
327 |
public static void array() {
|
|
328 |
JdkInternalMiscUnsafeAccessTestBoolean.testArray();
|
|
329 |
}
|
|
330 |
|
|
331 |
@Test
|
|
332 |
public void testArray() {
|
|
333 |
test(new OptionValues(getInitialOptions(), HighTier.Options.Inline, false), "array");
|
|
334 |
}
|
|
335 |
|
|
336 |
public static void fieldStatic() {
|
|
337 |
JdkInternalMiscUnsafeAccessTestBoolean.testFieldStatic();
|
|
338 |
}
|
|
339 |
|
|
340 |
@Test
|
|
341 |
public void testFieldStatic() {
|
|
342 |
test(new OptionValues(getInitialOptions(), HighTier.Options.Inline, false), "fieldStatic");
|
|
343 |
}
|
|
344 |
|
|
345 |
public static class JdkInternalMiscUnsafeAccessTestBoolean {
|
|
346 |
static final int ITERATIONS = 100000;
|
|
347 |
|
|
348 |
static final int WEAK_ATTEMPTS = 10;
|
|
349 |
|
|
350 |
static final long V_OFFSET;
|
|
351 |
|
|
352 |
static final Object STATIC_V_BASE;
|
|
353 |
|
|
354 |
static final long STATIC_V_OFFSET;
|
|
355 |
|
|
356 |
static final int ARRAY_OFFSET;
|
|
357 |
|
|
358 |
static final int ARRAY_SHIFT;
|
|
359 |
|
|
360 |
static {
|
|
361 |
try {
|
|
362 |
Field staticVField = UnsafeReplacementsTest.JdkInternalMiscUnsafeAccessTestBoolean.class.getDeclaredField("staticV");
|
|
363 |
STATIC_V_BASE = unsafe.staticFieldBase(staticVField);
|
|
364 |
STATIC_V_OFFSET = unsafe.staticFieldOffset(staticVField);
|
|
365 |
} catch (Exception e) {
|
|
366 |
throw new RuntimeException(e);
|
|
367 |
}
|
|
368 |
|
|
369 |
try {
|
|
370 |
Field vField = UnsafeReplacementsTest.JdkInternalMiscUnsafeAccessTestBoolean.class.getDeclaredField("v");
|
|
371 |
V_OFFSET = unsafe.objectFieldOffset(vField);
|
|
372 |
} catch (Exception e) {
|
|
373 |
throw new RuntimeException(e);
|
|
374 |
}
|
|
375 |
|
|
376 |
ARRAY_OFFSET = unsafe.arrayBaseOffset(boolean[].class);
|
|
377 |
int ascale = unsafe.arrayIndexScale(boolean[].class);
|
|
378 |
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
|
379 |
}
|
|
380 |
|
|
381 |
static boolean staticV;
|
|
382 |
|
|
383 |
boolean v;
|
|
384 |
|
|
385 |
@BytecodeParserForceInline
|
|
386 |
public static void testFieldInstance() {
|
|
387 |
JdkInternalMiscUnsafeAccessTestBoolean t = new JdkInternalMiscUnsafeAccessTestBoolean();
|
|
388 |
for (int c = 0; c < ITERATIONS; c++) {
|
|
389 |
testAccess(t, V_OFFSET);
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
public static void testFieldStatic() {
|
|
394 |
for (int c = 0; c < ITERATIONS; c++) {
|
|
395 |
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
public static void testArray() {
|
|
400 |
boolean[] array = new boolean[10];
|
|
401 |
for (int c = 0; c < ITERATIONS; c++) {
|
|
402 |
for (int i = 0; i < array.length; i++) {
|
|
403 |
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
|
404 |
}
|
|
405 |
}
|
|
406 |
}
|
|
407 |
|
|
408 |
public static void assertEquals(Object seen, Object expected, String message) {
|
|
409 |
if (seen != expected) {
|
|
410 |
throw new AssertionError(message + " - seen: " + seen + ", expected: " + expected);
|
|
411 |
}
|
|
412 |
}
|
|
413 |
|
|
414 |
// Checkstyle: stop
|
|
415 |
@BytecodeParserForceInline
|
|
416 |
public static void testAccess(Object base, long offset) {
|
|
417 |
// Advanced compare
|
|
418 |
{
|
|
419 |
boolean r = unsafe.compareAndExchangeBoolean(base, offset, false, true);
|
|
420 |
assertEquals(r, false, "success compareAndExchange boolean");
|
|
421 |
boolean x = unsafe.getBoolean(base, offset);
|
|
422 |
assertEquals(x, true, "success compareAndExchange boolean value");
|
|
423 |
}
|
|
424 |
|
|
425 |
{
|
|
426 |
boolean r = unsafe.compareAndExchangeBoolean(base, offset, false, false);
|
|
427 |
assertEquals(r, true, "failing compareAndExchange boolean");
|
|
428 |
boolean x = unsafe.getBoolean(base, offset);
|
|
429 |
assertEquals(x, true, "failing compareAndExchange boolean value");
|
|
430 |
}
|
|
431 |
|
|
432 |
{
|
|
433 |
boolean r = unsafe.compareAndExchangeBooleanAcquire(base, offset, true, false);
|
|
434 |
assertEquals(r, true, "success compareAndExchangeAcquire boolean");
|
|
435 |
boolean x = unsafe.getBoolean(base, offset);
|
|
436 |
assertEquals(x, false, "success compareAndExchangeAcquire boolean value");
|
|
437 |
}
|
|
438 |
|
|
439 |
{
|
|
440 |
boolean r = unsafe.compareAndExchangeBooleanAcquire(base, offset, true, false);
|
|
441 |
assertEquals(r, false, "failing compareAndExchangeAcquire boolean");
|
|
442 |
boolean x = unsafe.getBoolean(base, offset);
|
|
443 |
assertEquals(x, false, "failing compareAndExchangeAcquire boolean value");
|
|
444 |
}
|
|
445 |
|
|
446 |
{
|
|
447 |
boolean r = unsafe.compareAndExchangeBooleanRelease(base, offset, false, true);
|
|
448 |
assertEquals(r, false, "success compareAndExchangeRelease boolean");
|
|
449 |
boolean x = unsafe.getBoolean(base, offset);
|
|
450 |
assertEquals(x, true, "success compareAndExchangeRelease boolean value");
|
|
451 |
}
|
|
452 |
|
|
453 |
{
|
|
454 |
boolean r = unsafe.compareAndExchangeBooleanRelease(base, offset, false, false);
|
|
455 |
assertEquals(r, true, "failing compareAndExchangeRelease boolean");
|
|
456 |
boolean x = unsafe.getBoolean(base, offset);
|
|
457 |
assertEquals(x, true, "failing compareAndExchangeRelease boolean value");
|
|
458 |
}
|
|
459 |
|
|
460 |
{
|
|
461 |
boolean success = false;
|
|
462 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
|
|
463 |
success = unsafe.weakCompareAndSetBooleanPlain(base, offset, true, false);
|
|
464 |
}
|
|
465 |
assertEquals(success, true, "weakCompareAndSetPlain boolean");
|
|
466 |
boolean x = unsafe.getBoolean(base, offset);
|
|
467 |
assertEquals(x, false, "weakCompareAndSetPlain boolean value");
|
|
468 |
}
|
|
469 |
|
|
470 |
{
|
|
471 |
boolean success = false;
|
|
472 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
|
|
473 |
success = unsafe.weakCompareAndSetBooleanAcquire(base, offset, false, true);
|
|
474 |
}
|
|
475 |
assertEquals(success, true, "weakCompareAndSetAcquire boolean");
|
|
476 |
boolean x = unsafe.getBoolean(base, offset);
|
|
477 |
assertEquals(x, true, "weakCompareAndSetAcquire boolean");
|
|
478 |
}
|
|
479 |
|
|
480 |
{
|
|
481 |
boolean success = false;
|
|
482 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
|
|
483 |
success = unsafe.weakCompareAndSetBooleanRelease(base, offset, true, false);
|
|
484 |
}
|
|
485 |
assertEquals(success, true, "weakCompareAndSetRelease boolean");
|
|
486 |
boolean x = unsafe.getBoolean(base, offset);
|
|
487 |
assertEquals(x, false, "weakCompareAndSetRelease boolean");
|
|
488 |
}
|
|
489 |
|
|
490 |
{
|
|
491 |
boolean success = false;
|
|
492 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) {
|
|
493 |
success = unsafe.weakCompareAndSetBoolean(base, offset, false, true);
|
|
494 |
}
|
|
495 |
assertEquals(success, true, "weakCompareAndSet boolean");
|
|
496 |
boolean x = unsafe.getBoolean(base, offset);
|
|
497 |
assertEquals(x, true, "weakCompareAndSet boolean");
|
|
498 |
}
|
|
499 |
|
|
500 |
unsafe.putBoolean(base, offset, false);
|
|
501 |
|
|
502 |
// Compare set and get
|
|
503 |
{
|
|
504 |
boolean o = unsafe.getAndSetBoolean(base, offset, true);
|
|
505 |
assertEquals(o, false, "getAndSet boolean");
|
|
506 |
boolean x = unsafe.getBoolean(base, offset);
|
|
507 |
assertEquals(x, true, "getAndSet boolean value");
|
|
508 |
}
|
|
509 |
|
|
510 |
}
|
|
511 |
// Checkstyle: resume
|
|
512 |
}
|
50330
|
513 |
}
|