Search in sources :

Example 66 with RootNode

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

the class TckLanguage method parse.

@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
    Source code = request.getSource();
    final RootNode root;
    final String txt = code.getCharacters().toString();
    if (txt.startsWith("TCK42:")) {
        int nextColon = txt.indexOf(":", 6);
        String mimeType = txt.substring(6, nextColon);
        Source toParse = Source.newBuilder(txt.substring(nextColon + 1)).mimeType(mimeType).name("src.tck").build();
        root = new MultiplyNode(this, toParse);
    } else {
        final double value = Double.parseDouble(txt);
        root = RootNode.createConstantNode(value);
    }
    return Truffle.getRuntime().createCallTarget(root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Source(com.oracle.truffle.api.source.Source)

Example 67 with RootNode

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

the class SourceSectionFilterTest method testIgnoreInternal.

@Test
public void testIgnoreInternal() throws Exception {
    SourceSectionFilter internalFilter = SourceSectionFilter.newBuilder().includeInternal(false).build();
    SourceSectionFilter defaultFilter = SourceSectionFilter.newBuilder().build();
    Assert.assertTrue(isInstrumented(internalFilter, null, source()));
    Source nonInternalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
    // Default non-internal RootNode
    RootNode root = createRootNode(nonInternalSource.createSection(0, 23), null);
    Assert.assertTrue(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
    // Internal RootNode
    root = createRootNode(nonInternalSource.createSection(0, 23), true);
    Assert.assertFalse(isInstrumented(internalFilter, root, createNode(nonInternalSource.createSection(1))));
    Assert.assertTrue(isInstrumented(defaultFilter, root, createNode(nonInternalSource.createSection(1))));
    Source internalSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).internal().build();
    // Default internal RootNode
    root = createRootNode(internalSource.createSection(0, 23), null);
    Assert.assertFalse(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
    // Non-internal RootNode
    root = createRootNode(nonInternalSource.createSection(0, 23), false);
    Assert.assertTrue(isInstrumented(internalFilter, root, createNode(internalSource.createSection(1))));
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 68 with RootNode

use of com.oracle.truffle.api.nodes.RootNode 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 69 with RootNode

use of com.oracle.truffle.api.nodes.RootNode 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)

Example 70 with RootNode

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

the class UnwindInstrumentationReturnSnippets method validEventContext.

@SuppressWarnings("unchecked")
boolean validEventContext() {
    Node node = getInstrumentedNode();
    if (node instanceof RootNode) {
        throw new IllegalStateException("Instrumentable node must not be a root node.");
    }
    Object object = null;
    if (node instanceof InstrumentableNode) {
        object = ((InstrumentableNode) node).getNodeObject();
    } else {
        // legacy support
        return true;
    }
    if (object != null) {
        assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object);
    }
    boolean foundStandardTag = false;
    for (Class<?> clazz : StandardTags.ALL_TAGS) {
        if (hasTag((Class<? extends Tag>) clazz)) {
            foundStandardTag = true;
        }
    }
    if (foundStandardTag) {
        RootNode root = probeNode.getRootNode();
        if (root != null && root.getSourceSection() != null) {
            assert sourceSection != null : "All nodes tagged with a standard tag and with a root node that has a source section must also have a source section.";
        }
    }
    return true;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode)

Aggregations

RootNode (com.oracle.truffle.api.nodes.RootNode)86 Test (org.junit.Test)36 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)24 Node (com.oracle.truffle.api.nodes.Node)23 CallTarget (com.oracle.truffle.api.CallTarget)16 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)16 RootCallTarget (com.oracle.truffle.api.RootCallTarget)12 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)12 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)9 Source (com.oracle.truffle.api.source.Source)8 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)8 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 ArrayList (java.util.ArrayList)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 TruffleException (com.oracle.truffle.api.TruffleException)3 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)3