Search in sources :

Example 11 with TruffleLogger

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);
        }
    }
}
Also used : TruffleLogger(com.oracle.truffle.api.TruffleLogger) TargetTriple(com.oracle.truffle.llvm.runtime.target.TargetTriple) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 12 with TruffleLogger

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);
}
Also used : TruffleLogger(com.oracle.truffle.api.TruffleLogger) InstrumentClientInstrumenter(com.oracle.truffle.api.instrumentation.InstrumentationHandler.InstrumentClientInstrumenter) TruffleString(com.oracle.truffle.api.strings.TruffleString) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 13 with TruffleLogger

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);
    }
}
Also used : TruffleLogger(com.oracle.truffle.api.TruffleLogger) Method(java.lang.reflect.Method)

Example 14 with TruffleLogger

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());
    }
}
Also used : TruffleContext(com.oracle.truffle.api.TruffleContext) Context(org.graalvm.polyglot.Context) TruffleContext(com.oracle.truffle.api.TruffleContext) ArrayList(java.util.ArrayList) AbstractMap(java.util.AbstractMap) TruffleLogger(com.oracle.truffle.api.TruffleLogger) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 15 with TruffleLogger

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, "");
        }
    }
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) TruffleContext(com.oracle.truffle.api.TruffleContext) Context(org.graalvm.polyglot.Context) TruffleLogger(com.oracle.truffle.api.TruffleLogger) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) Engine(org.graalvm.polyglot.Engine) Test(org.junit.Test)

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