src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java Fri Jul 7 09:29:31 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java Fri Jul 7 09:29:31 2017
*** 35,44 ****
--- 35,45 ----
import java.lang.reflect.Executable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+ import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
*** 53,66 ****
--- 54,67 ----
import org.graalvm.compiler.core.GraalCompiler;
import org.graalvm.compiler.core.GraalCompiler.Request;
import org.graalvm.compiler.core.common.CompilationIdentifier;
import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.core.target.Backend;
! import org.graalvm.compiler.debug.DebugHandlersFactory;
! import org.graalvm.compiler.debug.Debug.Scope;
! import org.graalvm.compiler.debug.DebugContext;
+ import org.graalvm.compiler.debug.DebugDumpHandler;
import org.graalvm.compiler.debug.DebugDumpScope;
import org.graalvm.compiler.debug.DebugEnvironment;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.NodeMap;
*** 83,92 ****
--- 84,94 ----
import org.graalvm.compiler.nodes.ParameterNode;
import org.graalvm.compiler.nodes.ProxyNode;
import org.graalvm.compiler.nodes.ReturnNode;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
+ import org.graalvm.compiler.nodes.StructuredGraph.Builder;
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.cfg.Block;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
*** 109,125 ****
--- 111,127 ----
import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy;
import org.graalvm.compiler.phases.tiers.HighTierContext;
import org.graalvm.compiler.phases.tiers.Suites;
import org.graalvm.compiler.phases.tiers.TargetProvider;
import org.graalvm.compiler.phases.util.Providers;
+ import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
import org.graalvm.compiler.runtime.RuntimeProvider;
import org.graalvm.compiler.test.AddExports;
import org.graalvm.compiler.test.GraalTest;
import org.graalvm.compiler.test.JLModule;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.code.BailoutException;
*** 362,379 ****
--- 364,374 ----
public GraalCompilerTest(Backend backend) {
this.backend = backend;
this.providers = backend.getProviders();
}
private Scope debugScope;
@Before
public void beforeTest() {
assert debugScope == null;
debugScope = Debug.scope(getClass());
}
+ @Override
@After
public void afterTest() {
if (invocationPluginExtensions != null) {
synchronized (this) {
if (invocationPluginExtensions != null) {
*** 381,394 ****
--- 376,400 ----
extendedInvocationPlugins = null;
invocationPluginExtensions = null;
}
}
}
if (debugScope != null) {
debugScope.close();
+ super.afterTest();
+ }
+
+ /**
+ * Gets a {@link DebugContext} object corresponding to {@code options}, creating a new one if
+ * none currently exists. Debug contexts created by this method will have their
+ * {@link DebugDumpHandler}s closed in {@link #afterTest()}.
+ */
+ protected DebugContext getDebugContext() {
+ return getDebugContext(getInitialOptions());
}
debugScope = null;
+
+ @Override
+ protected Collection<DebugHandlersFactory> getDebugHandlersFactories() {
+ return Collections.singletonList(new GraalDebugHandlersFactory(getSnippetReflection()));
}
protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
assertEquals(expected, graph, false, true);
}
*** 411,427 ****
--- 417,433 ----
String expectedString = getCanonicalGraphString(expected, excludeVirtual, checkConstants);
String actualString = getCanonicalGraphString(graph, excludeVirtual, checkConstants);
String mismatchString = compareGraphStrings(expected, expectedString, graph, actualString);
if (!excludeVirtual && getNodeCountExcludingUnusedConstants(expected) != getNodeCountExcludingUnusedConstants(graph)) {
! Debug.dump(Debug.BASIC_LEVEL, expected, "Node count not matching - expected");
! Debug.dump(Debug.BASIC_LEVEL, graph, "Node count not matching - actual");
! expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "Node count not matching - expected");
! graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Node count not matching - actual");
Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount() + "\n" + mismatchString);
}
if (!expectedString.equals(actualString)) {
! Debug.dump(Debug.BASIC_LEVEL, expected, "mismatching graphs - expected");
! Debug.dump(Debug.BASIC_LEVEL, graph, "mismatching graphs - actual");
! expected.getDebug().dump(DebugContext.BASIC_LEVEL, expected, "mismatching graphs - expected");
! graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "mismatching graphs - actual");
Assert.fail(mismatchString);
}
}
private static String compareGraphStrings(StructuredGraph expectedGraph, String expectedString, StructuredGraph actualGraph, String actualString) {
*** 930,957 ****
--- 936,966 ----
// loop for retrying compilation
for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
InstalledCode installedCode = null;
try (AllocSpy spy = AllocSpy.open(installedCodeOwner); Scope ds = Debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
+ StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
+ DebugContext debug = graphToCompile.getDebug();
+ try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
final boolean printCompilation = PrintCompilation.getValue(options) && !TTY.isSuppressed();
if (printCompilation) {
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s ...", id, installedCodeOwner.getDeclaringClass().getName(), installedCodeOwner.getName(),
installedCodeOwner.getSignature()));
}
long start = System.currentTimeMillis();
! CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
if (printCompilation) {
TTY.println(String.format("@%-6s Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize()));
}
! try (Scope s = Debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult)) {
! try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
+ DebugContext.Activation a = debug.activate()) {
try {
if (installAsDefault) {
! installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
} else {
! installedCode = addMethod(debug, installedCodeOwner, compResult);
}
if (installedCode == null) {
throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
}
} catch (BailoutException e) {
*** 961,974 ****
--- 970,983 ----
continue;
}
throw e;
}
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
if (!forceCompile) {
cache.put(installedCodeOwner, installedCode);
}
*** 986,995 ****
--- 995,1008 ----
*/
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, OptionValues options) {
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), options);
}
+ protected final StructuredGraph parseForCompile(ResolvedJavaMethod method, DebugContext debug) {
+ return parseEager(method, AllowAssumptions.YES, debug);
+ }
+
protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) {
return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
}
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
*** 1030,1061 ****
--- 1043,1075 ----
*/
@SuppressWarnings("try")
protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
lastCompiledGraph = graphToCompile;
try (Scope s = Debug.scope("Compile", graphToCompile)) {
+ DebugContext debug = graphToCompile.getDebug();
+ try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
assert options != null;
Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
return GraalCompiler.compile(request);
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
}
protected StructuredGraph lastCompiledGraph;
protected SpeculationLog getSpeculationLog() {
return null;
}
! protected InstalledCode addMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
! return backend.addInstalledCode(debug, method, null, compilationResult);
}
! protected InstalledCode addDefaultMethod(DebugContext debug, final ResolvedJavaMethod method, final CompilationResult compilationResult) {
! return backend.createDefaultInstalledCode(debug, method, compilationResult);
}
private final Map<ResolvedJavaMethod, Executable> methodMap = new HashMap<>();
/**
*** 1106,1138 ****
--- 1120,1154 ----
*
* @param methodName the name of the method in {@code this.getClass()} to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
*/
protected final StructuredGraph parseProfiled(String methodName, AllowAssumptions allowAssumptions) {
! return parseProfiled(getResolvedJavaMethod(methodName), allowAssumptions);
! ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
+ return parse(builder(method, allowAssumptions), getDefaultGraphBuilderSuite());
}
/**
* Parses a Java method in {@linkplain GraphBuilderConfiguration#getDefault default} mode to
* produce a graph.
*
* @param method the method to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
*/
protected final StructuredGraph parseProfiled(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
! return parse1(method, getDefaultGraphBuilderSuite(), allowAssumptions, getCompilationId(method), getInitialOptions());
! return parse(builder(method, allowAssumptions), getDefaultGraphBuilderSuite());
}
/**
* Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
* set to true to produce a graph.
*
* @param methodName the name of the method in {@code this.getClass()} to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
*/
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions) {
! return parseEager(getResolvedJavaMethod(methodName), allowAssumptions, getInitialOptions());
! ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
+ return parse(builder(method, allowAssumptions), getEagerGraphBuilderSuite());
}
/**
* Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
* set to true to produce a graph.
*** 1140,1161 ****
--- 1156,1187 ----
* @param methodName the name of the method in {@code this.getClass()} to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
* @param options the option values to be used when compiling the graph
*/
protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions, OptionValues options) {
! return parseEager(getResolvedJavaMethod(methodName), allowAssumptions, options);
! ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
+ return parse(builder(method, allowAssumptions, options), getEagerGraphBuilderSuite());
+ }
+
+ protected final StructuredGraph parseEager(String methodName, AllowAssumptions allowAssumptions, DebugContext debug) {
+ ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
+ return parse(builder(method, allowAssumptions, debug), getEagerGraphBuilderSuite());
}
/**
* Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
* set to true to produce a graph.
*
* @param method the method to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
*/
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
! return parseEager(method, allowAssumptions, getCompilationId(method), getInitialOptions());
! return parse(builder(method, allowAssumptions), getEagerGraphBuilderSuite());
+ }
+
+ protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
+ return parse(builder(method, allowAssumptions, debug), getEagerGraphBuilderSuite());
}
/**
* Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
* set to true to produce a graph.
*** 1163,1173 ****
--- 1189,1199 ----
* @param method the method to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
* @param options the option values to be used when compiling the graph
*/
protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
! return parseEager(method, allowAssumptions, getCompilationId(method), options);
! return parse(builder(method, allowAssumptions, options), getEagerGraphBuilderSuite());
}
/**
* Parses a Java method with {@linkplain GraphBuilderConfiguration#withEagerResolving(boolean)}
* set to true to produce a graph.
*** 1175,1221 ****
--- 1201,1257 ----
* @param method the method to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
* @param compilationId the compilation identifier to be associated with the graph
* @param options the option values to be used when compiling the graph
*/
! protected final StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
! return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true)), allowAssumptions, compilationId, options);
! return parse(builder(method, allowAssumptions, compilationId, options), getEagerGraphBuilderSuite());
}
/**
* Parses a Java method using {@linkplain GraphBuilderConfiguration#withFullInfopoints(boolean)
* full debug} set to true to produce a graph.
*
* @param method the method to be parsed
* @param allowAssumptions specifies if {@link Assumption}s can be made compiling the graph
*/
protected StructuredGraph parseDebug(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)), allowAssumptions, getCompilationId(method),
getInitialOptions());
+ protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, DebugContext debug) {
+ OptionValues options = debug.getOptions();
+ return new Builder(options, debug, allowAssumptions).method(method).compilationId(getCompilationId(method));
+ }
+
+ protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions) {
+ OptionValues options = getInitialOptions();
+ return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
+ }
+
+ protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) {
+ return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(compilationId);
+ }
+
+ protected final Builder builder(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, OptionValues options) {
+ return new Builder(options, getDebugContext(options), allowAssumptions).method(method).compilationId(getCompilationId(method));
+ }
+
+ protected PhaseSuite<HighTierContext> getDebugGraphBuilderSuite() {
+ return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
}
@SuppressWarnings("try")
! private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId,
OptionValues options) {
! protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
+ ResolvedJavaMethod javaMethod = builder.getMethod();
+ if (builder.getCancellable() == null) {
+ builder.cancellable(getCancellable(javaMethod));
+ }
assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod;
// @formatter:off
StructuredGraph graph = new StructuredGraph.Builder(options, allowAssumptions).
method(javaMethod).
speculationLog(getSpeculationLog()).
useProfilingInfo(true).
compilationId(compilationId).
cancellable(getCancellable(javaMethod)).
build();
// @formatter:on
try (Scope ds = Debug.scope("Parsing", javaMethod, graph)) {
+ StructuredGraph graph = builder.build();
+ DebugContext debug = graph.getDebug();
+ try (DebugContext.Scope ds = debug.scope("Parsing", javaMethod, graph)) {
graphBuilderSuite.apply(graph, getDefaultHighTierContext());
return graph;
} catch (Throwable e) {
! throw Debug.handle(e);
! throw debug.handle(e);
}
}
+ protected PhaseSuite<HighTierContext> getEagerGraphBuilderSuite() {
+ return getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true));
+ }
+
/**
* Gets the cancellable that should be associated with a graph being created by any of the
* {@code parse...()} methods.
*
* @param method the method being parsed into a graph
*** 1383,1390 ****
--- 1419,1426 ----
* This method should be called in "timeout" tests which JUnit runs in a different thread.
*/
public static void initializeForTimeout() {
// timeout tests run in a separate thread which needs the DebugEnvironment to be
// initialized
! // DebugEnvironment.ensureInitialized(getInitialOptions());
}
}
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File