Search in sources :

Example 1 with TruffleDebugContext

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

the class TruffleToLibGraalEntryPoints method closeDebugContext.

@TruffleToLibGraal(CloseDebugContext)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_closeDebugContext")
@SuppressWarnings({ "unused", "try" })
public static void closeDebugContext(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle) {
    try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, CloseDebugContext, env)) {
        TruffleDebugContext debugContext = LibGraalObjectHandles.resolve(handle, TruffleDebugContext.class);
        debugContext.close();
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
    }
}
Also used : JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 2 with TruffleDebugContext

use of org.graalvm.compiler.truffle.common.TruffleDebugContext 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 3 with TruffleDebugContext

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

the class TruffleToLibGraalEntryPoints method openDebugContextScope.

@TruffleToLibGraal(OpenDebugContextScope)
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_openDebugContextScope")
@SuppressWarnings({ "unused", "try" })
public static long openDebugContextScope(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long handle, JString hsName, long compilationHandle) {
    try (JNIMethodScope s = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, OpenDebugContextScope, env)) {
        TruffleDebugContext debugContext = LibGraalObjectHandles.resolve(handle, TruffleDebugContext.class);
        String name = createString(env, hsName);
        AutoCloseable scope;
        if (compilationHandle == 0) {
            scope = debugContext.scope(name);
        } else {
            TruffleCompilationIdentifier compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilationIdentifier.class);
            scope = debugContext.scope(name, new TruffleDebugJavaMethod(compilation.getCompilable()));
        }
        if (scope == null) {
            return 0;
        }
        long scopeHandle = LibGraalObjectHandles.create(scope);
        return scopeHandle;
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
        return 0;
    }
}
Also used : TruffleCompilationIdentifier(org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) TruffleDebugJavaMethod(org.graalvm.compiler.truffle.common.TruffleDebugJavaMethod) JNIUtil.createString(org.graalvm.jniutils.JNIUtil.createString) JString(org.graalvm.jniutils.JNI.JString) GetSuppliedString(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString) JNIUtil.createHSString(org.graalvm.jniutils.JNIUtil.createHSString) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Example 4 with TruffleDebugContext

use of org.graalvm.compiler.truffle.common.TruffleDebugContext 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 5 with TruffleDebugContext

use of org.graalvm.compiler.truffle.common.TruffleDebugContext 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

TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)10 TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)4 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)4 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)4 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)4 TruffleCompiler (org.graalvm.compiler.truffle.common.TruffleCompiler)3 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)3 JString (org.graalvm.jniutils.JNI.JString)3 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)3 JNIUtil.createString (org.graalvm.jniutils.JNIUtil.createString)3 DebugContext (org.graalvm.compiler.debug.DebugContext)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 CompilableTruffleAST (org.graalvm.compiler.truffle.common.CompilableTruffleAST)2 TruffleCompilationIdentifier (org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier)2 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 HSObject (org.graalvm.jniutils.HSObject)2 JObject (org.graalvm.jniutils.JNI.JObject)2 OptimizationFailedException (com.oracle.truffle.api.OptimizationFailedException)1