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