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	Mon Mar 20 17:37:25 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java	Mon Mar 20 17:37:25 2017

*** 42,69 **** --- 42,65 ---- import java.util.ListIterator; import java.util.Map; import java.util.Set; import java.util.function.Supplier; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.internal.AssumptionViolatedException; import org.graalvm.compiler.api.directives.GraalDirectives; import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.api.test.Graal; import org.graalvm.compiler.code.CompilationResult; 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.common.util.ModuleAPI; import org.graalvm.compiler.core.target.Backend; import org.graalvm.compiler.debug.Debug; import org.graalvm.compiler.debug.Debug.Scope; 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;
*** 96,106 **** --- 92,102 ---- import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.nodes.spi.LoweringProvider; import org.graalvm.compiler.nodes.spi.Replacements; import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; ! import org.graalvm.compiler.options.DerivedOptionValue; ! import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.BasePhase; import org.graalvm.compiler.phases.OptimisticOptimizations; import org.graalvm.compiler.phases.Phase; import org.graalvm.compiler.phases.PhaseSuite; import org.graalvm.compiler.phases.common.CanonicalizerPhase;
*** 110,122 **** --- 106,125 ---- 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.runtime.RuntimeProvider; + import org.graalvm.compiler.test.AddExports; import org.graalvm.compiler.test.GraalTest; + 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; import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.meta.ConstantReflectionProvider; import jdk.vm.ci.meta.DeoptimizationReason;
*** 125,141 **** --- 128,146 ---- import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.ProfilingInfo; import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaType; import jdk.vm.ci.meta.SpeculationLog; + import jdk.vm.ci.meta.Assumptions.Assumption; + import jdk.vm.ci.services.Services; /** * Base class for Graal compiler unit tests. * <p> * White box tests for Graal compiler transformations use this pattern: * <ol> - * <li>Create a graph by {@linkplain #parseEager(String, AllowAssumptions) parsing} a method.</li> * <li>Manually modify the graph (e.g. replace a parameter node with a constant).</li> * <li>Apply a transformation to the graph.</li> * <li>Assert that the transformed graph is equal to an expected graph.</li> * </ol> * <p>
*** 145,160 **** --- 150,199 ---- * {@link #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. * <p> * These tests will be run by the {@code mx unittest} command. */ + @AddExports({"jdk.internal.vm.ci/jdk.vm.ci.meta", + "jdk.internal.vm.ci/jdk.vm.ci.services", + "jdk.internal.vm.ci/jdk.vm.ci.code", + "jdk.internal.vm.ci/jdk.vm.ci.services", + "java.base/jdk.internal.org.objectweb.asm", + "java.base/jdk.internal.org.objectweb.asm.tree"}) public abstract class GraalCompilerTest extends GraalTest { + /** + * Gets the initial option values provided by the Graal runtime. These are option values + * typically parsed from the command line. + */ + public static OptionValues getInitialOptions() { + return Graal.getRequiredCapability(OptionValues.class); + } + + private static final int BAILOUT_RETRY_LIMIT = 1; private final Providers providers; private final Backend backend; private final DerivedOptionValue<Suites> suites; private final DerivedOptionValue<LIRSuites> lirSuites; + + /** + * Representative class for the {@code java.base} module. + */ + public static final Class<?> JAVA_BASE = Class.class; + + /** + * Representative class for the {@code jdk.vm.ci} module. + */ + public static final Class<?> JDK_VM_CI = Services.class; + + /** + * Exports the package named {@code packageName} declared in {@code moduleMember}'s module to + * this object's module. This must be called before accessing packages that are no longer public + * as of JDK 9. + */ + protected final void exportPackage(Class<?> moduleMember, String packageName) { + if (!Java8OrEarlier) { + ModuleAPI.exportPackageTo(moduleMember, packageName, getClass()); + } + } /** * Denotes a test method that must be inlined by the {@link BytecodeParser}. */ @Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
*** 210,221 **** --- 249,260 ---- } protected static void shouldBeOptimizedAway() { } ! protected Suites createSuites(OptionValues opts) { ! Suites ret = backend.getSuites().getDefaultSuites().copy(); ! Suites ret = backend.getSuites().getDefaultSuites(opts).copy(); ListIterator<BasePhase<? super HighTierContext>> iter = ret.getHighTier().findPhase(ConvertDeoptimizeToGuardPhase.class, true); if (iter == null) { /* * in the economy configuration, we don't have the ConvertDeoptimizeToGuard phase, so we * just select the first CanonicalizerPhase in HighTier
*** 291,310 **** --- 330,347 ---- } }); return ret; } ! protected LIRSuites createLIRSuites(OptionValues opts) { ! LIRSuites ret = backend.getSuites().getDefaultLIRSuites(opts).copy(); return ret; } public GraalCompilerTest() { this.backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend(); this.providers = getBackend().getProviders(); this.suites = new DerivedOptionValue<>(this::createSuites); this.lirSuites = new DerivedOptionValue<>(this::createLIRSuites); } /** * Set up a test for a non-default backend. The test should check (via {@link #getBackend()} ) * whether the desired backend is available.
*** 319,342 **** --- 356,375 ---- } else { // Fall back to the default/host backend this.backend = runtime.getHostBackend(); } this.providers = backend.getProviders(); this.suites = new DerivedOptionValue<>(this::createSuites); this.lirSuites = new DerivedOptionValue<>(this::createLIRSuites); } /** * Set up a test for a non-default backend. * * @param backend the desired backend */ public GraalCompilerTest(Backend backend) { this.backend = backend; this.providers = backend.getProviders(); this.suites = new DerivedOptionValue<>(this::createSuites); this.lirSuites = new DerivedOptionValue<>(this::createLIRSuites); } private Scope debugScope; @Before
*** 530,547 **** --- 563,572 ---- protected Backend getBackend() { return backend; } protected Suites getSuites() { return suites.getValue(); } protected LIRSuites getLIRSuites() { return lirSuites.getValue(); } protected final Providers getProviders() { return providers; } protected HighTierContext getDefaultHighTierContext() {
*** 619,629 **** --- 644,654 ---- protected Object referenceInvoke(ResolvedJavaMethod method, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { return invoke(method, receiver, args); } ! protected static class Result { ! public static class Result { public final Object returnValue; public final Throwable exception; public Result(Object returnValue, Throwable exception) {
*** 663,678 **** --- 688,707 ---- after(); } } protected Result executeActual(ResolvedJavaMethod method, Object receiver, Object... args) { + return executeActual(getInitialOptions(), method, receiver, args); + } + + protected Result executeActual(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) { before(method); Object[] executeArgs = argsWithReceiver(receiver, args); checkArgs(method, executeArgs); ! InstalledCode compiledMethod = getCode(method, options); try { return new Result(compiledMethod.executeVarargs(executeArgs), null); } catch (Throwable e) { return new Result(null, e); } finally {
*** 716,733 **** --- 745,767 ---- } } return applyArgSuppliers(executeArgs); } ! protected void test(String name, Object... args) { ! protected final Result test(String name, Object... args) { + return test(getInitialOptions(), name, args); + } + + protected final Result test(OptionValues options, String name, Object... args) { try { ResolvedJavaMethod method = getResolvedJavaMethod(name); Object receiver = method.isStatic() ? null : this; ! return test(options, method, receiver, args); } catch (AssumptionViolatedException e) { // Suppress so that subsequent calls to this method within the // same Junit @Test annotated method can proceed. + return null; } } /** * Type denoting a lambda that supplies a fresh value each time it is called. This is useful
*** 743,758 **** --- 777,796 ---- */ public static Object supply(ArgSupplier supplier) { return supplier; } ! protected void test(ResolvedJavaMethod method, Object receiver, Object... args) { ! protected Result test(ResolvedJavaMethod method, Object receiver, Object... args) { + return test(getInitialOptions(), method, receiver, args); + } + + protected Result test(OptionValues options, ResolvedJavaMethod method, Object receiver, Object... args) { Result expect = executeExpected(method, receiver, args); ! if (getCodeCache() == null) { ! return; ! if (getCodeCache() != null) { ! testAgainstExpected(options, method, expect, receiver, args); } ! testAgainstExpected(method, expect, receiver, args); ! return expect; } /** * Process a given set of arguments, converting any {@link ArgSupplier} argument to the argument * it supplies.
*** 768,788 **** --- 806,839 ---- } } return res; } ! protected final void testAgainstExpected(ResolvedJavaMethod method, Result expect, Object receiver, Object... args) { ! testAgainstExpected(getInitialOptions(), method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args); } ! protected Result executeActualCheckDeopt(ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { ! protected void testAgainstExpected(ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { + testAgainstExpected(getInitialOptions(), method, expect, shouldNotDeopt, receiver, args); + } + + protected final void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Object receiver, Object... args) { + testAgainstExpected(options, method, expect, Collections.<DeoptimizationReason> emptySet(), receiver, args); + } + + protected void testAgainstExpected(OptionValues options, ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { + Result actual = executeActualCheckDeopt(options, method, shouldNotDeopt, receiver, args); + assertEquals(expect, actual); + } + + protected Result executeActualCheckDeopt(OptionValues options, ResolvedJavaMethod method, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { Map<DeoptimizationReason, Integer> deoptCounts = new EnumMap<>(DeoptimizationReason.class); ProfilingInfo profile = method.getProfilingInfo(); for (DeoptimizationReason reason : shouldNotDeopt) { deoptCounts.put(reason, profile.getDeoptimizationCount(reason)); } ! Result actual = executeActual(options, method, receiver, args); profile = method.getProfilingInfo(); // profile can change after execution for (DeoptimizationReason reason : shouldNotDeopt) { Assert.assertEquals((int) deoptCounts.get(reason), profile.getDeoptimizationCount(reason)); } return actual;
*** 799,882 **** --- 850,953 ---- } assertDeepEquals(expect.returnValue, actual.returnValue); } } protected void testAgainstExpected(ResolvedJavaMethod method, Result expect, Set<DeoptimizationReason> shouldNotDeopt, Object receiver, Object... args) { Result actual = executeActualCheckDeopt(method, shouldNotDeopt, receiver, args); assertEquals(expect, actual); } private Map<ResolvedJavaMethod, InstalledCode> cache = new HashMap<>(); /** * Gets installed code for a given method, compiling it first if necessary. The graph is parsed - * {@link #parseEager(ResolvedJavaMethod, AllowAssumptions) eagerly}. */ ! protected final InstalledCode getCode(ResolvedJavaMethod method) { ! return getCode(method, null); ! return getCode(method, null, false, false, getInitialOptions()); + } + + protected final InstalledCode getCode(ResolvedJavaMethod method, OptionValues options) { + return getCode(method, null, false, false, options); } /** * Gets installed code for a given method, compiling it first if necessary. * * @param installedCodeOwner the method the compiled code will be associated with when installed * @param graph the graph to be compiled. If null, a graph will be obtained from * {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}. */ ! protected final InstalledCode getCode(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) { ! return getCode(installedCodeOwner, graph, false, false, graph == null ? getInitialOptions() : graph.getOptions()); } protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph0, boolean forceCompile) { return getCode(installedCodeOwner, graph0, forceCompile, false); + /** + * Gets installed code for a given method and graph, compiling it first if necessary. + * + * @param installedCodeOwner the method the compiled code will be associated with when installed + * @param graph the graph to be compiled. If null, a graph will be obtained from + * {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}. + * @param forceCompile specifies whether to ignore any previous code cached for the (method, + * key) pair + */ + protected final InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile) { + return getCode(installedCodeOwner, graph, forceCompile, false, graph == null ? getInitialOptions() : graph.getOptions()); } /** * Gets installed code for a given method and graph, compiling it first if necessary. * * @param installedCodeOwner the method the compiled code will be associated with when installed * @param graph the graph to be compiled. If null, a graph will be obtained from * {@code installedCodeOwner} via {@link #parseForCompile(ResolvedJavaMethod)}. * @param forceCompile specifies whether to ignore any previous code cached for the (method, * key) pair ! * @param installDefault specifies whether to install as the default implementation ! * @param installAsDefault specifies whether to install as the default implementation + * @param options the options that will be used in {@link #parseForCompile(ResolvedJavaMethod)} */ @SuppressWarnings("try") ! protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installDefault) { ! protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) { if (!forceCompile) { InstalledCode cached = cache.get(installedCodeOwner); if (cached != null) { if (cached.isValid()) { return cached; } } } + // 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))) { ! 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())); + 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, graph, id); ! CompilationResult compResult = compile(installedCodeOwner, graph, 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)) { ! if (installDefault) { ! try { + if (installAsDefault) { installedCode = addDefaultMethod(installedCodeOwner, compResult); } else { installedCode = addMethod(installedCodeOwner, compResult); } if (installedCode == null) { throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)")); } + } catch (BailoutException e) { + if (retry <= BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) { + // retry (if there is no predefined graph) + TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id)); + continue; + } + throw e; + } } catch (Throwable e) { throw Debug.handle(e); } } catch (Throwable e) { throw Debug.handle(e);
*** 885,909 **** --- 956,985 ---- if (!forceCompile) { cache.put(installedCodeOwner, installedCode); } return installedCode; } + throw GraalError.shouldNotReachHere(); + } /** * Used to produce a graph for a method about to be compiled by * {@link #compile(ResolvedJavaMethod, StructuredGraph)} if the second parameter to that method * is null. * ! * The default implementation in {@link GraalCompilerTest} is to call {@link #parseEager}. * {@link #parseEager(ResolvedJavaMethod, AllowAssumptions)}. */ + protected StructuredGraph parseForCompile(ResolvedJavaMethod method, OptionValues options) { + return parseEager(method, AllowAssumptions.YES, getCompilationId(method), options); + } + protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) { ! return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions()); } ! protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) { ! return parseEager(method, AllowAssumptions.YES, compilationId, options); } /** * Compiles a given method. *
*** 911,944 **** --- 987,1027 ---- * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will * be obtained from {@code installedCodeOwner} via * {@link #parseForCompile(ResolvedJavaMethod)}. */ protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) { ! return compile(installedCodeOwner, graph, getOrCreateCompilationId(installedCodeOwner, graph)); ! OptionValues options = graph == null ? getInitialOptions() : graph.getOptions(); + return compile(installedCodeOwner, graph, new CompilationResult(), getOrCreateCompilationId(installedCodeOwner, graph), options); + } + + protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) { + OptionValues options = graph == null ? getInitialOptions() : graph.getOptions(); + return compile(installedCodeOwner, graph, new CompilationResult(), compilationId, options); } ! protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) { ! return compile(installedCodeOwner, graph, new CompilationResult(), compilationId); ! protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, OptionValues options) { ! assert graph == null || graph.getOptions() == options; + return compile(installedCodeOwner, graph, new CompilationResult(), getOrCreateCompilationId(installedCodeOwner, graph), options); } /** * Compiles a given method. * * @param installedCodeOwner the method the compiled code will be associated with when installed * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will * be obtained from {@code installedCodeOwner} via * {@link #parseForCompile(ResolvedJavaMethod)}. * @param compilationResult * @param compilationId */ @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)) { + assert options != null; Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, ! graphToCompile.getProfilingInfo(), getSuites(), getLIRSuites(), compilationResult, CompilationResultBuilderFactory.Default); ! graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default); return GraalCompiler.compile(request); } catch (Throwable e) { throw Debug.handle(e); } }
*** 1000,1064 **** --- 1083,1186 ---- /** * Parses a Java method in {@linkplain GraphBuilderConfiguration#getDefault default} mode 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 parseProfiled(String methodName, AllowAssumptions allowAssumptions) { return parseProfiled(getResolvedJavaMethod(methodName), allowAssumptions); } /** * 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 parseProfiled(m, allowAssumptions, getCompilationId(m)); ! return parse1(method, getDefaultGraphBuilderSuite(), allowAssumptions, getCompilationId(method), getInitialOptions()); } protected StructuredGraph parseProfiled(ResolvedJavaMethod m, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId) { return parse1(m, getDefaultGraphBuilderSuite(), allowAssumptions, compilationId); + /** + * 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()); } /** * 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 + * @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); ! return parseEager(getResolvedJavaMethod(methodName), allowAssumptions, options); } /** * 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()); } protected StructuredGraph parseEager(ResolvedJavaMethod m, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId) { return parse1(m, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true)), allowAssumptions, compilationId); + /** + * 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 + * @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); } /** ! * Parses a Java method using {@linkplain GraphBuilderConfiguration#withFullInfopoints(boolean) - * full debug} set to true to produce a graph. ! * 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 + * @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 parseDebug(ResolvedJavaMethod m, AllowAssumptions allowAssumptions) { ! return parseDebug(m, allowAssumptions, getCompilationId(m)); ! protected StructuredGraph parseEager(ResolvedJavaMethod method, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, OptionValues options) { ! return parse1(method, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true)), allowAssumptions, compilationId, options); } protected StructuredGraph parseDebug(ResolvedJavaMethod m, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId) { return parse1(m, getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)), allowAssumptions, compilationId); + /** + * 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()); } @SuppressWarnings("try") ! private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId) { ! private StructuredGraph parse1(ResolvedJavaMethod javaMethod, PhaseSuite<HighTierContext> graphBuilderSuite, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, + OptionValues options) { assert javaMethod.getAnnotation(Test.class) == null : "shouldn't parse method with @Test annotation: " + javaMethod; ! StructuredGraph graph = new StructuredGraph(javaMethod, allowAssumptions, getSpeculationLog(), compilationId); ! StructuredGraph graph = new StructuredGraph.Builder(options, allowAssumptions).method(javaMethod).speculationLog(getSpeculationLog()).useProfilingInfo(true).compilationId( + compilationId).build(); try (Scope ds = Debug.scope("Parsing", javaMethod, graph)) { graphBuilderSuite.apply(graph, getDefaultHighTierContext()); return graph; } catch (Throwable e) { throw Debug.handle(e);
*** 1184,1189 **** --- 1306,1320 ---- * @return true if we run on the architecture given by name */ protected boolean isArchitecture(String name) { return name.equals(backend.getTarget().arch.getName()); } + + /** + * 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