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);
}
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);
}
}
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);
}
Aggregations