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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations