Search in sources :

Example 1 with TruffleCompilerListener

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

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

the class TruffleToLibGraalEntryPoints method doCompile.

@TruffleToLibGraal(DoCompile)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_doCompile")
public static void doCompile(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, long debugContextHandle, long compilationHandle, JByteArray hsOptions, JObject hsTask, JObject hsListener) {
    try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, DoCompile, env)) {
        TruffleCompilationIdentifier compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilationIdentifier.class);
        try (CompilationContext hotSpotObjectConstantScope = HotSpotGraalServices.openLocalCompilationContext(compilation)) {
            HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class);
            TruffleDebugContext debugContext = LibGraalObjectHandles.resolve(debugContextHandle, TruffleDebugContext.class);
            Map<String, Object> options = decodeOptions(env, hsOptions);
            TruffleCompilationTask task = hsTask.isNull() ? null : new HSTruffleCompilationTask(hsTask);
            TruffleCompilerListener listener = hsListener.isNull() ? null : new HSTruffleCompilerListener(scope, hsListener);
            compiler.doCompile(debugContext, compilation, options, task, listener);
        }
    } catch (Throwable t) {
        JNIExceptionWrapper.throwInHotSpot(env, t);
    }
}
Also used : TruffleCompilationIdentifier(org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier) JNIMethodScope(org.graalvm.jniutils.JNIMethodScope) TruffleDebugContext(org.graalvm.compiler.truffle.common.TruffleDebugContext) 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) TruffleCompilationTask(org.graalvm.compiler.truffle.common.TruffleCompilationTask) HotSpotTruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl) CompilationContext(org.graalvm.compiler.hotspot.CompilationContext) HSObject(org.graalvm.jniutils.HSObject) JObject(org.graalvm.jniutils.JNI.JObject) TruffleCompilerListener(org.graalvm.compiler.truffle.common.TruffleCompilerListener) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) TruffleToLibGraal(org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)

Aggregations

TruffleCompilationTask (org.graalvm.compiler.truffle.common.TruffleCompilationTask)2 TruffleCompilerListener (org.graalvm.compiler.truffle.common.TruffleCompilerListener)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)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 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 CompilationContext (org.graalvm.compiler.hotspot.CompilationContext)1 TruffleCompilation (org.graalvm.compiler.truffle.common.TruffleCompilation)1 TruffleDebugContext (org.graalvm.compiler.truffle.common.TruffleDebugContext)1 TruffleToLibGraal (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal)1 GetSuppliedString (org.graalvm.compiler.truffle.common.hotspot.libgraal.TruffleToLibGraal.Id.GetSuppliedString)1 TruffleCompilationIdentifier (org.graalvm.compiler.truffle.compiler.TruffleCompilationIdentifier)1 HotSpotTruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.hotspot.HotSpotTruffleCompilerImpl)1 HSObject (org.graalvm.jniutils.HSObject)1 JObject (org.graalvm.jniutils.JNI.JObject)1 JString (org.graalvm.jniutils.JNI.JString)1 JNIMethodScope (org.graalvm.jniutils.JNIMethodScope)1 JNIUtil.createHSString (org.graalvm.jniutils.JNIUtil.createHSString)1