Search in sources :

Example 6 with TruffleOptionsOverrideScope

use of org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope 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));
        }
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) TruffleCompilerImpl(org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LogStream(org.graalvm.compiler.debug.LogStream) DebugContext(org.graalvm.compiler.debug.DebugContext) TruffleInliningPlan(org.graalvm.compiler.truffle.common.TruffleInliningPlan) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) DefaultInliningPolicy(org.graalvm.compiler.truffle.runtime.DefaultInliningPolicy) TruffleInlining(org.graalvm.compiler.truffle.runtime.TruffleInlining) TTY(org.graalvm.compiler.debug.TTY) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 7 with TruffleOptionsOverrideScope

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

the class OptimizedCallTargetTest method testCompileOnly4.

@Test
public void testCompileOnly4() {
    // OSR should not trigger for compile-only includes
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
        final OSRRepeatingNode repeating = new OSRRepeatingNode(TruffleCompilerOptions.getValue(TruffleOSRCompilationThreshold));
        final LoopNode loop = runtime.createLoopNode(repeating);
        OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar") {

            @Child
            LoopNode loopChild = loop;

            @Override
            public Object execute(VirtualFrame frame) {
                loopChild.executeLoop(frame);
                return super.execute(frame);
            }
        });
        target.call();
        OptimizedCallTarget osrTarget = findOSRTarget(loop);
        if (osrTarget != null) {
            assertNotCompiled(osrTarget);
        }
    }
}
Also used : LoopNode(com.oracle.truffle.api.nodes.LoopNode) OptimizedOSRLoopNode(org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 8 with TruffleOptionsOverrideScope

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

the class OptimizedCallTargetTest method testCompileOnly1.

@Test
public void testCompileOnly1() {
    final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
    try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foobar")) {
        OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar"));
        for (int i = 0; i < compilationThreshold; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertCompiled(target);
        target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("baz"));
        for (int i = 0; i < compilationThreshold; i++) {
            assertNotCompiled(target);
            target.call();
        }
        assertNotCompiled(target);
    }
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 9 with TruffleOptionsOverrideScope

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

the class TruffleToTruffleCallExceptionHandlerTest method testExceptionOnceCompileExceptionHandler.

@Test
@SuppressWarnings("try")
@Ignore
public void testExceptionOnceCompileExceptionHandler() {
    /*
         * call the function at least once so the exception profile will record an exception and the
         * partial evaluator will compile the exception handler edge
         */
    try {
        calleeWithException.callDirect(new Object());
        Assert.fail();
    } catch (Throwable t) {
        Assert.assertTrue(t instanceof RuntimeException);
    }
    /*
         * We disable truffle AST inlining to not inline the callee
         */
    try (TruffleOptionsOverrideScope o = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleFunctionInlining, false)) {
        StructuredGraph graph = partialEval(callerWithException, new Object[0], AllowAssumptions.YES);
        Assert.assertEquals(1, graph.getNodes().filter(UnwindNode.class).count());
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with TruffleOptionsOverrideScope

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

the class TruffleToTruffleCallExceptionHandlerTest method testNeverSeenExceptionHandlerSkipped.

@Test
@SuppressWarnings("try")
public void testNeverSeenExceptionHandlerSkipped() {
    /*
         * We disable truffle AST inlining to not inline the callee
         */
    try (TruffleOptionsOverrideScope o = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleFunctionInlining, false)) {
        StructuredGraph graph = partialEval(callerNoException, new Object[0], AllowAssumptions.YES);
        Assert.assertEquals(0, graph.getNodes().filter(UnwindNode.class).count());
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) Test(org.junit.Test)

Aggregations

TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)11 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)8 Test (org.junit.Test)8 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)3 LoopNode (com.oracle.truffle.api.nodes.LoopNode)3 OptimizedOSRLoopNode (org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)2 Ignore (org.junit.Ignore)2 Assumption (com.oracle.truffle.api.Assumption)1 CallTarget (com.oracle.truffle.api.CallTarget)1 CompilerDirectives (com.oracle.truffle.api.CompilerDirectives)1 Truffle (com.oracle.truffle.api.Truffle)1 Specialization (com.oracle.truffle.api.dsl.Specialization)1 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)1 Node (com.oracle.truffle.api.nodes.Node)1 RepeatingNode (com.oracle.truffle.api.nodes.RepeatingNode)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1