1 /* 2 * Copyright (c) 2020, Red Hat, Inc. 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 * @summary Test for disabled Runtime.fieldOffsetOf with 32-bit compressed oops 27 * @library /test/lib 28 * 29 * @run main/othervm -Xmx128m 30 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 31 * -XX:-RuntimeFieldOf 32 * -Xint 33 * FieldOffsetOfDisabled 34 * 35 * @run main/othervm -Xmx128m 36 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 37 * -XX:-RuntimeFieldOf 38 * -XX:TieredStopAtLevel=1 39 * FieldOffsetOfDisabled 40 * 41 * @run main/othervm -Xmx128m 42 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 43 * -XX:-RuntimeFieldOf 44 * -XX:-TieredCompilation 45 * FieldOffsetOfDisabled 46 */ 47 48 /* 49 * @test 50 * @summary Test for disabled Runtime.fieldOffsetOf with zero-based compressed oops 51 * @library /test/lib 52 * @requires vm.bits == 64 53 * 54 * @run main/othervm -Xmx4g 55 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 56 * -XX:-RuntimeFieldOf 57 * -Xint 58 * FieldOffsetOfDisabled 59 * 60 * @run main/othervm -Xmx4g 61 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 62 * -XX:-RuntimeFieldOf 63 * -XX:TieredStopAtLevel=1 64 * FieldOffsetOfDisabled 65 * 66 * @run main/othervm -Xmx4g 67 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 68 * -XX:-RuntimeFieldOf 69 * -XX:-TieredCompilation 70 * FieldOffsetOfDisabled 71 */ 72 73 /* 74 * @test 75 * @summary Test for disabled Runtime.fieldOffsetOf without compressed oops 76 * @library /test/lib 77 * @requires vm.bits == 64 78 * 79 * @run main/othervm -Xmx128m -XX:-UseCompressedOops 80 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 81 * -XX:-RuntimeFieldOf 82 * -Xint 83 * FieldOffsetOfDisabled 84 * 85 * @run main/othervm -Xmx128m -XX:-UseCompressedOops 86 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 87 * -XX:-RuntimeFieldOf 88 * -XX:TieredStopAtLevel=1 89 * FieldOffsetOfDisabled 90 * 91 * @run main/othervm -Xmx128m -XX:-UseCompressedOops 92 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni 93 * -XX:-RuntimeFieldOf 94 * -XX:-TieredCompilation 95 * FieldOffsetOfDisabled 96 */ 97 98 import java.lang.reflect.Field; 99 100 public class FieldOffsetOfDisabled { 101 102 public static void main(String ... args) throws Exception { 103 testInstanceOffset(); 104 testStaticOffset(); 105 } 106 107 private static void testInstanceOffset() throws Exception { 108 Field f = Holder.class.getDeclaredField("x"); 109 for (int c = 0; c < RuntimeOfUtil.ITERS; c++) { 110 RuntimeOfUtil.assertEquals(-1, Runtime.fieldOffsetOf(f)); 111 } 112 } 113 114 private static void testStaticOffset() throws Exception { 115 Field f = Holder.class.getDeclaredField("staticX"); 116 for (int c = 0; c < RuntimeOfUtil.ITERS; c++) { 117 RuntimeOfUtil.assertEquals(-1, Runtime.fieldOffsetOf(f)); 118 } 119 } 120 121 static class Holder { 122 static int staticX; 123 int x; 124 } 125 126 }