Search in sources :

Example 1 with TTY

use of org.graalvm.compiler.debug.TTY 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)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 LogStream (org.graalvm.compiler.debug.LogStream)1 TTY (org.graalvm.compiler.debug.TTY)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)1 TruffleInliningPlan (org.graalvm.compiler.truffle.common.TruffleInliningPlan)1 TruffleCompilerImpl (org.graalvm.compiler.truffle.compiler.TruffleCompilerImpl)1 DefaultInliningPolicy (org.graalvm.compiler.truffle.runtime.DefaultInliningPolicy)1 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)1 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)1 TruffleInlining (org.graalvm.compiler.truffle.runtime.TruffleInlining)1