use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class PerformanceWarningTest method testHelper.
@SuppressWarnings("try")
private static void testHelper(RootNode rootNode, boolean expectException, String... outputStrings) {
GraalTruffleRuntime runtime = GraalTruffleRuntime.getRuntime();
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
// Compile and capture output to TTY.
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
boolean seenException = false;
try (TTY.Filter filter = new TTY.Filter(new LogStream(outContent))) {
try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TraceTrufflePerformanceWarnings, Boolean.TRUE);
TruffleOptionsOverrideScope scope2 = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TrufflePerformanceWarningsAreFatal, Boolean.TRUE)) {
OptionValues options = TruffleCompilerOptions.getOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
try (DebugCloseable d = debug.disableIntercept();
DebugContext.Scope s = debug.scope("PerformanceWarningTest")) {
final OptimizedCallTarget compilable = target;
TruffleCompilerImpl compiler = (TruffleCompilerImpl) runtime.newTruffleCompiler();
CompilationIdentifier compilationId = compiler.getCompilationIdentifier(compilable);
TruffleInliningPlan inliningPlan = new TruffleInlining(compilable, new DefaultInliningPolicy());
compiler.compileAST(debug, compilable, inliningPlan, compilationId, null, null);
}
} catch (AssertionError e) {
seenException = true;
if (!expectException) {
throw new AssertionError("Unexpected exception caught", e);
}
}
}
if (expectException && !seenException) {
Assert.assertTrue("Expected exception not caught.", false);
}
// Check output on TTY.
String output = outContent.toString();
if (outputStrings == EMPTY_PERF_WARNINGS) {
Assert.assertEquals("", output);
} else {
for (String s : outputStrings) {
Assert.assertTrue(String.format("Root node class %s: \"%s\" not found in output \"%s\"", rootNode.getClass(), s, output), output.contains(s));
}
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class SafepointRethrowDeoptPETest method testInner.
private void testInner(RootNode rootNode) {
// executed 3 times
terminate = 1;
OptimizedCallTarget compiledMethod = compileHelper(rootNode.toString(), rootNode, new Object[0]);
terminate = 0;
entered = 0;
CountDownLatch cdl = new CountDownLatch(1);
Thread t1 = new Thread(() -> {
try {
cdl.await();
while (entered == 0) {
/* spin */
}
/* Thread.sleep(100); */
compiledMethod.invalidate(cdl, "timed out");
} catch (InterruptedException e) {
Assert.fail("interrupted");
}
terminate = 1;
});
Thread t2 = new Thread(() -> {
cdl.countDown();
Object result = compiledMethod.call();
Assert.assertEquals(RETURN_VALUE, result);
});
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
Assert.fail("interrupted");
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class SimplePartialEvaluationTest method inliningNullCheck2.
@Test
public void inliningNullCheck2() {
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new InliningNullCheckNode2();
RootNode rootNode = new RootTestNode(fd, "inliningNullCheck2", result);
OptimizedCallTarget compilable = compileHelper("inliningNullCheck2", rootNode, new Object[0]);
Assert.assertEquals(42, compilable.call(new Object[0]));
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class SimplePartialEvaluationTest method inliningNullCheck1.
@Test
public void inliningNullCheck1() {
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new InliningNullCheckNode1();
RootNode rootNode = new RootTestNode(fd, "inliningNullCheck1", result);
OptimizedCallTarget compilable = compileHelper("inliningNullCheck1", rootNode, new Object[0]);
Assert.assertEquals(42, compilable.call(new Object[0]));
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class SimplePartialEvaluationTest method intrinsicStatic.
@Test
public void intrinsicStatic() {
/*
* The intrinsic for String.equals() is inlined early during bytecode parsing, because we
* call equals() on a value that has the static type String.
*/
FrameDescriptor fd = new FrameDescriptor();
AbstractTestNode result = new StringEqualsNode("abc", "abf");
RootNode rootNode = new RootTestNode(fd, "intrinsicStatic", result);
OptimizedCallTarget compilable = compileHelper("intrinsicStatic", rootNode, new Object[0]);
Assert.assertEquals(42, compilable.call(new Object[0]));
}
Aggregations