Search in sources :

Example 1 with TruffleCompilation

use of org.graalvm.compiler.truffle.common.TruffleCompilation in project graal by oracle.

the class TransferToInterpreterTest method test.

@Test
public void test() {
    RootNode rootNode = new TestRootNode();
    GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
    OptimizedCallTarget target = (OptimizedCallTarget) rootNode.getCallTarget();
    target.call(0);
    Assert.assertFalse(target.isValid());
    final OptimizedCallTarget compilable = target;
    TruffleCompiler compiler = runtime.getTruffleCompiler(compilable);
    Map<String, Object> options = GraalTruffleRuntime.getOptionsForCompiler(target);
    try (TruffleCompilation compilation = compiler.openCompilation(compilable)) {
        TruffleDebugContext debug = compiler.openDebugContext(options, compilation);
        compiler.doCompile(debug, compilation, options, new TestTruffleCompilationTask(), null);
    }
    Assert.assertTrue(target.isValid());
    target.call(0);
    Assert.assertTrue(target.isValid());
    target.call(1);
    Assert.assertFalse(target.isValid());
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) TruffleCompiler(org.graalvm.compiler.truffle.common.TruffleCompiler) Test(org.junit.Test)

Example 2 with TruffleCompilation

use of org.graalvm.compiler.truffle.common.TruffleCompilation in project graal by oracle.

the class TruffleToLibGraalEntryPoints method closeCompilation.

@TruffleToLibGraal(CloseCompilation)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_closeCompilation")
public static void closeCompilation(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilationHandle) {
    try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, CloseCompilation, env)) {
        TruffleCompilation compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilation.class);
        HSCompilableTruffleAST compilable = (HSCompilableTruffleAST) compilation.getCompilable();
        try {
            compilation.close();
        } finally {
            compilable.release(env);
            HSObject.cleanHandles(env);
            doReferenceHandling();
        }
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 3 with TruffleCompilation

use of org.graalvm.compiler.truffle.common.TruffleCompilation in project graal by oracle.

the class JNIExceptionWrapperTest method testMergedStackTraceImpl.

private void testMergedStackTraceImpl() throws Exception {
    setupContext("engine.CompilationExceptionsAreThrown", Boolean.TRUE.toString(), "engine.CompilationExceptionsAreFatal", Boolean.FALSE.toString());
    GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
    OptimizedCallTarget compilable = (OptimizedCallTarget) RootNode.createConstantNode(42).getCallTarget();
    TruffleCompiler compiler = runtime.getTruffleCompiler(compilable);
    try (TruffleCompilation compilation = compiler.openCompilation(compilable)) {
        try (TruffleDebugContext debug = compiler.openDebugContext(GraalTruffleRuntime.getOptionsForCompiler(compilable), compilation)) {
            TestListener listener = new TestListener();
            compiler.doCompile(debug, compilation, GraalTruffleRuntime.getOptionsForCompiler(compilable), new TestTruffleCompilationTask(), listener);
        }
    } catch (Throwable t) {
        String message = t.getMessage();
        int runtimeIndex = findFrame(message, JNIExceptionWrapperTest.class, "testMergedStackTrace");
        assertNotEquals(message, -1, runtimeIndex);
        int listenerIndex = findFrame(message, TestListener.class, "onTruffleTierFinished");
        assertNotEquals(message, -1, listenerIndex);
        int compilerIndex = findFrame(message, TruffleCompilerImpl.class, "compileAST");
        assertNotEquals(message, -1, compilerIndex);
        assertTrue(listenerIndex < compilerIndex);
        assertTrue(compilerIndex < runtimeIndex);
    }
}
Also used : TruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) TruffleCompiler(org.graalvm.compiler.truffle.common.TruffleCompiler)

Example 4 with TruffleCompilation

use of org.graalvm.compiler.truffle.common.TruffleCompilation in project graal by oracle.

