< prev index next >

test/compiler/jvmci/compilerToVM/GetResolvedJavaMethodTest.java

Print this page




  28  * @library / /test/lib
  29  * @library ../common/patches
  30  * @modules java.base/jdk.internal.misc
  31  * @modules jdk.vm.ci/jdk.vm.ci.hotspot
  32  *
  33  * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
  34  *        jdk.vm.ci/jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject
  35  *        sun.hotspot.WhiteBox
  36  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  37  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  38  * @run main/othervm -Xbootclasspath/a:.
  39  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  40  *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  41  *                   compiler.jvmci.compilerToVM.GetResolvedJavaMethodTest
  42  */
  43 
  44 package compiler.jvmci.compilerToVM;
  45 
  46 import jdk.internal.misc.Unsafe;
  47 import jdk.test.lib.Asserts;
  48 import jdk.test.lib.unsafe.UnsafeHelper;
  49 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  50 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  51 import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject;
  52 import sun.hotspot.WhiteBox;
  53 
  54 import java.lang.reflect.Field;
  55 
  56 public class GetResolvedJavaMethodTest {
  57     private static enum TestCase {
  58         NULL_BASE {
  59             @Override
  60             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
  61                 return CompilerToVMHelper.getResolvedJavaMethod(
  62                         null, getPtrToMethod());
  63             }
  64         },
  65         JAVA_METHOD_BASE {
  66             @Override
  67             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
  68                 HotSpotResolvedJavaMethod methodInstance


  97         JAVA_METHOD_BASE_ZERO {
  98             @Override
  99             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
 100                 long ptr = getPtrToMethod();
 101                 HotSpotResolvedJavaMethod methodInstance
 102                         = CompilerToVMHelper.getResolvedJavaMethodAtSlot(
 103                         TEST_CLASS, 0);
 104                 try {
 105                     METASPACE_METHOD_FIELD.set(methodInstance, 0L);
 106                 } catch (ReflectiveOperationException e) {
 107                     throw new Error("TESTBUG : " + e, e);
 108                 }
 109                 return CompilerToVMHelper.getResolvedJavaMethod(methodInstance,
 110                         ptr);
 111             }
 112         }
 113         ;
 114         abstract HotSpotResolvedJavaMethod getResolvedJavaMethod();
 115     }
 116 
 117     private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
 118     private static final WhiteBox WB = WhiteBox.getWhiteBox();
 119     private static final Field METASPACE_METHOD_FIELD;
 120     private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class;
 121     private static final long PTR;
 122     static  {
 123         HotSpotResolvedJavaMethod method
 124                 = CompilerToVMHelper.getResolvedJavaMethodAtSlot(TEST_CLASS, 0);
 125         try {
 126             // jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod
 127             METASPACE_METHOD_FIELD = method.getClass()
 128                     .getDeclaredField("metaspaceMethod");
 129             METASPACE_METHOD_FIELD.setAccessible(true);
 130             PTR = (long) METASPACE_METHOD_FIELD.get(method);
 131         } catch (ReflectiveOperationException e) {
 132             throw new Error("TESTBUG : " + e, e);
 133         }
 134 
 135     }
 136 
 137     private static long getPtrToMethod() {




  28  * @library / /test/lib
  29  * @library ../common/patches
  30  * @modules java.base/jdk.internal.misc
  31  * @modules jdk.vm.ci/jdk.vm.ci.hotspot
  32  *
  33  * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
  34  *        jdk.vm.ci/jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject
  35  *        sun.hotspot.WhiteBox
  36  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  37  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  38  * @run main/othervm -Xbootclasspath/a:.
  39  *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  40  *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  41  *                   compiler.jvmci.compilerToVM.GetResolvedJavaMethodTest
  42  */
  43 
  44 package compiler.jvmci.compilerToVM;
  45 
  46 import jdk.internal.misc.Unsafe;
  47 import jdk.test.lib.Asserts;

  48 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  49 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  50 import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject;
  51 import sun.hotspot.WhiteBox;
  52 
  53 import java.lang.reflect.Field;
  54 
  55 public class GetResolvedJavaMethodTest {
  56     private static enum TestCase {
  57         NULL_BASE {
  58             @Override
  59             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
  60                 return CompilerToVMHelper.getResolvedJavaMethod(
  61                         null, getPtrToMethod());
  62             }
  63         },
  64         JAVA_METHOD_BASE {
  65             @Override
  66             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
  67                 HotSpotResolvedJavaMethod methodInstance


  96         JAVA_METHOD_BASE_ZERO {
  97             @Override
  98             HotSpotResolvedJavaMethod getResolvedJavaMethod() {
  99                 long ptr = getPtrToMethod();
 100                 HotSpotResolvedJavaMethod methodInstance
 101                         = CompilerToVMHelper.getResolvedJavaMethodAtSlot(
 102                         TEST_CLASS, 0);
 103                 try {
 104                     METASPACE_METHOD_FIELD.set(methodInstance, 0L);
 105                 } catch (ReflectiveOperationException e) {
 106                     throw new Error("TESTBUG : " + e, e);
 107                 }
 108                 return CompilerToVMHelper.getResolvedJavaMethod(methodInstance,
 109                         ptr);
 110             }
 111         }
 112         ;
 113         abstract HotSpotResolvedJavaMethod getResolvedJavaMethod();
 114     }
 115 
 116     private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 117     private static final WhiteBox WB = WhiteBox.getWhiteBox();
 118     private static final Field METASPACE_METHOD_FIELD;
 119     private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class;
 120     private static final long PTR;
 121     static  {
 122         HotSpotResolvedJavaMethod method
 123                 = CompilerToVMHelper.getResolvedJavaMethodAtSlot(TEST_CLASS, 0);
 124         try {
 125             // jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod
 126             METASPACE_METHOD_FIELD = method.getClass()
 127                     .getDeclaredField("metaspaceMethod");
 128             METASPACE_METHOD_FIELD.setAccessible(true);
 129             PTR = (long) METASPACE_METHOD_FIELD.get(method);
 130         } catch (ReflectiveOperationException e) {
 131             throw new Error("TESTBUG : " + e, e);
 132         }
 133 
 134     }
 135 
 136     private static long getPtrToMethod() {


< prev index next >