Search in sources :

Example 6 with LanguageInfo

use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.

the class DebugALot method logValue.

private void logValue(String prefix, DebugValue v) {
    LanguageInfo language = v.getOriginalLanguage();
    if (language != null) {
        logger.print(prefix);
        logger.print("From: ");
        logger.println(language.getId());
    }
    DebugValue metaObject = v.getMetaObject();
    if (metaObject != null) {
        logger.print(prefix);
        logger.print("Type: ");
        logger.println(metaObject.as(String.class));
    }
    SourceSection sourceLocation = v.getSourceLocation();
    if (sourceLocation != null) {
        logger.print(prefix);
        logger.print("SourceSection: ");
        logSourceSection(sourceLocation);
    }
    if (v.isArray()) {
        List<DebugValue> array = v.getArray();
        int length = array.size();
        logger.print(prefix);
        logger.print("Array of length: ");
        logger.println(Integer.toString(length));
        for (int i = 0; i < length && i < 10; i++) {
            logger.print(prefix);
            logger.print("  element #");
            logger.print(Integer.toString(i));
            logger.print(" : ");
            logger.println(array.get(i).as(String.class));
        }
    }
    Collection<DebugValue> properties = v.getProperties();
    logger.print(prefix);
    if (properties == null || properties.isEmpty()) {
        logger.println("Properties: none");
    } else {
        logger.print("Properties: ");
        logger.println(Integer.toString(properties.size()));
    }
    logger.print(prefix);
    logger.print("Internal: ");
    logger.println(v.isInternal());
    logger.print(prefix);
    logger.print("Readable: ");
    logger.println(v.isReadable());
    logger.print(prefix);
    logger.print("Writable: ");
    logger.println(v.isWritable());
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) DebugValue(com.oracle.truffle.api.debug.DebugValue) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 7 with LanguageInfo

use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.

the class InstrumentationTest method testAccessInstrumentFromLanguage.

@Test
public void testAccessInstrumentFromLanguage() {
    ReturnLanguageEnv envReturner = new ReturnLanguageEnv();
    InstrumentationTestLanguage.envConfig.put(ReturnLanguageEnv.KEY, envReturner);
    context.eval(Source.create(InstrumentationTestLanguage.ID, ""));
    assertNotNull(envReturner.env);
    TruffleLanguage.Env env = envReturner.env;
    LanguageInfo langInfo = env.getLanguages().get(InstrumentationTestLanguage.ID);
    assertNotNull(langInfo);
    assertTrue(langInfo.getMimeTypes().contains(InstrumentationTestLanguage.MIME_TYPE));
    assertEquals("InstrumentTestLang", langInfo.getName());
    assertEquals("2.0", langInfo.getVersion());
    InstrumentInfo instrInfo = env.getInstruments().get("testAccessInstruments");
    assertNotNull(instrInfo);
    assertEquals("testAccessInstruments", instrInfo.getId());
    assertEquals("name", instrInfo.getName());
    assertEquals("version", instrInfo.getVersion());
    assertNotNull(env.lookup(instrInfo, TestAccessInstruments.class));
    assertNull(env.lookup(instrInfo, SpecialService.class));
    try {
        // cannot load services from current languages to avoid cycles.
        env.lookup(langInfo, SpecialService.class);
        fail();
    } catch (Exception e1) {
    // expected
    }
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) PolyglotException(org.graalvm.polyglot.PolyglotException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with LanguageInfo

use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.

the class InstrumentationTest method testAccessLanguages.

@Test
public void testAccessLanguages() {
    Instrument instrument = engine.getInstruments().get("testAccessInstruments");
    TestAccessInstruments access = instrument.lookup(TestAccessInstruments.class);
    LanguageInfo info = access.env.getLanguages().get(InstrumentationTestLanguage.ID);
    assertNotNull(info);
    assertTrue(info.getMimeTypes().contains(InstrumentationTestLanguage.MIME_TYPE));
    assertEquals("InstrumentTestLang", info.getName());
    assertEquals("2.0", info.getVersion());
    assertNotNull(access.env.lookup(info, SpecialService.class));
    assertEquals(InstrumentationTestLanguage.FILENAME_EXTENSION, access.env.lookup(info, SpecialService.class).fileExtension());
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Test(org.junit.Test)

Example 9 with LanguageInfo

use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.

the class SourceSectionFilterTest method createRootNode.

static RootNode createRootNode(Engine engine, final SourceSection section, final Boolean internal, Node... children) throws Exception {
    Language language = engine.getLanguages().get(InstrumentationTestLanguage.ID);
    Field impl = Language.class.getDeclaredField("impl");
    ReflectionUtils.setAccessible(impl, true);
    Object polyglotLanguage = impl.get(language);
    Method ensureInitialized = polyglotLanguage.getClass().getDeclaredMethod("ensureInitialized");
    ReflectionUtils.setAccessible(ensureInitialized, true);
    ensureInitialized.invoke(polyglotLanguage);
    Field info = polyglotLanguage.getClass().getDeclaredField("info");
    ReflectionUtils.setAccessible(info, true);
    LanguageInfo languageInfo = (LanguageInfo) info.get(polyglotLanguage);
    Field spi = LanguageInfo.class.getDeclaredField("spi");
    ReflectionUtils.setAccessible(spi, true);
    TruffleLanguage<?> truffleLanguage = (TruffleLanguage<?>) spi.get(languageInfo);
    return new RootNode(truffleLanguage) {

        @Node.Children
        Node[] rootChildren = children;

        @Override
        protected boolean isInstrumentable() {
            return true;
        }

        @Override
        public SourceSection getSourceSection() {
            return section;
        }

        @Override
        public boolean isInternal() {
            if (internal == null) {
                return super.isInternal();
            } else {
                return internal;
            }
        }

        @Override
        public Object execute(VirtualFrame frame) {
            return null;
        }
    };
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Field(java.lang.reflect.Field) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) RootNode(com.oracle.truffle.api.nodes.RootNode) Language(org.graalvm.polyglot.Language) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) Method(java.lang.reflect.Method) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage)

Example 10 with LanguageInfo

use of com.oracle.truffle.api.nodes.LanguageInfo in project graal by oracle.

the class UnwindInstrumentationReturnSnippets method isLanguageContextInitialized.

/**
 * Test if language context of the source of the event is initialized.
 *
 * @since 0.26
 */
public boolean isLanguageContextInitialized() {
    CompilerAsserts.neverPartOfCompilation();
    Node node = getInstrumentedNode();
    if (node == null) {
        return true;
    }
    RootNode root = node.getRootNode();
    if (root == null) {
        return true;
    }
    LanguageInfo languageInfo = root.getLanguageInfo();
    Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo);
    return AccessorInstrumentHandler.langAccess().isContextInitialized(env);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Env(com.oracle.truffle.api.TruffleLanguage.Env)

Aggregations

LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)14 RootNode (com.oracle.truffle.api.nodes.RootNode)6 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)3 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 Node (com.oracle.truffle.api.nodes.Node)3 Test (org.junit.Test)3 Env (com.oracle.truffle.api.TruffleLanguage.Env)2 DebugValue (com.oracle.truffle.api.debug.DebugValue)2 IOException (java.io.IOException)2 Source (org.graalvm.polyglot.Source)2 CallTarget (com.oracle.truffle.api.CallTarget)1 InstrumentInfo (com.oracle.truffle.api.InstrumentInfo)1 Scope (com.oracle.truffle.api.Scope)1 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 HeapValue (com.oracle.truffle.api.debug.DebugValue.HeapValue)1 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)1 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)1 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1