public abstract class GraalCompilerTest extends com.oracle.graal.test.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 |
Modifier and Type | Field and Description |
---|---|
private Backend |
backend |
private Map<jdk.internal.jvmci.meta.ResolvedJavaMethod,jdk.internal.jvmci.code.InstalledCode> |
cache |
private static AtomicInteger |
compilationId |
private com.oracle.graal.debug.Debug.Scope |
debugScope |
protected com.oracle.graal.nodes.StructuredGraph |
lastCompiledGraph |
private jdk.internal.jvmci.options.DerivedOptionValue<com.oracle.graal.lir.phases.LIRSuites> |
lirSuites |
private Map<jdk.internal.jvmci.meta.ResolvedJavaMethod,Method> |
methodMap |
private com.oracle.graal.phases.util.Providers |
providers |
private jdk.internal.jvmci.options.DerivedOptionValue<com.oracle.graal.phases.tiers.Suites> |
suites |
Constructor and Description |
---|
GraalCompilerTest() |
GraalCompilerTest(Class<? extends jdk.internal.jvmci.code.Architecture> arch)
Set up a test for a non-default backend.
|
Modifier and Type | Method and Description |
---|---|
protected jdk.internal.jvmci.code.InstalledCode |
addMethod(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
jdk.internal.jvmci.code.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 jdk.internal.jvmci.meta.ResolvedJavaMethod |
asResolvedJavaMethod(Method method)
Converts a reflection
Method to a ResolvedJavaMethod . |
protected void |
assertConstantReturn(com.oracle.graal.nodes.StructuredGraph graph,
int value) |
protected void |
assertEquals(GraalCompilerTest.Result expect,
GraalCompilerTest.Result actual) |
protected void |
assertEquals(com.oracle.graal.nodes.StructuredGraph expected,
com.oracle.graal.nodes.StructuredGraph graph) |
protected void |
assertEquals(com.oracle.graal.nodes.StructuredGraph expected,
com.oracle.graal.nodes.StructuredGraph graph,
boolean excludeVirtual,
boolean checkConstants) |
protected void |
before(jdk.internal.jvmci.meta.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(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
Object[] args) |
protected boolean |
checkHighTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
protected boolean |
checkLowTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
protected boolean |
checkMidTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
Can be overridden by unit tests to verify properties of the graph.
|
private static String |
compareGraphStrings(com.oracle.graal.nodes.StructuredGraph expectedGraph,
String expectedString,
com.oracle.graal.nodes.StructuredGraph actualGraph,
String actualString) |
protected jdk.internal.jvmci.code.CompilationResult |
compile(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner,
com.oracle.graal.nodes.StructuredGraph graph)
Compiles a given method.
|
protected int |
countUnusedConstants(com.oracle.graal.nodes.StructuredGraph graph) |
protected com.oracle.graal.lir.phases.LIRSuites |
createLIRSuites() |
protected com.oracle.graal.phases.tiers.Suites |
createSuites() |
protected com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration |
editGraphBuilderConfiguration(com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration conf) |
protected GraalCompilerTest.Result |
executeActual(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected GraalCompilerTest.Result |
executeActualCheckDeopt(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
Set<jdk.internal.jvmci.meta.DeoptimizationReason> shouldNotDeopt,
Object receiver,
Object... args) |
protected GraalCompilerTest.Result |
executeExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected Backend |
getBackend() |
protected static String |
getCanonicalGraphString(com.oracle.graal.nodes.StructuredGraph graph,
boolean excludeVirtual,
boolean checkConstants) |
protected jdk.internal.jvmci.code.InstalledCode |
getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod method)
Gets installed code for a given method, compiling it first if necessary.
|
protected jdk.internal.jvmci.code.InstalledCode |
getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner,
com.oracle.graal.nodes.StructuredGraph graph)
Gets installed code for a given method, compiling it first if necessary.
|
protected jdk.internal.jvmci.code.InstalledCode |
getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner,
com.oracle.graal.nodes.StructuredGraph graph,
boolean forceCompile)
Gets installed code for a given method and graph, compiling it first if necessary.
|
protected jdk.internal.jvmci.code.CodeCacheProvider |
getCodeCache() |
protected jdk.internal.jvmci.meta.ConstantReflectionProvider |
getConstantReflection() |
protected com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> |
getCustomGraphBuilderSuite(com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration gbConf) |
protected com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins |
getDefaultGraphBuilderPlugins() |
protected com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> |
getDefaultGraphBuilderSuite() |
protected com.oracle.graal.phases.tiers.HighTierContext |
getDefaultHighTierContext() |
protected com.oracle.graal.lir.phases.LIRSuites |
getLIRSuites() |
protected com.oracle.graal.nodes.spi.LoweringProvider |
getLowerer() |
protected jdk.internal.jvmci.meta.MetaAccessProvider |
getMetaAccess() |
protected int |
getNodeCountExcludingUnusedConstants(com.oracle.graal.nodes.StructuredGraph graph) |
protected com.oracle.graal.phases.util.Providers |
getProviders() |
protected com.oracle.graal.nodes.spi.Replacements |
getReplacements() |
protected jdk.internal.jvmci.meta.ResolvedJavaMethod |
getResolvedJavaMethod(Class<?> clazz,
String methodName) |
protected jdk.internal.jvmci.meta.ResolvedJavaMethod |
getResolvedJavaMethod(Class<?> clazz,
String methodName,
Class<?>... parameterTypes) |
protected jdk.internal.jvmci.meta.ResolvedJavaMethod |
getResolvedJavaMethod(String methodName) |
protected SnippetReflectionProvider |
getSnippetReflection() |
protected jdk.internal.jvmci.meta.SpeculationLog |
getSpeculationLog() |
protected com.oracle.graal.phases.tiers.Suites |
getSuites() |
protected jdk.internal.jvmci.code.TargetDescription |
getTarget() |
static void |
initializeDebugging() |
protected Object |
invoke(jdk.internal.jvmci.meta.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(jdk.internal.jvmci.meta.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 com.oracle.graal.nodes.StructuredGraph |
parse1(jdk.internal.jvmci.meta.ResolvedJavaMethod javaMethod,
com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> graphBuilderSuite,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions) |
protected com.oracle.graal.nodes.StructuredGraph |
parseDebug(jdk.internal.jvmci.meta.ResolvedJavaMethod m,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in full debug
mode to produce a graph.
|
protected com.oracle.graal.nodes.StructuredGraph |
parseEager(jdk.internal.jvmci.meta.ResolvedJavaMethod m,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in eager mode to
produce a graph.
|
protected com.oracle.graal.nodes.StructuredGraph |
parseEager(String methodName,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in eager mode to
produce a graph.
|
protected com.oracle.graal.nodes.StructuredGraph |
parseForCompile(jdk.internal.jvmci.meta.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 com.oracle.graal.nodes.StructuredGraph |
parseProfiled(jdk.internal.jvmci.meta.ResolvedJavaMethod m,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in default mode to
produce a graph.
|
protected com.oracle.graal.nodes.StructuredGraph |
parseProfiled(String methodName,
com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
Parses a Java method in default mode to
produce a graph.
|
protected Object |
referenceInvoke(jdk.internal.jvmci.meta.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(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
Object receiver,
Object... args) |
protected void |
test(String name,
Object... args) |
protected void |
testAgainstExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
GraalCompilerTest.Result expect,
Object receiver,
Object... args) |
protected void |
testAgainstExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method,
GraalCompilerTest.Result expect,
Set<jdk.internal.jvmci.meta.DeoptimizationReason> shouldNotDeopt,
Object receiver,
Object... args) |
protected void |
testN(int n,
String name,
Object... args) |
private final com.oracle.graal.phases.util.Providers providers
private final jdk.internal.jvmci.options.DerivedOptionValue<com.oracle.graal.phases.tiers.Suites> suites
private final jdk.internal.jvmci.options.DerivedOptionValue<com.oracle.graal.lir.phases.LIRSuites> lirSuites
private com.oracle.graal.debug.Debug.Scope debugScope
private static AtomicInteger compilationId
private Map<jdk.internal.jvmci.meta.ResolvedJavaMethod,jdk.internal.jvmci.code.InstalledCode> cache
protected com.oracle.graal.nodes.StructuredGraph lastCompiledGraph
public GraalCompilerTest()
public GraalCompilerTest(Class<? extends jdk.internal.jvmci.code.Architecture> arch)
getBackend()
)
whether the desired backend is available.arch
- the name of the desired backend architectureprotected boolean checkHighTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
graph
- the graph at the end of HighTierprotected boolean checkMidTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
graph
- the graph at the end of MidTierprotected boolean checkLowTierGraph(com.oracle.graal.nodes.StructuredGraph graph)
graph
- the graph at the end of LowTierprotected static void breakpoint()
protected static void breakpoint(int arg0)
protected com.oracle.graal.phases.tiers.Suites createSuites()
protected com.oracle.graal.lir.phases.LIRSuites createLIRSuites()
public static void initializeDebugging()
public void beforeTest()
public void afterTest()
protected void assertEquals(com.oracle.graal.nodes.StructuredGraph expected, com.oracle.graal.nodes.StructuredGraph graph)
protected int countUnusedConstants(com.oracle.graal.nodes.StructuredGraph graph)
protected int getNodeCountExcludingUnusedConstants(com.oracle.graal.nodes.StructuredGraph graph)
protected void assertEquals(com.oracle.graal.nodes.StructuredGraph expected, com.oracle.graal.nodes.StructuredGraph graph, boolean excludeVirtual, boolean checkConstants)
private static String compareGraphStrings(com.oracle.graal.nodes.StructuredGraph expectedGraph, String expectedString, com.oracle.graal.nodes.StructuredGraph actualGraph, String actualString)
protected void assertConstantReturn(com.oracle.graal.nodes.StructuredGraph graph, int value)
protected static String getCanonicalGraphString(com.oracle.graal.nodes.StructuredGraph graph, boolean excludeVirtual, boolean checkConstants)
protected Backend getBackend()
protected com.oracle.graal.phases.tiers.Suites getSuites()
protected com.oracle.graal.lir.phases.LIRSuites getLIRSuites()
protected com.oracle.graal.phases.util.Providers getProviders()
protected com.oracle.graal.phases.tiers.HighTierContext getDefaultHighTierContext()
protected SnippetReflectionProvider getSnippetReflection()
protected jdk.internal.jvmci.code.TargetDescription getTarget()
protected jdk.internal.jvmci.code.CodeCacheProvider getCodeCache()
protected jdk.internal.jvmci.meta.ConstantReflectionProvider getConstantReflection()
protected jdk.internal.jvmci.meta.MetaAccessProvider getMetaAccess()
protected com.oracle.graal.nodes.spi.LoweringProvider getLowerer()
protected Object referenceInvoke(jdk.internal.jvmci.meta.ResolvedJavaMethod method, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
protected void before(jdk.internal.jvmci.meta.ResolvedJavaMethod method)
protected void after()
protected GraalCompilerTest.Result executeExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method, Object receiver, Object... args)
protected GraalCompilerTest.Result executeActual(jdk.internal.jvmci.meta.ResolvedJavaMethod method, Object receiver, Object... args)
protected void checkArgs(jdk.internal.jvmci.meta.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(jdk.internal.jvmci.meta.ResolvedJavaMethod method, Object receiver, Object... args)
protected Object[] applyArgSuppliers(Object... args)
GraalCompilerTest.ArgSupplier
argument to the argument
it supplies.protected void testAgainstExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method, GraalCompilerTest.Result expect, Object receiver, Object... args)
protected GraalCompilerTest.Result executeActualCheckDeopt(jdk.internal.jvmci.meta.ResolvedJavaMethod method, Set<jdk.internal.jvmci.meta.DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args)
protected void assertEquals(GraalCompilerTest.Result expect, GraalCompilerTest.Result actual)
protected void testAgainstExpected(jdk.internal.jvmci.meta.ResolvedJavaMethod method, GraalCompilerTest.Result expect, Set<jdk.internal.jvmci.meta.DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args)
protected jdk.internal.jvmci.code.InstalledCode getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod method)
eagerly
.protected jdk.internal.jvmci.code.InstalledCode getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner, com.oracle.graal.nodes.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 jdk.internal.jvmci.code.InstalledCode getCode(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner, com.oracle.graal.nodes.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 com.oracle.graal.nodes.StructuredGraph parseForCompile(jdk.internal.jvmci.meta.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 jdk.internal.jvmci.code.CompilationResult compile(jdk.internal.jvmci.meta.ResolvedJavaMethod installedCodeOwner, com.oracle.graal.nodes.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 jdk.internal.jvmci.meta.SpeculationLog getSpeculationLog()
protected jdk.internal.jvmci.code.InstalledCode addMethod(jdk.internal.jvmci.meta.ResolvedJavaMethod method, jdk.internal.jvmci.code.CompilationResult compResult)
protected jdk.internal.jvmci.meta.ResolvedJavaMethod asResolvedJavaMethod(Method method)
Method
to a ResolvedJavaMethod
.protected jdk.internal.jvmci.meta.ResolvedJavaMethod getResolvedJavaMethod(String methodName)
protected jdk.internal.jvmci.meta.ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String methodName)
protected jdk.internal.jvmci.meta.ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes)
protected Method lookupMethod(jdk.internal.jvmci.meta.ResolvedJavaMethod javaMethod)
Method
from which a given ResolvedJavaMethod
was created
or null if javaMethod
does not correspond to a reflection method.protected Object invoke(jdk.internal.jvmci.meta.ResolvedJavaMethod javaMethod, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
protected com.oracle.graal.nodes.StructuredGraph parseProfiled(String methodName, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
methodName
- the name of the method in this.getClass()
to be parsedprotected com.oracle.graal.nodes.StructuredGraph parseProfiled(jdk.internal.jvmci.meta.ResolvedJavaMethod m, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
protected com.oracle.graal.nodes.StructuredGraph parseEager(String methodName, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
methodName
- the name of the method in this.getClass()
to be parsedprotected com.oracle.graal.nodes.StructuredGraph parseEager(jdk.internal.jvmci.meta.ResolvedJavaMethod m, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
protected com.oracle.graal.nodes.StructuredGraph parseDebug(jdk.internal.jvmci.meta.ResolvedJavaMethod m, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
private com.oracle.graal.nodes.StructuredGraph parse1(jdk.internal.jvmci.meta.ResolvedJavaMethod javaMethod, com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> graphBuilderSuite, com.oracle.graal.nodes.StructuredGraph.AllowAssumptions allowAssumptions)
protected com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins getDefaultGraphBuilderPlugins()
protected com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> getDefaultGraphBuilderSuite()
protected com.oracle.graal.phases.PhaseSuite<com.oracle.graal.phases.tiers.HighTierContext> getCustomGraphBuilderSuite(com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration gbConf)
protected com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration editGraphBuilderConfiguration(com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration conf)
protected com.oracle.graal.nodes.spi.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