Search in sources :

Example 6 with TruffleLogger

use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.

the class LoggingTest method testParametersPrimitive.

@Test
public void testParametersPrimitive() {
    final Object[] expected = new Object[] { 1, 1L, null, 1.1, 1.1d, "test", 't', null, true };
    AbstractLoggingLanguage.action = new BiPredicate<>() {

        @Override
        public boolean test(final LoggingContext context, final TruffleLogger[] loggers) {
            for (TruffleLogger logger : loggers) {
                logger.log(Level.WARNING, "Parameters", Arrays.copyOf(expected, expected.length));
            }
            return false;
        }
    };
    final TestHandler handler1 = new TestHandler();
    try (Context ctx1 = newContextBuilder().logHandler(handler1).build()) {
        ctx1.eval(LoggingLanguageFirst.ID, "");
        boolean logged = false;
        for (LogRecord r : handler1.getRawLog()) {
            logged = true;
            Assert.assertEquals("Parameters", r.getMessage());
            Assert.assertArrayEquals(expected, r.getParameters());
        }
        Assert.assertTrue(logged);
    }
}
Also used : TruffleContext(com.oracle.truffle.api.TruffleContext) Context(org.graalvm.polyglot.Context) LogRecord(java.util.logging.LogRecord) TruffleLogger(com.oracle.truffle.api.TruffleLogger) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 7 with TruffleLogger

use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.

the class LoggingTest method testContextBoundLoggerSingleContext.

@Test
public void testContextBoundLoggerSingleContext() {
    TestHandler handler = new TestHandler();
    LoggingLanguageFirst.action = (ctx, loggers) -> {
        for (Level level : AbstractLoggingLanguage.LOGGER_LEVELS) {
            for (String loggerName : AbstractLoggingLanguage.LOGGER_NAMES) {
                TruffleLogger logger = ctx.env.getLogger(loggerName);
                logger.log(level, logger.getName());
            }
        }
        return false;
    };
    try (Context ctx = newContextBuilder().options(createLoggingOptions(null, null, Level.FINEST.toString())).logHandler(handler).build()) {
        ctx.eval(LoggingLanguageFirst.ID, "");
        Assert.assertEquals(createExpectedLog(LoggingLanguageFirst.ID, Level.FINEST, Collections.emptyMap()), handler.getLog());
    }
}
Also used : TruffleContext(com.oracle.truffle.api.TruffleContext) Context(org.graalvm.polyglot.Context) TruffleLogger(com.oracle.truffle.api.TruffleLogger) Level(java.util.logging.Level) Test(org.junit.Test)

Example 8 with TruffleLogger

use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.

the class SourceUtils method updateCoverageData.

private static void updateCoverageData(TextDocumentSurrogate surrogate, Source source, String newText, Range range, int replaceBegin, int replaceEnd, TruffleLogger logger) {
    Source newSourceSnippet = Source.newBuilder("dummyLanguage", newText, "dummyCoverage").cached(false).build();
    int linesNewText = newSourceSnippet.getLineCount() + (newText.endsWith("\n") ? 1 : 0) + (newText.isEmpty() ? 1 : 0);
    Source oldSourceSnippet = source.subSource(replaceBegin, replaceEnd - replaceBegin);
    int liensOldText = oldSourceSnippet.getLineCount() + (oldSourceSnippet.getCharacters().toString().endsWith("\n") ? 1 : 0) + (oldSourceSnippet.getLength() == 0 ? 1 : 0);
    int newLineModification = linesNewText - liensOldText;
    logger.log(Level.FINEST, "newLineModification: {0}", newLineModification);
    if (newLineModification != 0) {
        List<SourceSectionReference> sections = surrogate.getCoverageLocations();
        sections.stream().filter(section -> section.includes(range)).forEach(section -> {
            SourceSectionReference migratedSection = new SourceSectionReference(section);
            migratedSection.setEndLine(migratedSection.getEndLine() + newLineModification);
            surrogate.replace(section, migratedSection);
            logger.log(Level.FINEST, "Included - Old: {0} Fixed: {1}", new Object[] { section, migratedSection });
        });
        sections.stream().filter(section -> section.behind(range)).forEach(section -> {
            SourceSectionReference migratedSection = new SourceSectionReference(section);
            migratedSection.setStartLine(migratedSection.getStartLine() + newLineModification);
            migratedSection.setEndLine(migratedSection.getEndLine() + newLineModification);
            surrogate.replace(section, migratedSection);
            logger.log(Level.FINEST, "Behind   - Old: {0} Fixed: {1}", new Object[] { section, migratedSection });
        });
    }
}
Also used : Arrays(java.util.Arrays) Position(org.graalvm.tools.lsp.server.types.Position) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) TextDocumentContentChangeEvent(org.graalvm.tools.lsp.server.types.TextDocumentContentChangeEvent) TruffleLogger(com.oracle.truffle.api.TruffleLogger) Level(java.util.logging.Level) Range(org.graalvm.tools.lsp.server.types.Range) OptionValues(org.graalvm.options.OptionValues) List(java.util.List) Source(com.oracle.truffle.api.source.Source) CompilerDirectives(com.oracle.truffle.api.CompilerDirectives) Paths(java.nio.file.Paths) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) SourcePredicate(com.oracle.truffle.api.instrumentation.SourceSectionFilter.SourcePredicate) SourceSection(com.oracle.truffle.api.source.SourceSection) URI(java.net.URI) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) Path(java.nio.file.Path) Source(com.oracle.truffle.api.source.Source)

