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