8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8239014
27 * @summary -XX:-UseEmptySlotsInSupers sometime fails to reproduce the layout of the old code
28 * @library /test/lib
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @requires vm.bits == "64" & vm.opt.final.UseCompressedOops == true & vm.gc != "Z"
32 * @run main/othervm -XX:+UseCompressedClassPointers -XX:-UseEmptySlotsInSupers OldLayoutCheck
33 */
34
35 /*
36 * @test
37 * @requires vm.bits == "32"
38 * @library /test/lib
39 * @modules java.base/jdk.internal.misc
40 * java.management
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 }
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8239014
27 * @summary -XX:-UseEmptySlotsInSupers sometime fails to reproduce the layout of the old code
28 * @library /test/lib /
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @requires vm.bits == "64" & vm.opt.final.UseCompressedOops == true & vm.gc != "Z"
32 * @build jdk.test.whitebox.WhiteBox
33 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
34 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseCompressedClassPointers -XX:-UseEmptySlotsInSupers OldLayoutCheck
35 */
36
37 /*
38 * @test
39 * @requires vm.bits == "32"
40 * @library /test/lib /
41 * @modules java.base/jdk.internal.misc
42 * java.management
43 * @build jdk.test.whitebox.WhiteBox
44 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
45 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-UseEmptySlotsInSupers OldLayoutCheck
46 */
47
48 import java.lang.reflect.Field;
49 import java.util.Arrays;
50 import java.util.Comparator;
51 import jdk.internal.misc.Unsafe;
52
53 import jdk.test.lib.Asserts;
54 import jdk.test.lib.Platform;
55 import jdk.test.whitebox.WhiteBox;
56
57 public class OldLayoutCheck {
58
59 static class LIClass {
60 public long l;
61 public int i;
62 }
63
64 private static final long INT_OFFSET;
65 private static final long LONG_OFFSET;
66 static {
67 WhiteBox WB = WhiteBox.getWhiteBox();
68 if (!Platform.is64bit() || WB.getBooleanVMFlag("UseCompactObjectHeaders")) {
69 INT_OFFSET = 16L;
70 LONG_OFFSET = 8L;
71 } else {
72 INT_OFFSET = 12L;
73 LONG_OFFSET = 16L;
74 }
75 }
76 static public void main(String[] args) {
77 Unsafe unsafe = Unsafe.getUnsafe();
78 Class c = LIClass.class;
79 Field[] fields = c.getFields();
80 for (int i = 0; i < fields.length; i++) {
81 long offset = unsafe.objectFieldOffset(fields[i]);
82 if (fields[i].getType() == int.class) {
83 Asserts.assertEquals(offset, INT_OFFSET, "Misplaced int field");
84 } else if (fields[i].getType() == long.class) {
85 Asserts.assertEquals(offset, LONG_OFFSET, "Misplaced long field");
86 } else {
87 Asserts.fail("Unexpected field type");
88 }
89 }
90 }
91 }
|