Search in sources :

Example 21 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class FrameDescriptorTest method localsDefaultValue.

@Test
public void localsDefaultValue() throws Exception {
    Object defaultValue = "default";
    FrameDescriptor d = new FrameDescriptor(defaultValue);
    s1 = d.addFrameSlot("v1");
    s2 = d.addFrameSlot("v2");
    s3 = d.addFrameSlot("v3");
    VirtualFrame f = Truffle.getRuntime().createVirtualFrame(new Object[] { 1, 2 }, d);
    assertFrame(f, d);
    assertFrame(f.materialize(), d);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) Test(org.junit.Test)

Example 22 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class InputFilterTest method testHierarchicalInputs.

@Test
public void testHierarchicalInputs() {
    SourceSectionFilter expressionFilter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
    EventBinding<?> binding = instrumenter.attachExecutionEventFactory(expressionFilter, expressionFilter, factory);
    String exp1 = "EXPRESSION(EXPRESSION(CONSTANT(0)), EXPRESSION(CONSTANT(1)))";
    String exp2 = "EXPRESSION(EXPRESSION(CONSTANT(2)))";
    String exp3 = "EXPRESSION(EXPRESSION(CONSTANT(3)), EXPRESSION(EXPRESSION(CONSTANT(4))))";
    String code = "EXPRESSION(" + exp1 + "," + exp2 + "," + exp3 + ")";
    execute(code);
    FrameDescriptor[] descriptor = new FrameDescriptor[1];
    assertOn(ENTER, (e) -> {
        descriptor[0] = e.frame.getFrameDescriptor();
        assertCharacters(e, code);
    });
    // exp1
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp1);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(0))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(0))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(0)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertEquals("(0)", e.inputValue);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(1))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(1))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(1)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertEquals("(1)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp1);
        assertArrayEquals(new Object[] { "(0)", "(1)" }, e.inputs);
        assertEquals("((0)+(1))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((0)+(1))", e.inputValue);
    });
    // exp2
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp2);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(2))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(2))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(2)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp2);
        assertEquals("(2)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp2);
        assertArrayEquals(new Object[] { "(2)" }, e.inputs);
        assertEquals("((2))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((2))", e.inputValue);
    });
    // exp3
    assertOn(ENTER, (e) -> {
        assertCharacters(e, exp3);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(3))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(3))");
        assertEquals("(3)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertEquals("(3)", e.inputValue);
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
    });
    assertOn(ENTER, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(4))");
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(CONSTANT(4))");
        assertArrayEquals(new Object[] {}, e.inputs);
        assertEquals("(4)", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
        assertEquals("(4)", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, "EXPRESSION(EXPRESSION(CONSTANT(4)))");
        assertArrayEquals(new Object[] { "(4)" }, e.inputs);
        assertEquals("((4))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertEquals("((4))", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, exp3);
        assertArrayEquals(new Object[] { "(3)", "((4))" }, e.inputs);
        assertEquals("((3)+((4)))", e.result);
    });
    assertOn(INPUT_VALUE, (e) -> {
        assertCharacters(e, code);
        assertEquals("((3)+((4)))", e.inputValue);
    });
    assertOn(RETURN_VALUE, (e) -> {
        assertCharacters(e, code);
        assertArrayEquals(new Object[] { "((0)+(1))", "((2))", "((3)+((4)))" }, e.inputs);
        assertEquals("(((0)+(1))+((2))+((3)+((4))))", e.result);
    });
    // should use maximum four frame slots to save expression values
    assertEquals(4, descriptor[0].getIdentifiers().size());
    binding.dispose();
    assertCleanedUp(code);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 23 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class SLContext method installBuiltin.

