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:TieredStopAtLevel=2
  45  *                   FieldOffsetOfDisabled
  46  *
  47  * @run main/othervm -Xmx128m
  48  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  49  *                   -XX:-RuntimeFieldOf
  50  *                   -XX:TieredStopAtLevel=3
  51  *                   FieldOffsetOfDisabled
  52  *
  53  * @run main/othervm -Xmx128m
  54  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  55  *                   -XX:-RuntimeFieldOf
  56  *                   -XX:TieredStopAtLevel=4
  57  *                   FieldOffsetOfDisabled
  58  *
  59  * @run main/othervm -Xmx128m
  60  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  61  *                   -XX:-RuntimeFieldOf
  62  *                   -XX:-TieredCompilation
  63  *                   FieldOffsetOfDisabled
  64  */
  65 
  66 /*
  67  * @test
  68  * @summary Test for disabled Runtime.fieldOffsetOf with zero-based compressed oops
  69  * @library /test/lib
  70  * @requires vm.bits == 64
  71  *
  72  * @run main/othervm -Xmx4g
  73  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  74  *                   -XX:-RuntimeFieldOf
  75  *                   -Xint
  76  *                   FieldOffsetOfDisabled
  77  *
  78  * @run main/othervm -Xmx4g
  79  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  80  *                   -XX:-RuntimeFieldOf
  81  *                   -XX:TieredStopAtLevel=1
  82  *                   FieldOffsetOfDisabled
  83  *
  84  * @run main/othervm -Xmx4g
  85  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  86  *                   -XX:-RuntimeFieldOf
  87  *                   -XX:TieredStopAtLevel=2
  88  *                   FieldOffsetOfDisabled
  89  *
  90  * @run main/othervm -Xmx4g
  91  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  92  *                   -XX:-RuntimeFieldOf
  93  *                   -XX:TieredStopAtLevel=3
  94  *                   FieldOffsetOfDisabled
  95  *
  96  * @run main/othervm -Xmx4g
  97  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  98  *                   -XX:-RuntimeFieldOf
  99  *                   -XX:TieredStopAtLevel=4
 100  *                   FieldOffsetOfDisabled
 101  *
 102  * @run main/othervm -Xmx4g
 103  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 104  *                   -XX:-RuntimeFieldOf
 105  *                   -XX:-TieredCompilation
 106  *                   FieldOffsetOfDisabled
 107  */
 108 
 109 /*
 110  * @test
 111  * @summary Test for disabled Runtime.fieldOffsetOf without compressed oops
 112  * @library /test/lib
 113  * @requires vm.bits == 64
 114  *
 115  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 116  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 117  *                   -XX:-RuntimeFieldOf
 118  *                   -Xint
 119  *                   FieldOffsetOfDisabled
 120  *
 121  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 122  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 123  *                   -XX:-RuntimeFieldOf
 124  *                   -XX:TieredStopAtLevel=1
 125  *                   FieldOffsetOfDisabled
 126  *
 127  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 128  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 129  *                   -XX:-RuntimeFieldOf
 130  *                   -XX:TieredStopAtLevel=2
 131  *                   FieldOffsetOfDisabled
 132  *
 133  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 134  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 135  *                   -XX:-RuntimeFieldOf
 136  *                   -XX:TieredStopAtLevel=3
 137  *                   FieldOffsetOfDisabled
 138  *
 139  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 140  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 141  *                   -XX:-RuntimeFieldOf
 142  *                   -XX:TieredStopAtLevel=4
 143  *                   FieldOffsetOfDisabled
 144  *
 145  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 146  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 147  *                   -XX:-RuntimeFieldOf
 148  *                   -XX:-TieredCompilation
 149  *                   FieldOffsetOfDisabled
 150  */
 151 
 152 import java.lang.reflect.Field;
 153 
 154 public class FieldOffsetOfDisabled {
 155 
 156     public static void main(String ... args) throws Exception {
 157         testInstanceOffset();
 158         testStaticOffset();
 159     }
 160 
 161     private static void testInstanceOffset() throws Exception {
 162         Field f = Holder.class.getDeclaredField("x");
 163         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 164             RuntimeOfUtil.assertEquals(-1, Runtime.fieldOffsetOf(f));
 165         }
 166     }
 167 
 168     private static void testStaticOffset() throws Exception {
 169         Field f = Holder.class.getDeclaredField("staticX");
 170         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 171             RuntimeOfUtil.assertEquals(-1, Runtime.fieldOffsetOf(f));
 172         }
 173     }
 174 
 175     static class Holder {
 176         static int staticX;
 177         int x;
 178     }
 179 
 180 }