27 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM; 28 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION; 29 30 import java.io.PrintStream; 31 import java.io.PrintWriter; 32 import java.lang.reflect.Field; 33 import java.lang.reflect.Method; 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 import java.util.Collection; 37 import java.util.Collections; 38 import java.util.List; 39 import java.util.concurrent.TimeUnit; 40 41 import org.graalvm.compiler.debug.DebugContext; 42 import org.graalvm.compiler.debug.DebugDumpHandler; 43 import org.graalvm.compiler.debug.DebugHandlersFactory; 44 import org.graalvm.compiler.debug.GlobalMetrics; 45 import org.graalvm.compiler.options.OptionValues; 46 import org.graalvm.compiler.serviceprovider.GraalServices; 47 import org.junit.After; 48 import org.junit.Assert; 49 import org.junit.AssumptionViolatedException; 50 import org.junit.internal.ComparisonCriteria; 51 import org.junit.internal.ExactComparisonCriteria; 52 import org.junit.rules.DisableOnDebug; 53 import org.junit.rules.TestRule; 54 import org.junit.rules.Timeout; 55 56 import jdk.vm.ci.meta.ResolvedJavaMethod; 57 import sun.misc.Unsafe; 58 59 /** 60 * Base class that contains common utility methods and classes useful in unit tests. 61 */ 62 public class GraalTest { 63 64 public static final Unsafe UNSAFE; 65 static { 66 try { 67 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); 68 theUnsafe.setAccessible(true); 69 UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class); 70 } catch (Exception e) { 71 throw new RuntimeException("exception while trying to get Unsafe", e); 72 } 73 } 74 75 public static final boolean Java8OrEarlier = GraalServices.Java8OrEarlier; 76 public static final boolean Java11OrEarlier = GraalServices.Java11OrEarlier; 77 78 protected Method getMethod(String methodName) { 79 return getMethod(getClass(), methodName); 80 } 81 82 protected Method getMethod(Class<?> clazz, String methodName) { 83 Method found = null; 84 for (Method m : clazz.getMethods()) { 85 if (m.getName().equals(methodName)) { 86 Assert.assertNull(found); 87 found = m; 88 } 89 } 90 if (found == null) { 91 /* Now look for non-public methods (but this does not look in superclasses). */ 92 for (Method m : clazz.getDeclaredMethods()) { 93 if (m.getName().equals(methodName)) { 94 Assert.assertNull(found); 95 found = m; 96 } | 27 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM; 28 import static org.graalvm.compiler.debug.DebugContext.NO_DESCRIPTION; 29 30 import java.io.PrintStream; 31 import java.io.PrintWriter; 32 import java.lang.reflect.Field; 33 import java.lang.reflect.Method; 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 import java.util.Collection; 37 import java.util.Collections; 38 import java.util.List; 39 import java.util.concurrent.TimeUnit; 40 41 import org.graalvm.compiler.debug.DebugContext; 42 import org.graalvm.compiler.debug.DebugDumpHandler; 43 import org.graalvm.compiler.debug.DebugHandlersFactory; 44 import org.graalvm.compiler.debug.GlobalMetrics; 45 import org.graalvm.compiler.options.OptionValues; 46 import org.graalvm.compiler.serviceprovider.GraalServices; 47 import org.graalvm.compiler.serviceprovider.JavaVersionUtil; 48 import org.junit.After; 49 import org.junit.Assert; 50 import org.junit.AssumptionViolatedException; 51 import org.junit.internal.ComparisonCriteria; 52 import org.junit.internal.ExactComparisonCriteria; 53 import org.junit.rules.DisableOnDebug; 54 import org.junit.rules.TestRule; 55 import org.junit.rules.Timeout; 56 57 import jdk.vm.ci.meta.ResolvedJavaMethod; 58 import sun.misc.Unsafe; 59 60 /** 61 * Base class that contains common utility methods and classes useful in unit tests. 62 */ 63 public class GraalTest { 64 65 public static final Unsafe UNSAFE; 66 static { 67 try { 68 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); 69 theUnsafe.setAccessible(true); 70 UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class); 71 } catch (Exception e) { 72 throw new RuntimeException("exception while trying to get Unsafe", e); 73 } 74 } 75 76 public static final boolean Java8OrEarlier = JavaVersionUtil.Java8OrEarlier; 77 public static final boolean Java11OrEarlier = JavaVersionUtil.Java11OrEarlier; 78 79 protected Method getMethod(String methodName) { 80 return getMethod(getClass(), methodName); 81 } 82 83 protected Method getMethod(Class<?> clazz, String methodName) { 84 Method found = null; 85 for (Method m : clazz.getMethods()) { 86 if (m.getName().equals(methodName)) { 87 Assert.assertNull(found); 88 found = m; 89 } 90 } 91 if (found == null) { 92 /* Now look for non-public methods (but this does not look in superclasses). */ 93 for (Method m : clazz.getDeclaredMethods()) { 94 if (m.getName().equals(methodName)) { 95 Assert.assertNull(found); 96 found = m; 97 } |