Search in sources :

Example 1 with CompilerIsolateThread

use of com.oracle.svm.graal.isolated.CompilerIsolateThread in project graal by oracle.

the class IsolateAwareTruffleCompiler method beforeCompilation.

protected CompilerIsolateThread beforeCompilation() {
    Isolate isolate = getSharedIsolate();
    if (isolate.isNull()) {
        if (sharedIsolate.compareAndSet(WordFactory.nullPointer(), (Isolate) ISOLATE_INITIALIZING)) {
            CompilerIsolateThread thread = IsolatedGraalUtils.createCompilationIsolate();
            Runtime.getRuntime().addShutdownHook(new Thread(this::sharedIsolateShutdown));
            sharedIsolate.set(Isolates.getIsolate(thread));
            // (already attached)
            return thread;
        }
        isolate = getSharedIsolate();
        assert isolate.isNonNull();
    }
    return (CompilerIsolateThread) Isolates.attachCurrentThread(isolate);
}
Also used : CompilerIsolateThread(com.oracle.svm.graal.isolated.CompilerIsolateThread) Isolate(org.graalvm.nativeimage.Isolate) CurrentIsolate(org.graalvm.nativeimage.CurrentIsolate) IsolateThread(org.graalvm.nativeimage.IsolateThread) CompilerIsolateThread(com.oracle.svm.graal.isolated.CompilerIsolateThread) ClientIsolateThread(com.oracle.svm.graal.isolated.ClientIsolateThread)

Example 2 with CompilerIsolateThread

use of com.oracle.svm.graal.isolated.CompilerIsolateThread in project graal by oracle.

the class IsolateAwareTruffleCompiler method doCompile.

@Override
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "False positive.")
public void doCompile(TruffleDebugContext debug, TruffleCompilation compilation, Map<String, Object> options, TruffleCompilationTask task, TruffleCompilerListener listener) {
    if (!SubstrateOptions.shouldCompileInIsolates()) {
        delegate.doCompile(null, compilation, options, task, listener);
        return;
    }
    CompilerIsolateThread context = beforeCompilation();
    try {
        IsolatedCompileClient client = new IsolatedCompileClient(context);
        IsolatedCompileClient.set(client);
        try {
            byte[] encodedOptions = options.isEmpty() ? null : OptionsEncoder.encode(options);
            IsolatedEventContext eventContext = null;
            if (listener != null) {
                eventContext = new IsolatedEventContext(listener, compilation.getCompilable(), task);
            }
            ClientHandle<String> thrownException = doCompile0(context, (ClientIsolateThread) CurrentIsolate.getCurrentThread(), ImageHeapObjects.ref(delegate), client.hand(((TruffleCompilationIdentifier) compilation)), client.hand((SubstrateCompilableTruffleAST) compilation.getCompilable()), client.hand(encodedOptions), IsolatedGraalUtils.getNullableArrayLength(encodedOptions), client.hand(task), client.hand(eventContext), firstCompilation.getAndSet(false));
            String exception = client.unhand(thrownException);
            if (exception != null) {
                throw new RuntimeException("doCompile threw: " + exception);
            }
        } finally {
            IsolatedCompileClient.set(null);
        }
    } finally {
        afterCompilation(context);
    }
}
Also used : IsolatedCompileClient(com.oracle.svm.graal.isolated.IsolatedCompileClient) SubstrateCompilableTruffleAST(com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST) CompilerIsolateThread(com.oracle.svm.graal.isolated.CompilerIsolateThread) SuppressFBWarnings(org.graalvm.compiler.core.common.SuppressFBWarnings)

Example 3 with CompilerIsolateThread

use of com.oracle.svm.graal.isolated.CompilerIsolateThread in project graal by oracle.

the class IsolateAwareTruffleCompiler method sharedIsolateShutdown.

private void sharedIsolateShutdown() {
    Isolate isolate = getSharedIsolate();
    CompilerIsolateThread context = (CompilerIsolateThread) Isolates.attachCurrentThread(isolate);
    compilerIsolateThreadShutdown(context);
    Isolates.detachThread(context);
}
Also used : CompilerIsolateThread(com.oracle.svm.graal.isolated.CompilerIsolateThread) Isolate(org.graalvm.nativeimage.Isolate) CurrentIsolate(org.graalvm.nativeimage.CurrentIsolate)

Aggregations

CompilerIsolateThread (com.oracle.svm.graal.isolated.CompilerIsolateThread)3 CurrentIsolate (org.graalvm.nativeimage.CurrentIsolate)2 Isolate (org.graalvm.nativeimage.Isolate)2 ClientIsolateThread (com.oracle.svm.graal.isolated.ClientIsolateThread)1 IsolatedCompileClient (com.oracle.svm.graal.isolated.IsolatedCompileClient)1 SubstrateCompilableTruffleAST (com.oracle.svm.truffle.api.SubstrateCompilableTruffleAST)1 SuppressFBWarnings (org.graalvm.compiler.core.common.SuppressFBWarnings)1 IsolateThread (org.graalvm.nativeimage.IsolateThread)1