Search in sources :

Example 21 with Node

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

the class ChildNodeTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    TestChildNode leftChild = new TestChildNode();
    TestChildNode rightChild = new TestChildNode();
    TestRootNode rootNode = new TestRootNode(leftChild, rightChild);
    CallTarget target = runtime.createCallTarget(rootNode);
    assertEquals(rootNode, leftChild.getParent());
    assertEquals(rootNode, rightChild.getParent());
    Iterator<Node> iterator = rootNode.getChildren().iterator();
    assertEquals(leftChild, iterator.next());
    assertEquals(rightChild, iterator.next());
    assertFalse(iterator.hasNext());
    Object result = target.call();
    assertEquals(42, result);
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 22 with Node

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

the class SuspendableLocationFinder method findSuspendableLocations.

static Iterable<SourceSection> findSuspendableLocations(SourceSection range, boolean restrictToSingleFunction, TruffleInstrument.Env env) {
    Source source = range.getSource();
    int startIndex = range.getCharIndex();
    int endIndex = range.getCharEndIndex();
    SectionsCollector sectionsCollector = collectSuspendableLocations(source, startIndex, endIndex, restrictToSingleFunction, env);
    List<SourceSection> sections = sectionsCollector.getSections();
    if (sections.isEmpty()) {
        SourceSectionFilter filter = SourceSectionFilter.newBuilder().sourceIs(source).indexIn(IndexRange.between(startIndex, endIndex)).build();
        ContainerNodeCollector nodeCollector = new ContainerNodeCollector(startIndex);
        EventBinding<ContainerNodeCollector> binding = env.getInstrumenter().attachLoadSourceSectionListener(filter, nodeCollector, true);
        binding.dispose();
        if (nodeCollector.getContainerNode() != null) {
            Node suspendableNode = nodeCollector.getContainerNode().findNearestNodeAt(startIndex, SUSPENDABLE_TAGS_SET);
            if (suspendableNode != null) {
                startIndex = Math.min(startIndex, suspendableNode.getSourceSection().getCharIndex());
                endIndex = Math.max(endIndex, suspendableNode.getSourceSection().getCharEndIndex());
                sectionsCollector = collectSuspendableLocations(source, startIndex, endIndex, restrictToSingleFunction, env);
                sections = sectionsCollector.getSections();
            }
        }
    }
    return sections;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) SourceSection(com.oracle.truffle.api.source.SourceSection) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source)

Example 23 with Node

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

the class NodeAdoptionBenchmark method shallowSmallBlocks.

@Benchmark
public Object shallowSmallBlocks() {
    Node block = createBlock(0, 5);
    block.adoptChildren();
    return block;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 24 with Node

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

the class NodeAdoptionBenchmark method deepSmallBlocks.

@Benchmark
public Object deepSmallBlocks() {
    Node block = createBlock(5, 5);
    block.adoptChildren();
    return block;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 25 with Node

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

the class NodeAdoptionBenchmark method deepBigBlocks.

@Benchmark
public Object deepBigBlocks() {
    Node block = createBlock(5, 30);
    block.adoptChildren();
    return block;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) Benchmark(org.openjdk.jmh.annotations.Benchmark)

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