Example 9 with TruffleLogger

use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.

the class OptimizedAssumption method invalidateImpl.

@TruffleBoundary
private synchronized void invalidateImpl(String message) {
    /*
         * Check again, now that we are holding the lock. Since isValid is defined volatile,
         * double-checked locking is allowed.
         */
    if (!isValid) {
        return;
    }
    OptionValues engineOptions = null;
    TruffleLogger logger = null;
    boolean logStackTrace = false;
    Entry e = dependencies;
    CharSequence reason = null;
    while (e != null) {
        OptimizedAssumptionDependency dependency = e.awaitDependency();
        if (dependency != null) {
            if (reason == null) {
                String useName = name != null ? name : "";
                String useMessage = message != null ? message : "";
                if (useName.isEmpty() && useMessage.isEmpty()) {
                    reason = "assumption invalidated";
                } else if (useName.isEmpty()) {
                    reason = useMessage;
                } else if (useMessage.isEmpty()) {
                    reason = useName;
                } else {
                    reason = new LazyReason(useName, useMessage);
                }
            }
            dependency.onAssumptionInvalidated(this, reason);
            if (engineOptions == null) {
                OptimizedCallTarget callTarget = (OptimizedCallTarget) dependency.getCompilable();
                if (callTarget != null) {
                    engineOptions = callTarget.getOptionValues();
                    logger = callTarget.engine.getEngineLogger();
                } else {
                    EngineData engineData = GraalTVMCI.getEngineData(null);
                    engineOptions = engineData.engineOptions;
                    logger = engineData.getEngineLogger();
                }
            }
            if (engineOptions.get(PolyglotCompilerOptions.TraceAssumptions)) {
                logStackTrace = true;
                logInvalidatedDependency(dependency, message, logger);
            }
        }
        e = e.next;
    }
    dependencies = null;
    size = 0;
    sizeAfterLastRemove = 0;
    isValid = false;
    if (logStackTrace) {
        logStackTrace(engineOptions, logger);
    }
}
Also used : OptionValues(org.graalvm.options.OptionValues) TruffleLogger(com.oracle.truffle.api.TruffleLogger) FormatWithToString(jdk.vm.ci.meta.JavaKind.FormatWithToString) OptimizedAssumptionDependency(org.graalvm.compiler.truffle.common.OptimizedAssumptionDependency) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 10 with TruffleLogger

use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.

the class StatisticsListener method printStatistics.

