Search in sources :

Example 1 with InstalledCode

use of jdk.vm.ci.code.InstalledCode in project graal by oracle.

the class TruffleCompilerImpl method compilePEGraph.

/**
 * Compiles a graph produced by {@link PartialEvaluator#createGraph partial evaluation}.
 *
 * @param graph a graph resulting from partial evaluation
 * @param name the name to be used for the returned {@link CompilationResult#getName() result}
 * @param graphBuilderSuite phase suite to be used for creating new graphs during inlining
 * @param compilationRequest
 * @param listener
 */
@SuppressWarnings("try")
public CompilationResult compilePEGraph(StructuredGraph graph, String name, PhaseSuite<HighTierContext> graphBuilderSuite, CompilableTruffleAST compilable, CompilationRequest compilationRequest, TruffleCompilerListener listener) {
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope s = debug.scope("TruffleFinal")) {
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After TruffleTier");
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    CompilationResult result = null;
    try (DebugCloseable a = CompilationTime.start(debug);
        DebugContext.Scope s = debug.scope("TruffleGraal.GraalCompiler", graph, providers.getCodeCache());
        DebugCloseable c = CompilationMemUse.start(debug)) {
        CompilationResult compilationResult = createCompilationResult(name, graph.compilationId());
        result = GraalCompiler.compileGraph(graph, graph.method(), providers, backend, graphBuilderSuite, Optimizations, graph.getProfilingInfo(), suites, lirSuites, compilationResult, CompilationResultBuilderFactory.Default);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    if (listener != null) {
        listener.onGraalTierFinished(compilable, new GraphInfoImpl(graph));
    }
    try (DebugCloseable a = CodeInstallationTime.start(debug);
        DebugCloseable c = CodeInstallationMemUse.start(debug)) {
        InstalledCode installedCode = createInstalledCode(compilable);
        backend.createInstalledCode(debug, graph.method(), compilationRequest, result, graph.getSpeculationLog(), installedCode, false);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return result;
}
Also used : Scope(org.graalvm.compiler.debug.DebugContext.Scope) InstalledCode(jdk.vm.ci.code.InstalledCode) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 2 with InstalledCode

use of jdk.vm.ci.code.InstalledCode in project graal by oracle.

the class AssemblerTest method runTest.

protected Object runTest(String methodName, CodeGenTest test, Object... args) {
    Method method = getMethod(methodName);
    InstalledCode code = assembleMethod(method, test);
    try {
        return code.executeVarargs(args);
    } catch (InvalidInstalledCodeException e) {
        throw new RuntimeException(e);
    }
}
Also used : InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) InstalledCode(jdk.vm.ci.code.InstalledCode) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with InstalledCode

use of jdk.vm.ci.code.InstalledCode in project graal by oracle.

the class PartialEscapeAnalysisTreesTest method testGraph.

/**
 * Prepare a graph that includes some blackholes and then remove the blackholes and compile
 * normally to create an unusual situation for PEA.
 */
@SuppressWarnings("try")
public void testGraph(String name) {
    ResolvedJavaMethod method = getResolvedJavaMethod(name);
    prepareGraph(name, true);
    try (DebugContext.Scope s = graph.getDebug().scope(getClass(), method, getCodeCache(), graph)) {
        for (BlackholeNode node : graph.getNodes().filter(BlackholeNode.class)) {
            graph.removeFixed(node);
        }
        new DeadCodeEliminationPhase().apply(graph);
        new CanonicalizerPhase().apply(graph, context);
        InstalledCode code = getCode(method, graph, true);
        GraalCompilerTest.Result r = executeExpected(method, null, true);
        int expectedInstances = ((TreeNode) r.returnValue).countInstances();
        TreeNode r2 = (TreeNode) code.executeVarargs(true);
        Assert.assertEquals("Wrong number of nodes in tree", expectedInstances, r2.countInstances());
        r = executeExpected(method, null, false);
        expectedInstances = ((TreeNode) r.returnValue).countInstances();
        r2 = (TreeNode) code.executeVarargs(false);
        Assert.assertEquals("Wrong number of nodes in tree", expectedInstances, r2.countInstances());
    } catch (Throwable e) {
        throw graph.getDebug().handle(e);
    }
}
Also used : BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with InstalledCode

use of jdk.vm.ci.code.InstalledCode 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 5 with InstalledCode

use of jdk.vm.ci.code.InstalledCode in project graal by oracle.

the class SafepointRethrowDeoptTest method test.

@Test
public void test() {
    Assume.assumeTrue(GraalOptions.GenLoopSafepoints.getValue(getInitialOptions()));
    synchronized (SafepointRethrowDeoptTest.class) {
        // needs static fields
        terminate = 1;
        InstalledCode installed = getCode(getResolvedJavaMethod("execute"));
        terminate = 0;
        entered = 0;
        CountDownLatch cdl = new CountDownLatch(1);
        Thread t1 = new Thread(() -> {
            try {
                cdl.await();
                while (entered == 0) {
                /* spin */
                }
                installed.invalidate();
            } catch (InterruptedException e) {
                Assert.fail("interrupted");
            } finally {
                terminate = 1;
            }
        });
        Thread t2 = new Thread(() -> {
            cdl.countDown();
            Object result;
            try {
                result = installed.executeVarargs();
            } catch (Exception e) {
                e.printStackTrace();
                Assert.fail("exception");
                return;
            }
            Assert.assertEquals(RETURN_VALUE, result);
        });
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            Assert.fail("interrupted");
        }
    }
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Aggregations

InstalledCode (jdk.vm.ci.code.InstalledCode)40 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)25 Test (org.junit.Test)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)13 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)10 CompilationResult (org.graalvm.compiler.code.CompilationResult)8 InvalidInstalledCodeException (jdk.vm.ci.code.InvalidInstalledCodeException)6 DebugContext (org.graalvm.compiler.debug.DebugContext)5 OptionValues (org.graalvm.compiler.options.OptionValues)4 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)2 GraalError (org.graalvm.compiler.debug.GraalError)2 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1