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