< prev index next >

test/hotspot/jtreg/runtime/FieldLayout/OldLayoutCheck.java

Print this page

41  * @run main/othervm -XX:-UseEmptySlotsInSupers OldLayoutCheck
42  */
43 
44 import java.lang.reflect.Field;
45 import java.util.Arrays;
46 import java.util.Comparator;
47 import jdk.internal.misc.Unsafe;
48 
49 import jdk.test.lib.Asserts;
50 import jdk.test.lib.Platform;
51 
52 public class OldLayoutCheck {
53 
54     static class LIClass {
55         public long l;
56         public int i;
57     }
58 
59     // 32-bit VMs: @0:  8 byte header,  @8: long field, @16:  int field
60     // 64-bit VMs: @0: 12 byte header, @12:  int field, @16: long field
61     static final long INT_OFFSET  = Platform.is64bit() ? 12L : 16L;
62     static final long LONG_OFFSET = Platform.is64bit() ? 16L :  8L;
63 
64     static public void main(String[] args) {
65         Unsafe unsafe = Unsafe.getUnsafe();
66         Class c = LIClass.class;
67         Field[] fields = c.getFields();
68         for (int i = 0; i < fields.length; i++) {
69             long offset = unsafe.objectFieldOffset(fields[i]);
70             if (fields[i].getType() == int.class) {
71                 Asserts.assertEquals(offset, INT_OFFSET, "Misplaced int field");
72             } else if (fields[i].getType() == long.class) {
73                 Asserts.assertEquals(offset, LONG_OFFSET, "Misplaced long field");
74             } else {
75                 Asserts.fail("Unexpected field type");
76             }
77         }
78     }
79 }

41  * @run main/othervm -XX:-UseEmptySlotsInSupers OldLayoutCheck
42  */
43 
44 import java.lang.reflect.Field;
45 import java.util.Arrays;
46 import java.util.Comparator;
47 import jdk.internal.misc.Unsafe;
48 
49 import jdk.test.lib.Asserts;
50 import jdk.test.lib.Platform;
51 
52 public class OldLayoutCheck {
53 
54     static class LIClass {
55         public long l;
56         public int i;
57     }
58 
59     // 32-bit VMs: @0:  8 byte header,  @8: long field, @16:  int field
60     // 64-bit VMs: @0: 12 byte header, @12:  int field, @16: long field
61     static final long INT_OFFSET  = 16L;
62     static final long LONG_OFFSET = 8L;
63 
64     static public void main(String[] args) {
65         Unsafe unsafe = Unsafe.getUnsafe();
66         Class c = LIClass.class;
67         Field[] fields = c.getFields();
68         for (int i = 0; i < fields.length; i++) {
69             long offset = unsafe.objectFieldOffset(fields[i]);
70             if (fields[i].getType() == int.class) {
71                 Asserts.assertEquals(offset, INT_OFFSET, "Misplaced int field");
72             } else if (fields[i].getType() == long.class) {
73                 Asserts.assertEquals(offset, LONG_OFFSET, "Misplaced long field");
74             } else {
75                 Asserts.fail("Unexpected field type");
76             }
77         }
78     }
79 }
< prev index next >