Search in sources :

Example 36 with RootNode

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

the class SourceListenerTest method testBindingDisposalImpl.

private void testBindingDisposalImpl(boolean load) throws Exception {
    Instrument instrument = engine.getInstruments().get("testBindingDisposal");
    TestBindingDisposal impl = instrument.lookup(TestBindingDisposal.class);
    impl.doAttach(load);
    Source source1 = lines("STATEMENT");
    run(source1);
    assertEvents(impl.onlyNewEvents, source1);
    assertEvents(impl.allEvents, source1);
    impl.onlyNewBinding.dispose();
    impl.allBinding.dispose();
    // No new events received after bindings are disposed
    com.oracle.truffle.api.source.Source source2a = com.oracle.truffle.api.source.Source.newBuilder("line2a").mimeType("mime").name("NoName2a").build();
    com.oracle.truffle.api.source.Source source2b = com.oracle.truffle.api.source.Source.newBuilder("line2b").mimeType("mime").name("NoName2b").build();
    Node node2a = new SourceSectionFilterTest.SourceSectionNode(source2a.createSection(1));
    Node node2b = new SourceSectionFilterTest.SourceSectionNode(source2b.createSection(1));
    RootNode root2 = SourceSectionFilterTest.createRootNode(engine, null, Boolean.FALSE, node2a, node2b);
    Truffle.getRuntime().createCallTarget(root2).call();
    assertEvents(impl.onlyNewEvents, source1);
    assertEvents(impl.allEvents, source1);
    // Clear and reattach
    impl.onlyNewEvents.clear();
    impl.allEvents.clear();
    impl.doAttach(load);
    Source source3 = lines("VARIABLE(a, 10)");
    run(source3);
    assertEvents(impl.onlyNewEvents, source3);
    assertEvents(impl.allEvents, getSourceImpl(source1), source2a, source2b, getSourceImpl(source3));
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Source(org.graalvm.polyglot.Source)

Example 37 with RootNode

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

the class SourceSectionFilterTest method isInstrumentedRoot.

private static boolean isInstrumentedRoot(SourceSectionFilter filter, Node root, int rootNodeBits) {
    try {
        Method m = filter.getClass().getDeclaredMethod("isInstrumentedRoot", Set.class, SourceSection.class, RootNode.class, int.class);
        ReflectionUtils.setAccessible(m, true);
        RootNode rootNode = null;
        if (root instanceof RootNode) {
            rootNode = (RootNode) root;
        }
        return (boolean) m.invoke(filter, ALL_TAGS, root != null ? root.getSourceSection() : null, rootNode, rootNodeBits);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Method(java.lang.reflect.Method)

Example 38 with RootNode

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

the class InputFilterTest method assertCleanedUp.

private void assertCleanedUp(String code) {
    // first we capture all root nodes used by the code.
    Set<RootNode> rootNodes = new HashSet<>();
    EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {

        public void onEnter(EventContext c, VirtualFrame frame) {
            addRoot(c);
        }

        @TruffleBoundary
        private void addRoot(EventContext c) {
            rootNodes.add(c.getInstrumentedNode().getRootNode());
        }

        public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
        }

        public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
        }
    });
    execute(code);
    binding.dispose();
    // we execute again to let the instrumentation wrappers be cleaned up
    execute(code);
    for (RootNode root : rootNodes) {
        // all frame slots got removed
        assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
        // no wrappers left
        root.accept(new NodeVisitor() {

            public boolean visit(Node node) {
                if (node instanceof WrapperNode) {
                    throw new AssertionError();
                }
                return true;
            }
        });
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) HashSet(java.util.HashSet)

Example 39 with RootNode

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

the class InstrumentationHandler method lazyInitializeSourcesList.

/**
 * Initializes sources and sourcesList by populating them from loadedRoots.
 */
private void lazyInitializeSourcesList() {
    assert Thread.holdsLock(sources);
    if (sourcesListRef.get() == null) {
        // build the sourcesList, we need it now
        Collection<Source> sourcesList = new WeakAsyncList<>(16);
        sourcesListRef.set(sourcesList);
        for (RootNode root : loadedRoots) {
            int rootBits = RootNodeBits.get(root);
            if (RootNodeBits.isNoSourceSection(rootBits)) {
                continue;
            } else {
                SourceSection sourceSection = root.getSourceSection();
                if (RootNodeBits.isSameSource(rootBits) && sourceSection != null) {
                    Source source = sourceSection.getSource();
                    if (!sources.containsKey(source)) {
                        sources.put(source, null);
                        sourcesList.add(source);
                    }
                } else {
                    if (sourceSection != null) {
                        findSourcesVisitor.adoptSource(sourceSection.getSource());
                    }
                    visitRoot(root, root, findSourcesVisitor, false);
                    for (Source source : findSourcesVisitor.rootSources) {
                        if (!sources.containsKey(source)) {
                            sources.put(source, null);
                            sourcesList.add(source);
                        }
                    }
                    findSourcesVisitor.rootSources.clear();
                }
            }
        }
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(com.oracle.truffle.api.source.Source)

Example 40 with RootNode

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

the class InstrumentationHandler method createBindings.

EventChainNode createBindings(VirtualFrame frame, ProbeNode probeNodeImpl) {
    EventContext context = probeNodeImpl.getContext();
    SourceSection sourceSection = context.getInstrumentedSourceSection();
    if (TRACE) {
        trace("BEGIN: Lazy update for %s%n", sourceSection);
    }
    RootNode rootNode;
    Node parentInstrumentable = null;
    SourceSection parentInstrumentableSourceSection = null;
    Node parentNode = probeNodeImpl.getParent();
    while (parentNode != null && parentNode.getParent() != null) {
        if (parentInstrumentable == null) {
            SourceSection parentSourceSection = parentNode.getSourceSection();
            if (isInstrumentableNode(parentNode, parentSourceSection)) {
                parentInstrumentable = parentNode;
                parentInstrumentableSourceSection = parentSourceSection;
            }
        }
        parentNode = parentNode.getParent();
    }
    if (parentNode instanceof RootNode) {
        rootNode = (RootNode) parentNode;
    } else {
        throw new AssertionError();
    }
    Node instrumentedNode = probeNodeImpl.getContext().getInstrumentedNode();
    Set<Class<?>> providedTags = getProvidedTags(rootNode);
    EventChainNode root = null;
    EventChainNode parent = null;
    for (EventBinding.Source<?> binding : executionBindings) {
        if (binding.isChildInstrumentedFull(providedTags, rootNode, parentInstrumentable, parentInstrumentableSourceSection, instrumentedNode, sourceSection)) {
            if (TRACE) {
                trace("  Found input value binding %s, %s%n", binding.getInputFilter(), System.identityHashCode(binding));
            }
            EventChainNode next = probeNodeImpl.createParentEventChainCallback(frame, binding, rootNode, providedTags);
            if (next == null) {
                // inconsistent AST
                continue;
            }
            if (root == null) {
                root = next;
            } else {
                assert parent != null;
                parent.setNext(next);
            }
            parent = next;
        }
        if (binding.isInstrumentedFull(providedTags, rootNode, instrumentedNode, sourceSection)) {
            if (TRACE) {
                trace("  Found binding %s, %s%n", binding.getFilter(), binding.getElement());
            }
            EventChainNode next = probeNodeImpl.createEventChainCallback(frame, binding, rootNode, providedTags, instrumentedNode, sourceSection);
            if (next == null) {
                continue;
            }
            if (root == null) {
                root = next;
            } else {
                assert parent != null;
                parent.setNext(next);
            }
            parent = next;
        }
    }
    if (TRACE) {
        trace("END: Lazy updated for %s%n", sourceSection);
    }
    return root;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) EventChainNode(com.oracle.truffle.api.instrumentation.ProbeNode.EventChainNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) EventChainNode(com.oracle.truffle.api.instrumentation.ProbeNode.EventChainNode) SourceSection(com.oracle.truffle.api.source.SourceSection)

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