1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 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 }