public abstract class GraalCompilerTest extends GraalTest
White box tests for Graal compiler transformations use this pattern:
See InvokeHintsTest
as an example of a white box test.
Black box tests use the test(String, Object...)
or
testN(int, String, Object...)
to execute some method in the interpreter and compare its
result against that produced by a Graal compiled version of the method.
These tests will be run by the mx unittest
command.
Modifier and Type | Class and Description |
---|---|
static interface |
GraalCompilerTest.ArgSupplier
Type denoting a lambda that supplies a fresh value each time it is called.
|
protected static class |
GraalCompilerTest.Result |
GraalTest.MultiCauseAssertionError
Modifier and Type | Field and Description |
---|---|
private Backend |
backend |
private Map<ResolvedJavaMethod,InstalledCode> |
cache |
private static AtomicInteger |
compilationId |
private Debug.Scope |
debugScope |
protected StructuredGraph |
lastCompiledGraph |
private DerivedOptionValue<LIRSuites> |
lirSuites |
private Map<ResolvedJavaMethod,Method> |
methodMap |
private Providers |
providers |
private DerivedOptionValue<Suites> |
suites |
Constructor and Description |
---|
GraalCompilerTest() |
GraalCompilerTest(Class<? extends Architecture> arch)
Set up a test for a non-default backend.
|
Modifier and Type | Method and Description |
---|---|
protected InstalledCode |
addMethod(ResolvedJavaMethod method,
CompilationResult compResult) |
protected void |
after()
Called after a test is executed.
|
void |
afterTest() |
protected Object[] |
applyArgSuppliers(Object... args)
Process a given set of arguments, converting any
GraalCompilerTest.ArgSupplier argument to the argument
it supplies. |
protected Object[] |
argsWithReceiver(Object receiver,
Object... args)
Prepends a non-null receiver argument to a given list or args.
|
protected ResolvedJavaMethod |
asResolvedJavaMethod(Method method)
Converts a reflection
Method to a ResolvedJavaMethod . |
protected void |
assertConstantReturn(StructuredGraph graph,
int value) |
protected void |
assertEquals(GraalCompilerTest.Result expect,
GraalCompilerTest.Result actual) |
protected void |
assertEquals(StructuredGraph expected,
StructuredGraph graph) |
protected void |
assertEquals(StructuredGraph expected,
StructuredGraph graph,
boolean excludeVirtual,
boolean checkConstants) |
protected void |
before(ResolvedJavaMethod method)
Called before a test is executed.
|
void |
beforeTest() |
protected static boolean |
branchProbability(double p,
boolean cond)
Inject a probability for a branch condition into the profiling information of this test case.
|
protected static void |
breakpoint() |
protected static void |
breakpoint(int arg0) |
protected void |
checkArgs(ResolvedJavaMethod method,
Object[] args) |
protected boolean |
checkHighTierGraph(StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
protected boolean |
checkLowTierGraph(StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
protected boolean |
checkMidTierGraph(StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
private static String |
compareGraphStrings(StructuredGraph expectedGraph,
String expectedString,
StructuredGraph actualGraph,
String actualString) |
protected CompilationResult |
compile(ResolvedJavaMethod installedCodeOwner,
StructuredGraph graph)
Compiles a given method.
|
protected int |
countUnusedConstants(StructuredGraph graph) |
protected LIRSuites |
createLIRSuites() |
protected Suites |
createSuites() |
protected GraphBuilderConfiguration |
editGraphBuilderConfiguration(GraphBuilderConfiguration conf) |
protected GraalCompilerTest.Result |
executeActual(ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected GraalCompilerTest.Result |
executeActualCheckDeopt(ResolvedJavaMethod method,
Set<DeoptimizationReason> shouldNotDeopt,
Object receiver,
Object... args) |
protected GraalCompilerTest.Result |
executeExpected(ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected Backend |
getBackend() |
protected static String |
getCanonicalGraphString(StructuredGraph graph,
boolean excludeVirtual,
boolean checkConstants) |
protected InstalledCode |
getCode(ResolvedJavaMethod method)
Gets installed code for a given method, compiling it first if necessary.
|
protected InstalledCode |
getCode(ResolvedJavaMethod installedCodeOwner,
StructuredGraph graph)
Gets installed code for a given method, compiling it first if necessary.
|
protected InstalledCode |
getCode(ResolvedJavaMethod installedCodeOwner,
StructuredGraph graph,
boolean forceCompile)
Gets installed code for a given method and graph, compiling it first if necessary.
|
protected CodeCacheProvider |
getCodeCache() |
protected ConstantReflectionProvider |
getConstantReflection() |
protected PhaseSuite<HighTierContext> |
getCustomGraphBuilderSuite(GraphBuilderConfiguration gbConf) |
protected GraphBuilderConfiguration.Plugins |
getDefaultGraphBuilderPlugins() |
protected PhaseSuite<HighTierContext> |
getDefaultGraphBuilderSuite() |
protected HighTierContext |
getDefaultHighTierContext() |
protected LIRSuites |
getLIRSuites() |
protected LoweringProvider |
getLowerer() |
protected MetaAccessProvider |
getMetaAccess() |
protected int |
getNodeCountExcludingUnusedConstants(StructuredGraph graph) |
protected Providers |
getProviders() |
protected Replacements |
getReplacements() |
protected ResolvedJavaMethod |
getResolvedJavaMethod(Class<?> clazz,
String methodName) |
protected ResolvedJavaMethod |
getResolvedJavaMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes) |
protected ResolvedJavaMethod |
getResolvedJavaMethod(String methodName) |
protected SnippetReflectionProvider |
getSnippetReflection() |
protected SpeculationLog |
getSpeculationLog() |
protected Suites |
getSuites() |
protected TargetDescription |
getTarget() |
static void |
initializeDebugging() |
protected Object |
invoke(ResolvedJavaMethod javaMethod,
Object receiver,
Object... args) |
protected boolean |
isArchitecture(String name)
Test if the current test runs on the given platform.
|
protected static boolean |
iterationCount(double i,
boolean cond)
Inject an iteration count for a loop condition into the profiling information of this test
case.
|
protected Method |
lookupMethod(ResolvedJavaMethod javaMethod)
Gets the reflection
Method from which a given ResolvedJavaMethod was created
or null if javaMethod does not correspond to a reflection method. |
private StructuredGraph |
parse1(ResolvedJavaMethod javaMethod,
PhaseSuite<HighTierContext> graphBuilderSuite,
StructuredGraph.AllowAssumptions allowAssumptions) |
protected StructuredGraph |
parseDebug(ResolvedJavaMethod m,
StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in full debug
mode to produce a graph.
|
protected StructuredGraph |
parseEager(ResolvedJavaMethod m,
StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in eager mode to
produce a graph.
|
protected StructuredGraph |
parseEager(String methodName,
StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in eager mode to
produce a graph.
|
protected StructuredGraph |
parseForCompile(ResolvedJavaMethod method)
Used to produce a graph for a method about to be compiled by
compile(ResolvedJavaMethod, StructuredGraph) if the second parameter to that method
is null. |
protected StructuredGraph |
parseProfiled(ResolvedJavaMethod m,
StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in default mode to
produce a graph.
|
protected StructuredGraph |
parseProfiled(String methodName,
StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in default mode to
produce a graph.
|
protected Object |
referenceInvoke(ResolvedJavaMethod method,
Object receiver,
Object... args) |
static Object |
supply(GraalCompilerTest.ArgSupplier supplier)
Convenience method for using an
GraalCompilerTest.ArgSupplier lambda in a varargs list. |
protected void |
test(ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected void |
test(String name,
Object... args) |
protected void |
testAgainstExpected(ResolvedJavaMethod method,
GraalCompilerTest.Result expect,
Object receiver,
Object... args) |
protected void |
testAgainstExpected(ResolvedJavaMethod method,
GraalCompilerTest.Result expect,
Set<DeoptimizationReason> shouldNotDeopt,
Object receiver,
Object... args) |
protected void |
testN(int n,
String name,
Object... args) |
assertDeepEquals, assertDeepEquals, assertDeepEquals, assertDeepEquals, assertFalse, assertFalse, assertFalse, assertTrue, assertTrue, assertTrue, equalFloatsOrDoublesDelta, fail, getMethod, getMethod, getMethod, ulpsDelta
private final DerivedOptionValue<Suites> suites
private final DerivedOptionValue<LIRSuites> lirSuites
private Debug.Scope debugScope
private static AtomicInteger compilationId
private Map<ResolvedJavaMethod,InstalledCode> cache
protected StructuredGraph lastCompiledGraph
private final Map<ResolvedJavaMethod,Method> methodMap
public GraalCompilerTest()
public GraalCompilerTest(Class<? extends Architecture> arch)
getBackend()
)
whether the desired backend is available.arch
- the name of the desired backend architectureprotected boolean checkHighTierGraph(StructuredGraph graph)
graph
- the graph at the end of HighTierprotected boolean checkMidTierGraph(StructuredGraph graph)
graph
- the graph at the end of MidTierprotected boolean checkLowTierGraph(StructuredGraph graph)
graph
- the graph at the end of LowTierprotected static void breakpoint()
protected static void breakpoint(int arg0)
protected Suites createSuites()
protected LIRSuites createLIRSuites()
public static void initializeDebugging()
public void beforeTest()
public void afterTest()
protected void assertEquals(StructuredGraph expected, StructuredGraph graph)
protected int countUnusedConstants(StructuredGraph graph)
protected int getNodeCountExcludingUnusedConstants(StructuredGraph graph)
protected void assertEquals(StructuredGraph expected, StructuredGraph graph, boolean excludeVirtual, boolean checkConstants)
private static String compareGraphStrings(StructuredGraph expectedGraph, String expectedString, StructuredGraph actualGraph, String actualString)
protected void assertConstantReturn(StructuredGraph graph, int value)
protected static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants)
protected Backend getBackend()
protected LIRSuites getLIRSuites()
protected Providers getProviders()
protected HighTierContext getDefaultHighTierContext()
protected SnippetReflectionProvider getSnippetReflection()
protected TargetDescription getTarget()
protected CodeCacheProvider getCodeCache()
protected ConstantReflectionProvider getConstantReflection()
protected MetaAccessProvider getMetaAccess()
protected LoweringProvider getLowerer()
protected Object referenceInvoke(ResolvedJavaMethod method, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
protected void before(ResolvedJavaMethod method)
protected void after()
protected GraalCompilerTest.Result executeExpected(ResolvedJavaMethod method, Object receiver, Object... args)
protected GraalCompilerTest.Result executeActual(ResolvedJavaMethod method, Object receiver, Object... args)
protected void checkArgs(ResolvedJavaMethod method, Object[] args)
protected Object[] argsWithReceiver(Object receiver, Object... args)
receiver
- the receiver argument to prepend if it is non-nullpublic static Object supply(GraalCompilerTest.ArgSupplier supplier)
GraalCompilerTest.ArgSupplier
lambda in a varargs list.protected void test(ResolvedJavaMethod method, Object receiver, Object... args)
protected Object[] applyArgSuppliers(Object... args)
GraalCompilerTest.ArgSupplier
argument to the argument
it supplies.protected void testAgainstExpected(ResolvedJavaMethod method, GraalCompilerTest.Result expect, Object receiver, Object... args)
protected GraalCompilerTest.Result executeActualCheckDeopt(ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args)
protected void assertEquals(GraalCompilerTest.Result expect, GraalCompilerTest.Result actual)
protected void testAgainstExpected(ResolvedJavaMethod method, GraalCompilerTest.Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args)
protected InstalledCode getCode(ResolvedJavaMethod method)
eagerly
.protected InstalledCode getCode(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph)
installedCodeOwner
- the method the compiled code will be associated with when installedgraph
- the graph to be compiled. If null, a graph will be obtained from
installedCodeOwner
via parseForCompile(ResolvedJavaMethod)
.protected InstalledCode getCode(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile)
installedCodeOwner
- the method the compiled code will be associated with when installedgraph
- the graph to be compiled. If null, a graph will be obtained from
installedCodeOwner
via parseForCompile(ResolvedJavaMethod)
.forceCompile
- specifies whether to ignore any previous code cached for the (method,
key) pairprotected StructuredGraph parseForCompile(ResolvedJavaMethod method)
compile(ResolvedJavaMethod, StructuredGraph)
if the second parameter to that method
is null.
The default implementation in GraalCompilerTest
is to call
#parseEager(ResolvedJavaMethod, AllowAssumptions)
.protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph)
installedCodeOwner
- the method the compiled code will be associated with when installedgraph
- the graph to be compiled for installedCodeOwner
. If null, a graph will
be obtained from installedCodeOwner
via
parseForCompile(ResolvedJavaMethod)
.protected SpeculationLog getSpeculationLog()
protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult)
protected ResolvedJavaMethod asResolvedJavaMethod(Method method)
Method
to a ResolvedJavaMethod
.protected ResolvedJavaMethod getResolvedJavaMethod(String methodName)
protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String methodName)
protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
protected Method lookupMethod(ResolvedJavaMethod javaMethod)
Method
from which a given ResolvedJavaMethod
was created
or null if javaMethod
does not correspond to a reflection method.protected Object invoke(ResolvedJavaMethod javaMethod, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
protected StructuredGraph parseProfiled(String methodName, StructuredGraph.AllowAssumptions allowAssumptions)
methodName
- the name of the method in this.getClass()
to be parsedprotected StructuredGraph parseProfiled(ResolvedJavaMethod m, StructuredGraph.AllowAssumptions allowAssumptions)
protected StructuredGraph parseEager(String methodName, StructuredGraph.AllowAssumptions allowAssumptions)
methodName
- the name of the method in this.getClass()
to be parsedprotected StructuredGraph parseEager(ResolvedJavaMethod m, StructuredGraph.AllowAssumptions allowAssumptions)
protected StructuredGraph parseDebug(ResolvedJavaMethod m, StructuredGraph.AllowAssumptions allowAssumptions)
private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, StructuredGraph.AllowAssumptions allowAssumptions)
protected GraphBuilderConfiguration.Plugins getDefaultGraphBuilderPlugins()
protected PhaseSuite<HighTierContext> getDefaultGraphBuilderSuite()
protected PhaseSuite<HighTierContext> getCustomGraphBuilderSuite(GraphBuilderConfiguration gbConf)
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf)
protected Replacements getReplacements()
protected static boolean branchProbability(double p, boolean cond)
p
- the probability that cond is truecond
- the condition of the branchprotected static boolean iterationCount(double i, boolean cond)
i
- the iteration count of the loopcond
- the condition of the loopprotected boolean isArchitecture(String name)
Architecture.getName()
.name
- The name to test