1 /* 2 * Copyright Amazon.com Inc. 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 id=with-coops-no-ccp 26 * @library /test/lib 27 * @requires vm.bits == "64" 28 * @modules java.base/jdk.internal.misc 29 * @run main/othervm -XX:+UseCompressedOops -XX:-UseCompressedClassPointers ArrayBaseOffsets 30 */ 31 /* 32 * @test id=with-coops-with-ccp 33 * @library /test/lib 34 * @requires vm.bits == "64" 35 * @requires vm.opt.UseCompressedClassPointers != false 36 * @modules java.base/jdk.internal.misc 37 * @run main/othervm -XX:+UseCompressedOops -XX:+UseCompressedClassPointers ArrayBaseOffsets 38 */ 39 /* 40 * @test id=no-coops-no-ccp 41 * @library /test/lib 42 * @requires vm.bits == "64" 43 * @modules java.base/jdk.internal.misc 44 * @run main/othervm -XX:-UseCompressedOops -XX:-UseCompressedClassPointers ArrayBaseOffsets 45 */ 46 /* 47 * @test id=no-coops-with-ccp 48 * @library /test/lib 49 * @requires vm.bits == "64" 50 * @requires vm.opt.UseCompressedClassPointers != false 51 * @modules java.base/jdk.internal.misc 52 * @run main/othervm -XX:-UseCompressedOops -XX:+UseCompressedClassPointers ArrayBaseOffsets 53 */ 54 /* 55 * @test id=32bit 56 * @library /test/lib 57 * @requires vm.bits == "32" 58 * @modules java.base/jdk.internal.misc 59 * @run main/othervm ArrayBaseOffsets 60 */ 61 62 import jdk.internal.misc.Unsafe; 63 64 import java.lang.management.ManagementFactory; 65 import java.lang.management.RuntimeMXBean; 66 import java.util.List; 67 68 import jdk.test.lib.Asserts; 69 import jdk.test.lib.Platform; 70 71 public class ArrayBaseOffsets { 72 73 private static final boolean COOP; 74 private static final boolean CCP; 75 76 static { 77 if (Platform.is64bit()) { 78 RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); 79 List<String> vmargs = runtime.getInputArguments(); 80 CCP = !vmargs.contains("-XX:-UseCompressedClassPointers"); 81 COOP = System.getProperty("java.vm.compressedOopsMode") != null; 82 } else { 83 COOP = CCP = false; 84 } 85 } 86 87 static public void main(String[] args) { 88 Unsafe unsafe = Unsafe.getUnsafe(); 89 int intOffset, longOffset; 90 if (Platform.is64bit()) { 91 if (CCP) { 92 intOffset = 16; 93 longOffset = 16; 94 } else { 95 intOffset = 20; 96 longOffset = 24; 97 } 98 } else { 99 intOffset = 12; 100 longOffset = 16; 101 } 102 Asserts.assertEquals(unsafe.arrayBaseOffset(boolean[].class), intOffset, "Misplaced boolean array base"); 103 Asserts.assertEquals(unsafe.arrayBaseOffset(byte[].class), intOffset, "Misplaced byte array base"); 104 Asserts.assertEquals(unsafe.arrayBaseOffset(char[].class), intOffset, "Misplaced char array base"); 105 Asserts.assertEquals(unsafe.arrayBaseOffset(short[].class), intOffset, "Misplaced short array base"); 106 Asserts.assertEquals(unsafe.arrayBaseOffset(int[].class), intOffset, "Misplaced int array base"); 107 Asserts.assertEquals(unsafe.arrayBaseOffset(long[].class), longOffset, "Misplaced long array base"); 108 Asserts.assertEquals(unsafe.arrayBaseOffset(float[].class), intOffset, "Misplaced float array base"); 109 Asserts.assertEquals(unsafe.arrayBaseOffset(double[].class), longOffset, "Misplaced double array base"); 110 int expectedObjArrayOffset = (COOP || !Platform.is64bit()) ? intOffset : longOffset; 111 Asserts.assertEquals(unsafe.arrayBaseOffset(Object[].class), expectedObjArrayOffset, "Misplaced object array base"); 112 } 113 }