< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.test/src/org/graalvm/compiler/test/GraalTest.java

Print this page
rev 51958 : 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
Reviewed-by: alanb, dfuchs, kvn


  51 import jdk.vm.ci.meta.ResolvedJavaMethod;
  52 import sun.misc.Unsafe;
  53 
  54 /**
  55  * Base class that contains common utility methods and classes useful in unit tests.
  56  */
  57 public class GraalTest {
  58 
  59     public static final Unsafe UNSAFE;
  60     static {
  61         try {
  62             Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
  63             theUnsafe.setAccessible(true);
  64             UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class);
  65         } catch (Exception e) {
  66             throw new RuntimeException("exception while trying to get Unsafe", e);
  67         }
  68     }
  69 
  70     public static final boolean Java8OrEarlier = GraalServices.Java8OrEarlier;

  71 
  72     protected Method getMethod(String methodName) {
  73         return getMethod(getClass(), methodName);
  74     }
  75 
  76     protected Method getMethod(Class<?> clazz, String methodName) {
  77         Method found = null;
  78         for (Method m : clazz.getMethods()) {
  79             if (m.getName().equals(methodName)) {
  80                 Assert.assertNull(found);
  81                 found = m;
  82             }
  83         }
  84         if (found == null) {
  85             /* Now look for non-public methods (but this does not look in superclasses). */
  86             for (Method m : clazz.getDeclaredMethods()) {
  87                 if (m.getName().equals(methodName)) {
  88                     Assert.assertNull(found);
  89                     found = m;
  90                 }




  51 import jdk.vm.ci.meta.ResolvedJavaMethod;
  52 import sun.misc.Unsafe;
  53 
  54 /**
  55  * Base class that contains common utility methods and classes useful in unit tests.
  56  */
  57 public class GraalTest {
  58 
  59     public static final Unsafe UNSAFE;
  60     static {
  61         try {
  62             Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
  63             theUnsafe.setAccessible(true);
  64             UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class);
  65         } catch (Exception e) {
  66             throw new RuntimeException("exception while trying to get Unsafe", e);
  67         }
  68     }
  69 
  70     public static final boolean Java8OrEarlier = GraalServices.Java8OrEarlier;
  71     public static final boolean Java11OrEarlier = GraalServices.Java11OrEarlier;
  72 
  73     protected Method getMethod(String methodName) {
  74         return getMethod(getClass(), methodName);
  75     }
  76 
  77     protected Method getMethod(Class<?> clazz, String methodName) {
  78         Method found = null;
  79         for (Method m : clazz.getMethods()) {
  80             if (m.getName().equals(methodName)) {
  81                 Assert.assertNull(found);
  82                 found = m;
  83             }
  84         }
  85         if (found == null) {
  86             /* Now look for non-public methods (but this does not look in superclasses). */
  87             for (Method m : clazz.getDeclaredMethods()) {
  88                 if (m.getName().equals(methodName)) {
  89                     Assert.assertNull(found);
  90                     found = m;
  91                 }


< prev index next >