public void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory) {
    /*
         * The builtin node factory is a class that is automatically generated by the Truffle DSL.
         * The signature returned by the factory reflects the signature of the @Specialization
         *
         * methods in the builtin classes.
         */
    int argumentCount = factory.getExecutionSignature().size();
    SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount];
    /*
         * Builtin functions are like normal functions, i.e., the arguments are passed in as an
         * Object[] array encapsulated in SLArguments. A SLReadArgumentNode extracts a parameter
         * from this array.
         */
    for (int i = 0; i < argumentCount; i++) {
        argumentNodes[i] = new SLReadArgumentNode(i);
    }
    /* Instantiate the builtin node. This node performs the actual functionality. */
    SLBuiltinNode builtinBodyNode = factory.createNode((Object) argumentNodes);
    builtinBodyNode.addRootTag();
    /* The name of the builtin function is specified via an annotation on the node class. */
    String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName();
    builtinBodyNode.setUnavailableSourceSection();
    /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */
    SLRootNode rootNode = new SLRootNode(language, new FrameDescriptor(), builtinBodyNode, BUILTIN_SOURCE.createUnavailableSection(), name);
    /* Register the builtin function in our function registry. */
    getFunctionRegistry().register(name, Truffle.getRuntime().createCallTarget(rootNode));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLReadArgumentNode(com.oracle.truffle.sl.nodes.local.SLReadArgumentNode) SLRootNode(com.oracle.truffle.sl.nodes.SLRootNode) SLBuiltinNode(com.oracle.truffle.sl.builtins.SLBuiltinNode)

Example 24 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class SimplePartialEvaluationTest method longSequenceConstants.

@Test
public void longSequenceConstants() {
    FrameDescriptor fd = new FrameDescriptor();
    int length = 40;
    AbstractTestNode[] children = new AbstractTestNode[length];
    for (int i = 0; i < children.length; ++i) {
        children[i] = new ConstantTestNode(42);
    }
    AbstractTestNode result = new BlockTestNode(children);
    assertPartialEvalEquals("constant42", new RootTestNode(fd, "longSequenceConstants", result));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) BlockTestNode(org.graalvm.compiler.truffle.test.nodes.BlockTestNode) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) ConstantTestNode(org.graalvm.compiler.truffle.test.nodes.ConstantTestNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Example 25 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class SimplePartialEvaluationTest method intrinsicStringHashCodeNonFinal.

@Test
public void intrinsicStringHashCodeNonFinal() {
    /*
         * The intrinsic for String.hashcode() does not trigger on non-constant strings, so the
         * method String.hashCode() must be inlined during partial evaluation (so there must not be
         * an invoke after partial evaluation).
         */
    FrameDescriptor fd = new FrameDescriptor();
    AbstractTestNode result = new StringHashCodeNonFinalNode("*");
    assertPartialEvalNoInvokes(new RootTestNode(fd, "intrinsicStringHashCodeNonFinal", result));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) AbstractTestNode(org.graalvm.compiler.truffle.test.nodes.AbstractTestNode) StringHashCodeNonFinalNode(org.graalvm.compiler.truffle.test.nodes.StringHashCodeNonFinalNode) RootTestNode(org.graalvm.compiler.truffle.test.nodes.RootTestNode) Test(org.junit.Test)

Aggregations

FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)72 Test (org.junit.Test)61 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)50 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)43 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 ConstantTestNode (org.graalvm.compiler.truffle.test.nodes.ConstantTestNode)14 RootNode (com.oracle.truffle.api.nodes.RootNode)12 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)9 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)7 AddTestNode (org.graalvm.compiler.truffle.test.nodes.AddTestNode)7 BlockTestNode (org.graalvm.compiler.truffle.test.nodes.BlockTestNode)6 Assumption (com.oracle.truffle.api.Assumption)5 CallTarget (com.oracle.truffle.api.CallTarget)5 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 LoadLocalTestNode (org.graalvm.compiler.truffle.test.nodes.LoadLocalTestNode)3 NestedExplodedLoopTestNode (org.graalvm.compiler.truffle.test.nodes.NestedExplodedLoopTestNode)3 StoreLocalTestNode (org.graalvm.compiler.truffle.test.nodes.StoreLocalTestNode)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 WeakReference (java.lang.ref.WeakReference)2 List (java.util.List)2