Search in sources :

Example 11 with CompilationResult

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

the class MonitorDeoptTest method run0.

@Test
public void run0() throws Throwable {
    ResolvedJavaMethod javaMethod = getResolvedJavaMethod("test");
    StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
    removeLoopSafepoint(graph);
    CompilationResult compilationResult = compile(javaMethod, graph);
    final InstalledCode installedCode = getBackend().createDefaultInstalledCode(graph.getDebug(), javaMethod, compilationResult);
    final Monitor monitor = new Monitor();
    Thread controlThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                // Wait for thread to reach RUNNING_GRAAL and then invalidate the code
                monitor.invalidate(installedCode);
                // wait for the main thread to continue running in the interpreter
                monitor.waitState(State.RUNNING_INTERPRETER);
                // terminate the main thread
                monitor.setState(State.TERMINATED);
            } catch (InterruptedException e) {
            }
        }
    });
    controlThread.start();
    boolean result = test(monitor);
    Assert.assertTrue(result);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 12 with CompilationResult

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

the class InfopointReasonTest method lineInfopoints.

@Test
public void lineInfopoints() {
    final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
    final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
    int graphLineSPs = 0;
    for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
        if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
            ++graphLineSPs;
        }
    }
    assertTrue(graphLineSPs > 0);
    PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
    final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
    int lineSPs = 0;
    for (Infopoint sp : cr.getInfopoints()) {
        assertNotNull(sp.reason);
        if (sp.reason == InfopointReason.BYTECODE_POSITION) {
            ++lineSPs;
        }
    }
    assertTrue(lineSPs > 0);
}
Also used : FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Infopoint(jdk.vm.ci.code.site.Infopoint) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Infopoint(jdk.vm.ci.code.site.Infopoint) Test(org.junit.Test)

Example 13 with CompilationResult

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

the class Stub method buildCompilationResult.

@SuppressWarnings("try")
private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) {
    CompilationIdentifier compilationId = getStubCompilationId();
    final StructuredGraph graph = getGraph(debug, compilationId);
    CompilationResult compResult = new CompilationResult(compilationId, toString(), GeneratePIC.getValue(options));
    // Stubs cannot be recompiled so they cannot be compiled with assumptions
    assert graph.getAssumptions() == null;
    if (!(graph.start() instanceof StubStartNode)) {
        StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
        newStart.setStateAfter(graph.start().stateAfter());
        graph.replaceFixed(graph.start(), newStart);
    }
    try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) {
        Suites suites = createSuites();
        emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
        LIRSuites lirSuites = createLIRSuites();
        emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
        assert checkStubInvariants(compResult);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return compResult;
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) StubStartNode(org.graalvm.compiler.hotspot.nodes.StubStartNode) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) CompilationResult(org.graalvm.compiler.code.CompilationResult) DebugContext(org.graalvm.compiler.debug.DebugContext) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 14 with CompilationResult

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

the class Stub method getCode.

/**
 * Gets the code for this stub, compiling it first if necessary.
 */
@SuppressWarnings("try")
public synchronized InstalledCode getCode(final Backend backend) {
    if (code == null) {
        try (DebugContext debug = openDebugContext(DebugContext.forCurrentThread())) {
            try (DebugContext.Scope d = debug.scope("CompilingStub", providers.getCodeCache(), debugScopeContext())) {
                CodeCacheProvider codeCache = providers.getCodeCache();
                CompilationResult compResult = buildCompilationResult(debug, backend);
                try (DebugContext.Scope s = debug.scope("CodeInstall", compResult);
                    DebugContext.Activation a = debug.activate()) {
                    assert destroyedCallerRegisters != null;
                    // Add a GeneratePIC check here later, we don't want to install
                    // code if we don't have a corresponding VM global symbol.
                    HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(codeCache, null, null, compResult);
                    code = codeCache.installCode(null, compiledCode, null, null, false);
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
            } catch (Throwable e) {
                throw debug.handle(e);
            }
            assert code != null : "error installing stub " + this;
        }
    }
    return code;
}
Also used : HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider)

Example 15 with CompilationResult

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

the class SubstrateCodeCacheProvider method installCode.

@Override
@SuppressFBWarnings(value = { "BC_UNCONFIRMED_CAST" }, justification = "We know what we are doing.")
public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compiledCode, InstalledCode predefinedInstalledCode, SpeculationLog log, boolean isDefault) {
    VMError.guarantee(!isDefault);
    SubstrateInstalledCode substrateInstalledCode;
    if (predefinedInstalledCode instanceof SubstrateInstalledCode.Access) {
        substrateInstalledCode = ((SubstrateInstalledCode.Access) predefinedInstalledCode).getSubstrateInstalledCode();
    } else {
        substrateInstalledCode = (SubstrateInstalledCode) predefinedInstalledCode;
    }
    CompilationResult compResult = ((SubstrateCompiledCode) compiledCode).getCompilationResult();
    InstalledCodeBuilder builder = new InstalledCodeBuilder((SharedRuntimeMethod) method, compResult, substrateInstalledCode, null);
    builder.install();
    return predefinedInstalledCode;
}
Also used : SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) SubstrateCompiledCode(com.oracle.svm.core.graal.code.SubstrateCompiledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) SuppressFBWarnings(org.graalvm.compiler.core.common.SuppressFBWarnings)

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