23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for byte
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestByte
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestByte
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestByte
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestByte
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 JdkInternalMiscUnsafeAccessTestByte {
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);
167 // Opaque
168 {
169 UNSAFE.putByteOpaque(base, offset, (byte)2);
170 byte x = UNSAFE.getByteOpaque(base, offset);
171 assertEquals(x, (byte)2, "putOpaque byte value");
172 }
173
174
175
176 }
177
178 static void testAccess(long address) {
179 // Plain
180 {
181 UNSAFE.putByte(address, (byte)1);
182 byte x = UNSAFE.getByte(address);
183 assertEquals(x, (byte)1, "set byte value");
184 }
185 }
186 }
187
188
|
23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for byte
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestByte
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestByte
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestByte
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestByte
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 JdkInternalMiscUnsafeAccessTestByte {
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);
168 // Opaque
169 {
170 UNSAFE.putByteOpaque(base, offset, (byte)2);
171 byte x = UNSAFE.getByteOpaque(base, offset);
172 assertEquals(x, (byte)2, "putOpaque byte value");
173 }
174
175
176
177 }
178
179 static void testAccess(long address) {
180 // Plain
181 {
182 UNSAFE.putByte(address, (byte)1);
183 byte x = UNSAFE.getByte(address);
184 assertEquals(x, (byte)1, "set byte value");
185 }
186 }
187 }
188
|