the class IsolateAwareTruffleCompiler method doCompile0.

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class)
@CEntryPointOptions(publishAs = CEntryPointOptions.Publish.NotPublished)
private static ClientHandle<String> doCompile0(@SuppressWarnings("unused") @CEntryPoint.IsolateThreadContext CompilerIsolateThread context, ClientIsolateThread client, ImageHeapRef<SubstrateTruffleCompiler> delegateRef, ClientHandle<TruffleCompilationIdentifier> compilationIdentifierHandle, ClientHandle<SubstrateCompilableTruffleAST> compilableHandle, ClientHandle<byte[]> encodedOptionsHandle, int encodedOptionsLength, ClientHandle<TruffleCompilationTask> taskHandle, ClientHandle<IsolatedEventContext> eventContextHandle, boolean firstCompilation) {
    IsolatedCompileContext.set(new IsolatedCompileContext(client));
    try {
        SubstrateTruffleCompiler delegate = ImageHeapObjects.deref(delegateRef);
        Map<String, Object> options = decodeOptions(client, encodedOptionsHandle, encodedOptionsLength);
        IsolatedCompilableTruffleAST compilable = new IsolatedCompilableTruffleAST(compilableHandle);
        delegate.initialize(options, compilable, firstCompilation);
        TruffleCompilation compilation = new IsolatedCompilationIdentifier(compilationIdentifierHandle, compilable);
        TruffleCompilationTask task = null;
        if (taskHandle.notEqual(IsolatedHandles.nullHandle())) {
            task = new IsolatedTruffleCompilationTask(taskHandle);
        }
        TruffleCompilerListener listener = null;
        if (eventContextHandle.notEqual(IsolatedHandles.nullHandle())) {
            listener = new IsolatedTruffleCompilerEventForwarder(eventContextHandle);
        }
        delegate.doCompile(null, compilation, options, task, listener);
        // no exception
        return IsolatedHandles.nullHandle();
    } catch (Throwable t) {
        StringWriter writer = new StringWriter();
        t.printStackTrace(new PrintWriter(writer));
        return IsolatedCompileContext.get().createStringInClient(writer.toString());
    } finally {
        /*
             * Compilation isolate do not use a dedicated reference handler thread, so we trigger
             * the reference handling manually when a compilation finishes.
             */
        Heap.getHeap().doReferenceHandling();
        IsolatedCompileContext.set(null);
    }
}
Also used : TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) IsolatedCompileContext(com.oracle.svm.graal.isolated.IsolatedCompileContext) TruffleCompilationTask(org.graalvm.compiler.truffle.common.TruffleCompilationTask) SubstrateTruffleCompiler(com.oracle.svm.truffle.api.SubstrateTruffleCompiler) StringWriter(java.io.StringWriter) PinnedObject(org.graalvm.nativeimage.PinnedObject) TruffleCompilerListener(org.graalvm.compiler.truffle.common.TruffleCompilerListener) PrintWriter(java.io.PrintWriter) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 5 with TruffleCompilation

use of org.graalvm.compiler.truffle.common.TruffleCompilation in project graal by oracle.

the class GraalTruffleRuntime method compileImpl.

@SuppressWarnings("try")
private void compileImpl(TruffleDebugContext initialDebug, OptimizedCallTarget callTarget, TruffleCompilationTask task) {
    boolean compilationStarted = false;
    try {
        TruffleCompiler compiler = getTruffleCompiler(callTarget);
        try (TruffleCompilation compilation = compiler.openCompilation(callTarget)) {
            final Map<String, Object> optionsMap = getOptionsForCompiler(callTarget);
            TruffleDebugContext debug = initialDebug;
            if (debug == null) {
                debug = compiler.openDebugContext(optionsMap, compilation);
            }
            listeners.onCompilationStarted(callTarget, task);
            compilationStarted = true;
            try {
                compiler.doCompile(debug, compilation, optionsMap, task, listeners.isEmpty() ? null : listeners);
            } finally {
                if (initialDebug == null) {
                    debug.close();
                }
            }
            TruffleInlining inlining = (TruffleInlining) task.inliningData();
            truffleDump(callTarget, compiler, compilation, optionsMap, inlining);
            inlining.dequeueTargets();
        }
    } catch (OptimizationFailedException e) {
        // Listeners already notified
        throw e;
    } catch (RuntimeException | Error e) {
        notifyCompilationFailure(callTarget, e, compilationStarted, task.tier());
        throw e;
    } catch (Throwable e) {
        notifyCompilationFailure(callTarget, e, compilationStarted, task.tier());
        throw new InternalError(e);
    }
}
Also used : TruffleCompilation(org.graalvm.compiler.truffle.common.TruffleCompilation) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) ServiceConfigurationError(java.util.ServiceConfigurationError) TruffleCompiler(org.graalvm.compiler.truffle.common.TruffleCompiler) OptimizationFailedException(com.oracle.truffle.api.OptimizationFailedException)

Aggregations

TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)7 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)4 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)4 TruffleCompiler (org.graalvm.compiler.truffle.common.TruffleCompiler)3 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)3 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)3 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)2 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)2 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)2 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 IsolatedCompileContext (com.oracle.svm.graal.isolated.IsolatedCompileContext)1 SubstrateTruffleCompiler (com.oracle.svm.truffle.api.SubstrateTruffleCompiler)1 OptimizationFailedException (com.oracle.truffle.api.OptimizationFailedException)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 CompilableTruffleAST (org.graalvm.compiler.truffle.common.CompilableTruffleAST)1 TruffleCompilationTask (org.graalvm.compiler.truffle.common.TruffleCompilationTask)1 TruffleCompilerListener (org.graalvm.compiler.truffle.common.TruffleCompilerListener)1