23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for boolean
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestBoolean
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestBoolean
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestBoolean
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestBoolean
33 */
34
35 import org.testng.annotations.Test;
36
37 import java.lang.reflect.Field;
38
39 import static org.testng.Assert.*;
40
41 public class JdkInternalMiscUnsafeAccessTestBoolean {
42 static final int ITERS = Integer.getInteger("iters", 1);
43
44 static final jdk.internal.misc.Unsafe UNSAFE;
45
46 static final long V_OFFSET;
47
48 static final Object STATIC_V_BASE;
49
50 static final long STATIC_V_OFFSET;
51
52 static int ARRAY_OFFSET;
53
54 static int ARRAY_SHIFT;
55
56 static {
57 try {
58 Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
59 f.setAccessible(true);
60 UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
61 } catch (Exception e) {
62 throw new RuntimeException("Unable to get Unsafe instance.", e);
130
131 // Lazy
132 {
133 UNSAFE.putBooleanRelease(base, offset, true);
134 boolean x = UNSAFE.getBooleanAcquire(base, offset);
135 assertEquals(x, true, "putRelease boolean value");
136 }
137
138 // Opaque
139 {
140 UNSAFE.putBooleanOpaque(base, offset, false);
141 boolean x = UNSAFE.getBooleanOpaque(base, offset);
142 assertEquals(x, false, "putOpaque boolean value");
143 }
144
145
146
147 }
148
149 }
150
151
|
23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for boolean
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestBoolean
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestBoolean
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestBoolean
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestBoolean
33 */
34
35 import org.testng.annotations.Test;
36
37 import java.lang.reflect.Field;
38
39 import static org.testng.Assert.*;
40
41 public class JdkInternalMiscUnsafeAccessTestBoolean {
42 static final int ITERS = Integer.getInteger("iters", 1);
43 static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
44
45 static final jdk.internal.misc.Unsafe UNSAFE;
46
47 static final long V_OFFSET;
48
49 static final Object STATIC_V_BASE;
50
51 static final long STATIC_V_OFFSET;
52
53 static int ARRAY_OFFSET;
54
55 static int ARRAY_SHIFT;
56
57 static {
58 try {
59 Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
60 f.setAccessible(true);
61 UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
62 } catch (Exception e) {
63 throw new RuntimeException("Unable to get Unsafe instance.", e);
131
132 // Lazy
133 {
134 UNSAFE.putBooleanRelease(base, offset, true);
135 boolean x = UNSAFE.getBooleanAcquire(base, offset);
136 assertEquals(x, true, "putRelease boolean value");
137 }
138
139 // Opaque
140 {
141 UNSAFE.putBooleanOpaque(base, offset, false);
142 boolean x = UNSAFE.getBooleanOpaque(base, offset);
143 assertEquals(x, false, "putOpaque boolean value");
144 }
145
146
147
148 }
149
150 }
151
|