private void printStatistics(EngineData runtimeData) {
    GraalTruffleRuntime rt = runtime;
    long endTime = System.nanoTime();
    StringWriter logMessage = new StringWriter();
    try (PrintWriter out = new PrintWriter(logMessage)) {
        out.print("Truffle runtime statistics for engine " + runtimeData.id);
        printStatistic(out, "Compilations", compilations);
        printStatistic(out, "  Success", success);
        printStatistic(out, "  Temporary Bailouts", temporaryBailouts);
        temporaryBailoutReasons.printStatistics(out, String::toString, true, false);
        printStatistic(out, "  Permanent Bailouts", permanentBailouts);
        permanentBailoutReasons.printStatistics(out, String::toString, true, false);
        printStatistic(out, "  Failed", failures);
        failureReasons.printStatistics(out, String::toString, true, false);
        printStatistic(out, "  Interrupted", compilations - (success + failures + temporaryBailouts + permanentBailouts));
        printStatistic(out, "Invalidated", invalidations);
        invalidatedReasons.printStatistics(out, String::toString, true, false);
        printStatistic(out, "Queues", queues);
        printStatistic(out, "Dequeues", dequeues);
        dequeuedReasons.printStatistics(out, String::toString, true, false);
        printStatistic(out, "Splits", splits);
        printStatistic(out, "Compilation Accuracy", 1.0 - invalidations / (double) compilations);
        printStatistic(out, "Queue Accuracy", 1.0 - dequeues / (double) queues);
        printStatistic(out, "Compilation Utilization", compilationTime.getSum() / (double) (endTime - firstCompilation));
        printStatistic(out, "Remaining Compilation Queue", rt.getCompilationQueueSize());
        printStatisticTime(out, "Time to queue", timeToQueue);
        printStatisticTime(out, "Time waiting in queue", timeInQueue);
        printStatisticTime(out, "Time for compilation", compilationTime);
        printStatisticTime(out, "  Truffle Tier", compilationTimeTruffleTier);
        printStatisticTime(out, "  Graal Tier", compilationTimeGraalTier);
        printStatisticTime(out, "  Code Installation", compilationTimeCodeInstallation);
        // GR-25014 Truffle node count statistics are broken with language agnostic inlining
        printStatistic(out, "Truffle node count", nodeCount);
        printStatistic(out, "  Trivial", nodeCountTrivial);
        printStatistic(out, "  Non Trivial", nodeCountNonTrivial);
        printStatistic(out, "    Monomorphic", nodeCountMonomorphic);
        printStatistic(out, "    Polymorphic", nodeCountPolymorphic);
        printStatistic(out, "    Megamorphic", nodeCountMegamorphic);
        printStatistic(out, "Truffle call count", callCount);
        printStatistic(out, "  Indirect", callCountIndirect);
        printStatistic(out, "  Direct", callCountDirect);
        printStatistic(out, "    Dispatched", callCountDirectDispatched);
        printStatistic(out, "    Inlined", callCountDirectInlined);
        printStatistic(out, "    ----------");
        printStatistic(out, "    Cloned", callCountDirectCloned);
        printStatistic(out, "    Not Cloned", callCountDirectNotCloned);
        printStatistic(out, "Truffle loops", loopCount);
        printStatistic(out, "Graal node count");
        printStatistic(out, "  After Truffle Tier", truffleTierNodeCount);
        printStatistic(out, "  After Graal Tier", graalTierNodeCount);
        printStatistic(out, "Graal compilation result");
        printStatistic(out, "  Code size", compilationResultCodeSize);
        printStatistic(out, "  Total frame size", compilationResultTotalFrameSize);
        printStatistic(out, "  Exception handlers", compilationResultExceptionHandlers);
        printStatistic(out, "  Infopoints", compilationResultInfopoints);
        compilationResultInfopointStatistics.printStatistics(out, Function.identity(), false, true);
        printStatistic(out, "  Marks", compilationResultMarks);
        printStatistic(out, "  Data references", compilationResultDataPatches);
        if (runtimeData.callTargetStatisticDetails) {
            printStatistic(out, "Truffle nodes");
            nodeStatistics.printStatistics(out, Class::getSimpleName, false, true);
            printStatistic(out, "Graal nodes after Truffle tier");
            truffleTierNodeStatistics.printStatistics(out, Function.identity(), false, true);
            printStatistic(out, "Graal nodes after Graal tier");
            graalTierNodeStatistics.printStatistics(out, Function.identity(), false, true);
        }
    }
    TruffleLogger logger = runtimeData.getEngineLogger();
    logger.log(Level.INFO, logMessage.toString());
}
Also used : StringWriter(java.io.StringWriter) GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) TruffleLogger(com.oracle.truffle.api.TruffleLogger) PrintWriter(java.io.PrintWriter)

Aggregations

TruffleLogger (com.oracle.truffle.api.TruffleLogger)23 TruffleContext (com.oracle.truffle.api.TruffleContext)16 Context (org.graalvm.polyglot.Context)16 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)4 Level (java.util.logging.Level)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 LogRecord (java.util.logging.LogRecord)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)2 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 PrintStream (java.io.PrintStream)2 AbstractMap (java.util.AbstractMap)2 OptionValues (org.graalvm.options.OptionValues)2 Engine (org.graalvm.polyglot.Engine)2 Value (org.graalvm.polyglot.Value)2 CompilerDirectives (com.oracle.truffle.api.CompilerDirectives)1 InstrumentClientInstrumenter (com.oracle.truffle.api.instrumentation.InstrumentationHandler.InstrumentClientInstrumenter)1