Search in sources :

Example 51 with Node

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

the class DefaultNearestNodeSearch method findFirstNode.

private static Node findFirstNode(Node contextNode, Set<Class<? extends Tag>> tags) {
    Node[] first = new Node[] { null };
    contextNode.accept(new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (isTaggedWith(node, tags)) {
                first[0] = node;
                return false;
            }
            return true;
        }
    });
    return first[0];
}
Also used : WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 52 with Node

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

the class UnwindInstrumentationReturnSnippets method getNodeObject.

/**
 * Returns a language provided object that represents the instrumented node properties. The
 * returned is alwasy a valid interop object. The returned object is never <code>null</code> and
 * always returns <code>true</code> for the HAS_KEYS message. Multiple calls to
 * {@link #getNodeObject()} return the same node object instance.
 *
 * @see InstrumentableNode#getNodeObject()
 * @since 0.33
 */
public Object getNodeObject() {
    Object object = this.nodeObject;
    if (object == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        Node node = getInstrumentedNode();
        if (node instanceof InstrumentableNode) {
            object = ((InstrumentableNode) node).getNodeObject();
        } else {
            return null;
        }
        if (object == null) {
            object = AccessorInstrumentHandler.interopAccess().createDefaultNodeObject(node);
        } else {
            assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object);
        }
        this.nodeObject = object;
    }
    return object;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode)

Example 53 with Node

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

the class UnwindInstrumentationReturnSnippets method parseInContext.

/**
 * Evaluates source of (potentially different) language using the current context. The names of
 * arguments are parameters for the resulting {#link CallTarget} that allow the
 * <code>source</code> to reference the actual parameters passed to
 * {@link CallTarget#call(java.lang.Object...)}.
 *
 * @param source the source to evaluate
 * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments that
 *            can be referenced from the source
 * @return the call target representing the parsed result
 * @throws IOException if the parsing or evaluation fails for some reason
 * @since 0.12
 * @deprecated Use
 *             {@link TruffleInstrument.Env#parseInline(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.MaterializedFrame)}
 *             with {@link #getInstrumentedNode()} instead.
 */
@Deprecated
public CallTarget parseInContext(Source source, String... argumentNames) throws IOException {
    Node instrumentedNode = getInstrumentedNode();
    LanguageInfo languageInfo = instrumentedNode.getRootNode().getLanguageInfo();
    if (languageInfo == null) {
        throw new IllegalArgumentException("No language available for given node.");
    }
    Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo);
    return AccessorInstrumentHandler.langAccess().parse(env, source, instrumentedNode, argumentNames);
}
Also used : 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 54 with Node

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

Example 55 with Node

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

the class InstrumentationHandler method invalidateWrapper.

@SuppressWarnings("deprecation")
private static void invalidateWrapper(Node node) {
    Node parent = node.getParent();
    if (!(parent instanceof com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode)) {
        // not yet wrapped
        return;
    }
    invalidateWrapperImpl((com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode) parent, node);
}
Also used : EventChainNode(com.oracle.truffle.api.instrumentation.ProbeNode.EventChainNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)101 RootNode (com.oracle.truffle.api.nodes.RootNode)65 Test (org.junit.Test)46 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)21 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)21 Source (com.oracle.truffle.api.source.Source)16 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 CallTarget (com.oracle.truffle.api.CallTarget)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)8 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)7 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 TestHelper.createNode (com.oracle.truffle.api.dsl.test.TestHelper.createNode)5 ValueNode (com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode)5 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)5 LinkedHashMap (java.util.LinkedHashMap)5 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)4