23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for short
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestShort
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestShort
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestShort
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestShort
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 JdkInternalMiscUnsafeAccessTestShort {
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);
185 }
186
187 {
188 UNSAFE.putShortUnaligned(base, offset, (short)2, false);
189 short x = UNSAFE.getShortUnaligned(base, offset, false);
190 assertEquals(x, (short)2, "putUnaligned little endian short value");
191 }
192
193
194 }
195
196 static void testAccess(long address) {
197 // Plain
198 {
199 UNSAFE.putShort(address, (short)1);
200 short x = UNSAFE.getShort(address);
201 assertEquals(x, (short)1, "set short value");
202 }
203 }
204 }
205
206
|
23
24 /*
25 * @test
26 * @bug 8143628
27 * @summary Test unsafe access for short
28 * @modules java.base/jdk.internal.misc
29 * @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestShort
30 * @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestShort
31 * @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestShort
32 * @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestShort
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 JdkInternalMiscUnsafeAccessTestShort {
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);
186 }
187
188 {
189 UNSAFE.putShortUnaligned(base, offset, (short)2, false);
190 short x = UNSAFE.getShortUnaligned(base, offset, false);
191 assertEquals(x, (short)2, "putUnaligned little endian short value");
192 }
193
194
195 }
196
197 static void testAccess(long address) {
198 // Plain
199 {
200 UNSAFE.putShort(address, (short)1);
201 short x = UNSAFE.getShort(address);
202 assertEquals(x, (short)1, "set short value");
203 }
204 }
205 }
206
|