Path: blob/master/test/hotspot/jtreg/runtime/FieldLayout/OldLayoutCheck.java
40942 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 823901426* @summary -XX:-UseEmptySlotsInSupers sometime fails to reproduce the layout of the old code27* @library /test/lib28* @modules java.base/jdk.internal.misc29* java.management30* @requires vm.bits == "64" & vm.opt.final.UseCompressedOops == true & vm.gc != "Z"31* @run main/othervm -XX:+UseCompressedClassPointers -XX:-UseEmptySlotsInSupers OldLayoutCheck32*/3334/*35* @test36* @requires vm.bits == "32"37* @library /test/lib38* @modules java.base/jdk.internal.misc39* java.management40* @run main/othervm -XX:-UseEmptySlotsInSupers OldLayoutCheck41*/4243import java.lang.reflect.Field;44import java.util.Arrays;45import java.util.Comparator;46import jdk.internal.misc.Unsafe;4748import jdk.test.lib.Asserts;49import jdk.test.lib.Platform;5051public class OldLayoutCheck {5253static class LIClass {54public long l;55public int i;56}5758// 32-bit VMs: @0: 8 byte header, @8: long field, @16: int field59// 64-bit VMs: @0: 12 byte header, @12: int field, @16: long field60static final long INT_OFFSET = Platform.is64bit() ? 12L : 16L;61static final long LONG_OFFSET = Platform.is64bit() ? 16L : 8L;6263static public void main(String[] args) {64Unsafe unsafe = Unsafe.getUnsafe();65Class c = LIClass.class;66Field[] fields = c.getFields();67for (int i = 0; i < fields.length; i++) {68long offset = unsafe.objectFieldOffset(fields[i]);69if (fields[i].getType() == int.class) {70Asserts.assertEquals(offset, INT_OFFSET, "Misplaced int field");71} else if (fields[i].getType() == long.class) {72Asserts.assertEquals(offset, LONG_OFFSET, "Misplaced long field");73} else {74Asserts.fail("Unexpected field type");75}76}77}78}798081