47 * @modules java.base/jdk.internal.vm.annotation |
47 * @modules java.base/jdk.internal.vm.annotation |
48 * @run main/othervm -XX:-RestrictContended Inheritance1 |
48 * @run main/othervm -XX:-RestrictContended Inheritance1 |
49 */ |
49 */ |
50 public class Inheritance1 { |
50 public class Inheritance1 { |
51 |
51 |
52 private static final Unsafe U; |
52 private static final Unsafe U = Unsafe.getUnsafe(); |
53 private static int ADDRESS_SIZE; |
53 private static int ADDRESS_SIZE; |
54 private static int HEADER_SIZE; |
54 private static int HEADER_SIZE; |
55 |
55 |
56 static { |
56 static { |
57 // steal Unsafe |
|
58 try { |
|
59 Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); |
|
60 unsafe.setAccessible(true); |
|
61 U = (Unsafe) unsafe.get(null); |
|
62 } catch (NoSuchFieldException | IllegalAccessException e) { |
|
63 throw new IllegalStateException(e); |
|
64 } |
|
65 |
|
66 // When running with CompressedOops on 64-bit platform, the address size |
57 // When running with CompressedOops on 64-bit platform, the address size |
67 // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. |
58 // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. |
68 // Try to guess the reference field size with this naive trick. |
59 // Try to guess the reference field size with this naive trick. |
69 try { |
60 try { |
70 long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); |
61 long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); |