use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.
the class ParserDriver method verifyBitcodeSource.
private void verifyBitcodeSource(Source source, DataLayout targetDataLayout, TargetTriple targetTriple) {
if (targetDataLayout.getByteOrder() != ByteOrder.LITTLE_ENDIAN) {
throw new LLVMParserException("Byte order " + targetDataLayout.getByteOrder() + " of file " + source.getPath() + " is not supported");
}
boolean verifyBitcode = context.getEnv().getOptions().get(SulongEngineOption.VERIFY_BITCODE);
TargetTriple defaultTargetTriple = language.getDefaultTargetTriple();
if (defaultTargetTriple == null && !context.isInternalLibraryPath(Paths.get(source.getPath()))) {
// some internal libraries (libsulong++) might be loaded before libsulong
throw new IllegalStateException("No default target triple.");
}
if (defaultTargetTriple != null && targetTriple != null && !defaultTargetTriple.matches(targetTriple)) {
TruffleLogger logger = TruffleLogger.getLogger(LLVMLanguage.ID, "BitcodeVerifier");
String exceptionMessage = "Mismatching target triple (expected " + defaultTargetTriple + ", got " + targetTriple + ')';
logger.severe(exceptionMessage);
logger.severe("Source " + source.getPath());
logger.severe("See https://www.graalvm.org/reference-manual/llvm/Compiling/ for more details");
logger.severe("To silence this message, set --log." + logger.getName() + ".level=OFF");
if (verifyBitcode) {
logger.severe("To make this error non-fatal, set --" + SulongEngineOption.VERIFY_BITCODE_NAME + "=false");
throw new LLVMParserException(exceptionMessage);
}
}
}
use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.
the class ProbeNode method exceptionEventForClientInstrument.
/**
* Previously, by default, all instruments did log their exceptions. They now by default throw,
* but we still want to respect if engine.InstrumentExceptionsAreThrown is explicitly set to
* false. This can be a workaround if an instrument fails but the execution should continue.
*/
@TruffleBoundary
static void exceptionEventForClientInstrument(EventBinding.Source<?> b, String eventName, Throwable t) {
if (t instanceof ThreadDeath) {
// Terminates guest language execution immediately
throw (ThreadDeath) t;
}
// we only want to ever log for probes of instruments
if (!(b.getInstrumenter() instanceof InstrumentClientInstrumenter)) {
throw sthrow(RuntimeException.class, t);
}
InstrumentClientInstrumenter instrumenter = (InstrumentClientInstrumenter) b.getInstrumenter();
Object probeInstrument = instrumenter.getEnv().getPolyglotInstrument();
if (InstrumentAccessor.engineAccess().isInstrumentExceptionsAreThrown(probeInstrument)) {
throw sthrow(RuntimeException.class, t);
}
// fetch default logger for instrument of the current probe
TruffleLogger logger = InstrumentAccessor.engineAccess().getLogger(probeInstrument, null);
String message = //
String.format(//
"Event %s failed for instrument class %s and listener/factory %s.", eventName, instrumenter.getInstrumentClassName(), b.getElement());
logger.log(Level.SEVERE, message, t);
}
use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.
the class ContextPreInitializationTest method getEngineLogger.
private static TruffleLogger getEngineLogger(Object engine) {
try {
Class<?> clz = Class.forName("com.oracle.truffle.polyglot.PolyglotEngineImpl");
Method m = clz.getDeclaredMethod("getEngineLogger");
m.setAccessible(true);
return (TruffleLogger) m.invoke(engine);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.
the class LoggingTest method testInnerContextLogging.
@Test
public void testInnerContextLogging() {
AbstractLoggingLanguage.action = new BiPredicate<>() {
@Override
public boolean test(final LoggingContext context, final TruffleLogger[] loggers) {
TruffleContext tc = context.getEnv().newContextBuilder().build();
final Object prev = tc.enter(null);
try {
for (TruffleLogger logger : loggers) {
logger.log(Level.FINEST, "INNER: " + logger.getName());
}
} finally {
tc.leave(null, prev);
tc.close();
}
return true;
}
};
TestHandler handler = new TestHandler();
try (Context ctx = newContextBuilder().options(createLoggingOptions(LoggingLanguageFirst.ID, null, Level.FINEST.toString())).logHandler(handler).build()) {
ctx.eval(LoggingLanguageFirst.ID, "");
List<Map.Entry<Level, String>> expected = new ArrayList<>();
for (String loggerName : AbstractLoggingLanguage.LOGGER_NAMES) {
expected.add(new AbstractMap.SimpleImmutableEntry<>(Level.FINEST, "INNER: " + LoggingLanguageFirst.ID + '.' + loggerName));
}
expected.addAll(createExpectedLog(LoggingLanguageFirst.ID, Level.FINEST, Collections.emptyMap()));
Assert.assertEquals(expected, handler.getLog());
}
}
use of com.oracle.truffle.api.TruffleLogger in project graal by oracle.
the class LoggingTest method testEngineLoggerIdentity.
@Test
public void testEngineLoggerIdentity() {
ProxyInstrument delegate = new ProxyInstrument();
AtomicReferenceArray<TruffleLogger> eng1Loggers = new AtomicReferenceArray<>(2);
delegate.setOnCreate(new Consumer<TruffleInstrument.Env>() {
@Override
public void accept(TruffleInstrument.Env env) {
TruffleLogger logger1 = env.getLogger("a.b.c");
TruffleLogger logger2 = env.getLogger("a.b");
Assert.assertNotSame(logger1, logger2);
Assert.assertSame(logger1, env.getLogger("a.b.c"));
Assert.assertSame(logger2, env.getLogger("a.b"));
Assert.assertNotSame(logger1, TruffleLogger.getLogger(ProxyInstrument.ID, "a.b.c"));
Assert.assertNotSame(logger2, TruffleLogger.getLogger(ProxyInstrument.ID, "a.b"));
eng1Loggers.set(0, logger1);
eng1Loggers.set(1, logger2);
}
});
ProxyInstrument.setDelegate(delegate);
try (Engine eng = Engine.create()) {
LoggingLanguageFirst.action = new LookupInstrumentAction(false);
try (Context ctx = newContextBuilder().engine(eng).build()) {
ctx.eval(LoggingLanguageFirst.ID, "");
}
}
delegate = new ProxyInstrument();
delegate.setOnCreate(new Consumer<TruffleInstrument.Env>() {
@Override
public void accept(TruffleInstrument.Env env) {
TruffleLogger logger1 = env.getLogger("a.b.c");
TruffleLogger logger2 = env.getLogger("a.b");
Assert.assertNotSame(logger1, logger2);
Assert.assertNotSame(eng1Loggers.get(0), logger1);
Assert.assertNotSame(eng1Loggers.get(1), logger2);
}
});
ProxyInstrument.setDelegate(delegate);
try (Engine eng = Engine.create()) {
LoggingLanguageFirst.action = new LookupInstrumentAction(false);
try (Context ctx = newContextBuilder().engine(eng).build()) {
ctx.eval(LoggingLanguageFirst.ID, "");
}
}
}
Aggregations