23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for byte
28 * @modules jdk.unsupported/sun.misc
29 * @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestByte
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestByte
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestByte
32 * @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestByte
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 SunMiscUnsafeAccessTestByte {
42 static final int ITERS = Integer.getInteger("iters", 1);
43
44 static final sun.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 = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
59 f.setAccessible(true);
60 UNSAFE = (sun.misc.Unsafe) f.get(null);
61 } catch (Exception e) {
62 throw new RuntimeException("Unable to get Unsafe instance.", e);
143
144 static void testAccess(Object base, long offset) {
145 // Plain
146 {
147 UNSAFE.putByte(base, offset, (byte)1);
148 byte x = UNSAFE.getByte(base, offset);
149 assertEquals(x, (byte)1, "set byte value");
150 }
151
152 // Volatile
153 {
154 UNSAFE.putByteVolatile(base, offset, (byte)2);
155 byte x = UNSAFE.getByteVolatile(base, offset);
156 assertEquals(x, (byte)2, "putVolatile byte value");
157 }
158
159
160
161
162
163
164 }
165
166 static void testAccess(long address) {
167 // Plain
168 {
169 UNSAFE.putByte(address, (byte)1);
170 byte x = UNSAFE.getByte(address);
171 assertEquals(x, (byte)1, "set byte value");
172 }
173 }
174 }
175
176
|
23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for byte
28 * @modules jdk.unsupported/sun.misc
29 * @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestByte
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestByte
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestByte
32 * @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestByte
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 SunMiscUnsafeAccessTestByte {
42 static final int ITERS = Integer.getInteger("iters", 1);
43 static final int WEAK_ATTEMPTS = Integer.getInteger("weakAttempts", 10);
44
45 static final sun.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 = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
60 f.setAccessible(true);
61 UNSAFE = (sun.misc.Unsafe) f.get(null);
62 } catch (Exception e) {
63 throw new RuntimeException("Unable to get Unsafe instance.", e);
144
145 static void testAccess(Object base, long offset) {
146 // Plain
147 {
148 UNSAFE.putByte(base, offset, (byte)1);
149 byte x = UNSAFE.getByte(base, offset);
150 assertEquals(x, (byte)1, "set byte value");
151 }
152
153 // Volatile
154 {
155 UNSAFE.putByteVolatile(base, offset, (byte)2);
156 byte x = UNSAFE.getByteVolatile(base, offset);
157 assertEquals(x, (byte)2, "putVolatile byte value");
158 }
159
160
161
162
163
164 }
165
166 static void testAccess(long address) {
167 // Plain
168 {
169 UNSAFE.putByte(address, (byte)1);
170 byte x = UNSAFE.getByte(address);
171 assertEquals(x, (byte)1, "set byte value");
172 }
173 }
174 }
175
|