Search in sources :

Example 41 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class GraalCompilerTest method compile.

/**
 * 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 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;
    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);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Request(org.graalvm.compiler.core.GraalCompiler.Request) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 42 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class GraalCompilerTest method getCode.

/**
 * 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 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 installAsDefault, OptionValues options) {
    boolean useCache = !forceCompile && getArgumentToBind() == null;
    if (useCache && graph == null) {
        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;
        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))) {
            CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
            CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
            printer.finish(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) {
                    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);
        }
        if (useCache) {
            cache.put(installedCodeOwner, installedCode);
        }
        return installedCode;
    }
    throw GraalError.shouldNotReachHere();
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) BailoutException(jdk.vm.ci.code.BailoutException) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) CompilationPrinter(org.graalvm.compiler.core.CompilationPrinter) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 43 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class DontReuseArgumentSpaceTest method run0.

@Test
public void run0() throws Throwable {
    /*
         * Exercise the methods once so everything is resolved
         */
    callTwice(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    /*
         * Create a standalone compile of killArguments. This test assumes that zapping of argument
         * space is being performed by the backend.
         */
    ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
    StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
    CompilationResult compilationResult = compile(javaMethod, graph);
    DebugContext debug = getDebugContext();
    getBackend().createDefaultInstalledCode(debug, javaMethod, compilationResult);
    test("callTwice", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationResult(org.graalvm.compiler.code.CompilationResult) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Example 44 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class InfopointReasonTest method callInfopoints.

@Test
public void callInfopoints() {
    final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
    final StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
    for (Infopoint sp : cr.getInfopoints()) {
        assertNotNull(sp.reason);
        if (sp instanceof Call) {
            assertDeepEquals(InfopointReason.CALL, sp.reason);
        }
    }
}
Also used : Call(jdk.vm.ci.code.site.Call) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Infopoint(jdk.vm.ci.code.site.Infopoint) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Example 45 with CompilationResult

use of org.graalvm.compiler.code.CompilationResult in project graal by oracle.

the class CFGPrinterObserver method checkMethodScope.

/**
 * Looks for the outer most method and its {@link DebugDumpScope#decorator}s in the current
 * debug scope and opens a new compilation scope if this pair does not match the current method
 * and decorator pair.
 */
private boolean checkMethodScope(DebugContext debug) {
    JavaMethod method = null;
    CompilationIdentifier compilation = null;
    ArrayList<String> decorators = new ArrayList<>();
    for (Object o : debug.context()) {
        if (o instanceof JavaMethod) {
            method = (JavaMethod) o;
            decorators.clear();
        } else if (o instanceof StructuredGraph) {
            StructuredGraph graph = (StructuredGraph) o;
            if (graph.method() != null) {
                method = graph.method();
                decorators.clear();
                compilation = graph.compilationId();
            }
        } else if (o instanceof DebugDumpScope) {
            DebugDumpScope debugDumpScope = (DebugDumpScope) o;
            if (debugDumpScope.decorator) {
                decorators.add(debugDumpScope.name);
            }
        } else if (o instanceof CompilationResult) {
            CompilationResult compilationResult = (CompilationResult) o;
            compilation = compilationResult.getCompilationId();
        }
    }
    if (method == null && compilation == null) {
        return false;
    }
    if (compilation != null) {
        if (!compilation.equals(curCompilation) || !curDecorators.equals(decorators)) {
            cfgPrinter.printCompilation(compilation);
        }
    } else {
        if (!method.equals(curMethod) || !curDecorators.equals(decorators)) {
            cfgPrinter.printCompilation(method);
        }
    }
    curCompilation = compilation;
    curMethod = method;
    curDecorators = decorators;
    return true;
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) ArrayList(java.util.ArrayList) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Aggregations

CompilationResult (org.graalvm.compiler.code.CompilationResult)46 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)20 Test (org.junit.Test)15 DebugContext (org.graalvm.compiler.debug.DebugContext)13 CallingConvention (jdk.vm.ci.code.CallingConvention)12 RegisterConfig (jdk.vm.ci.code.RegisterConfig)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)12 Register (jdk.vm.ci.code.Register)11 TargetDescription (jdk.vm.ci.code.TargetDescription)11 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)11 AMD64Assembler (org.graalvm.compiler.asm.amd64.AMD64Assembler)9 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)8 Infopoint (jdk.vm.ci.code.site.Infopoint)8 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)8 OptionValues (org.graalvm.compiler.options.OptionValues)8 InstalledCode (jdk.vm.ci.code.InstalledCode)7 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)6 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)6 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)5 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)5