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 Runtime.addressOf with 32-bit compressed oops
  27  * @library /test/lib
  28  *
  29  * @run main/othervm -Xmx128m
  30  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  31  *                   -Xint
  32  *                   AddressOf
  33  *
  34  * @run main/othervm -Xmx128m
  35  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  36  *                   -XX:TieredStopAtLevel=1
  37  *                   AddressOf
  38  *
  39  * @run main/othervm -Xmx128m
  40  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  41  *                   -XX:TieredStopAtLevel=2
  42  *                   AddressOf
  43  *
  44  * @run main/othervm -Xmx128m
  45  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  46  *                   -XX:TieredStopAtLevel=3
  47  *                   AddressOf
  48  *
  49  * @run main/othervm -Xmx128m
  50  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  51  *                   -XX:TieredStopAtLevel=4
  52  *                   AddressOf
  53  *
  54  * @run main/othervm -Xmx128m
  55  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  56  *                   -XX:-TieredCompilation
  57  *                   AddressOf
  58  */
  59 
  60 /*
  61  * @test
  62  * @summary Test for Runtime.addressOf with zero-based compressed oops
  63  * @library /test/lib
  64  * @requires vm.bits == 64
  65  *
  66  * @run main/othervm -Xmx4g
  67  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  68  *                   -Xint
  69  *                   AddressOf
  70  *
  71  * @run main/othervm -Xmx4g
  72  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  73  *                   -XX:TieredStopAtLevel=1
  74  *                   AddressOf
  75  *
  76  * @run main/othervm -Xmx4g
  77  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  78  *                   -XX:TieredStopAtLevel=2
  79  *                   AddressOf
  80  *
  81  * @run main/othervm -Xmx4g
  82  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  83  *                   -XX:TieredStopAtLevel=3
  84  *                   AddressOf
  85  *
  86  * @run main/othervm -Xmx4g
  87  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  88  *                   -XX:TieredStopAtLevel=4
  89  *                   AddressOf
  90  *
  91  * @run main/othervm -Xmx4g
  92  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
  93  *                   -XX:-TieredCompilation
  94  *                   AddressOf
  95  */
  96 
  97 /*
  98  * @test
  99  * @summary Test for Runtime.addressOf without compressed oops
 100  * @library /test/lib
 101  * @requires vm.bits == 64
 102  *
 103  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 104  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 105  *                   -Xint
 106  *                   AddressOf
 107  *
 108  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 109  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 110  *                   -XX:TieredStopAtLevel=1
 111  *                   AddressOf
 112  *
 113  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 114  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 115  *                   -XX:TieredStopAtLevel=2
 116  *                   AddressOf
 117  *
 118  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 119  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 120  *                   -XX:TieredStopAtLevel=3
 121  *                   AddressOf
 122  *
 123  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 124  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 125  *                   -XX:TieredStopAtLevel=4
 126  *                   AddressOf
 127  *
 128  * @run main/othervm -Xmx128m -XX:-UseCompressedOops
 129  *                   -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
 130  *                   -XX:-TieredCompilation
 131  *                   AddressOf
 132  */
 133 
 134 import java.lang.reflect.Field;
 135 
 136 public class AddressOf {
 137 
 138     public static void main(String ... args) throws Exception {
 139         testAddress_newInteger();
 140         testAddress_IntegerValueOf();
 141         testAddress_newObject();
 142         testAddress_localObject();
 143         testAddress_fieldObject();
 144         testNulls();
 145     }
 146 
 147     private static void testAddress_newInteger() throws Exception {
 148         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 149             RuntimeOfUtil.assertNotEquals(0, Runtime.addressOf(new Integer(c)));
 150         }
 151     }
 152 
 153     private static void testAddress_IntegerValueOf() throws Exception {
 154         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 155             RuntimeOfUtil.assertNotEquals(0, Runtime.addressOf(Integer.valueOf(c)));
 156         }
 157     }
 158 
 159     private static void testAddress_newObject() throws Exception {
 160         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 161             RuntimeOfUtil.assertNotEquals(0, Runtime.addressOf(new Object()));
 162         }
 163     }
 164 
 165     private static void testAddress_localObject() throws Exception {
 166         Object o = new Object();
 167         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 168             RuntimeOfUtil.assertNotEquals(0, Runtime.addressOf(o));
 169         }
 170     }
 171 
 172     static Object staticO = new Object();
 173 
 174     private static void testAddress_fieldObject() throws Exception {
 175         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 176             RuntimeOfUtil.assertNotEquals(0, Runtime.addressOf(staticO));
 177         }
 178     }
 179 
 180     private static void testNulls() {
 181         for (int c = 0; c < RuntimeOfUtil.ITERS; c++) {
 182             RuntimeOfUtil.assertEquals(0, Runtime.addressOf(null));
 183         }
 184     }
 185 
 186 }