Search in sources :

Example 11 with Node

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

the class DebugStackFrame method getScope.

/**
 * Get the current inner-most scope. The scope remain valid as long as the current stack frame
 * remains valid.
 * <p>
 * Use {@link DebuggerSession#getTopScope(java.lang.String)} to get scopes with global validity.
 * <p>
 * This method is not thread-safe and will throw an {@link IllegalStateException} if called on
 * another thread than it was created with.
 *
 * @return the scope, or <code>null</code> when no language is associated with this frame
 *         location, or when no local scope exists.
 * @since 0.26
 */
public DebugScope getScope() {
    verifyValidState(false);
    SuspendedContext context = getContext();
    RootNode root = findCurrentRoot();
    if (root == null) {
        return null;
    }
    Node node;
    if (currentFrame == null) {
        node = context.getInstrumentedNode();
    } else {
        node = currentFrame.getCallNode();
    }
    if (node.getRootNode().getLanguageInfo() == null) {
        // no language, no scopes
        return null;
    }
    Debugger debugger = event.getSession().getDebugger();
    MaterializedFrame frame = findTruffleFrame();
    Iterable<Scope> scopes = debugger.getEnv().findLocalScopes(node, frame);
    Iterator<Scope> it = scopes.iterator();
    if (!it.hasNext()) {
        return null;
    }
    return new DebugScope(it.next(), it, debugger, event, frame, root);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) Scope(com.oracle.truffle.api.Scope) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) MaterializedFrame(com.oracle.truffle.api.frame.MaterializedFrame)

Example 12 with Node

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

the class FlatNodeGenFactory method createFields.

private void createFields(CodeTypeElement clazz) {
    state.declareFields(clazz);
    if (requiresExclude()) {
        exclude.declareFields(clazz);
    }
    for (SpecializationData specialization : reachableSpecializations) {
        List<CodeVariableElement> fields = new ArrayList<>();
        boolean useSpecializationClass = useSpecializationClass(specialization);
        for (CacheExpression cache : specialization.getCaches()) {
            Parameter parameter = cache.getParameter();
            String fieldName = createFieldName(specialization, parameter);
            TypeMirror type = parameter.getType();
            Modifier visibility = useSpecializationClass ? null : Modifier.PRIVATE;
            CodeVariableElement cachedField;
            if (ElementUtils.isAssignable(type, context.getType(NodeInterface.class))) {
                cachedField = createNodeField(visibility, type, fieldName, Child.class);
            } else if (isNodeInterfaceArray(type)) {
                cachedField = createNodeField(visibility, type, fieldName, Children.class);
            } else {
                cachedField = createNodeField(visibility, type, fieldName, null);
                setFieldCompilationFinal(cachedField, parameter.getVariableElement().getAnnotation(Cached.class).dimensions());
            }
            fields.add(cachedField);
        }
        for (AssumptionExpression assumption : specialization.getAssumptionExpressions()) {
            String fieldName = createAssumptionFieldName(specialization, assumption);
            TypeMirror type;
            int compilationFinalDimensions;
            if (assumption.getExpression().getResolvedType().getKind() == TypeKind.ARRAY) {
                type = context.getType(Assumption[].class);
                compilationFinalDimensions = 1;
            } else {
                type = context.getType(Assumption.class);
                compilationFinalDimensions = -1;
            }
            CodeVariableElement assumptionField;
            if (useSpecializationClass) {
                assumptionField = createNodeField(null, type, fieldName, null);
            } else {
                assumptionField = createNodeField(PRIVATE, type, fieldName, null);
            }
            setFieldCompilationFinal(assumptionField, compilationFinalDimensions);
            fields.add(assumptionField);
        }
        if (useSpecializationClass) {
            TypeMirror baseType;
            boolean useNode = specializationClassIsNode(specialization);
            if (useNode) {
                baseType = context.getType(Node.class);
            } else {
                baseType = context.getType(Object.class);
            }
            CodeTypeElement cacheType = GeneratorUtils.createClass(node, null, modifiers(PRIVATE, FINAL, STATIC), createSpecializationTypeName(specialization), baseType);
            Class<?> annotationType;
            if (useNode) {
                annotationType = Child.class;
                if (specialization.getMaximumNumberOfInstances() > 1) {
                    cacheType.add(createNodeField(null, cacheType.asType(), "next_", Child.class));
                }
                CodeExecutableElement getNodeCost = new CodeExecutableElement(modifiers(PUBLIC), context.getType(NodeCost.class), "getCost");
                getNodeCost.createBuilder().startReturn().staticReference(context.getType(NodeCost.class), "NONE").end();
                cacheType.add(getNodeCost);
            } else {
                annotationType = CompilationFinal.class;
                if (specialization.getMaximumNumberOfInstances() > 1) {
                    cacheType.add(createNodeField(null, cacheType.asType(), "next_", annotationType));
                }
            }
            cacheType.add(GeneratorUtils.createConstructorUsingFields(modifiers(), cacheType));
            cacheType.getEnclosedElements().addAll(fields);
            clazz.add(createNodeField(PRIVATE, cacheType.asType(), createSpecializationFieldName(specialization), annotationType));
            clazz.add(cacheType);
            specializationClasses.put(specialization, cacheType);
        } else {
            clazz.getEnclosedElements().addAll(fields);
        }
    }
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) Node(com.oracle.truffle.api.nodes.Node) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) ArrayList(java.util.ArrayList) NodeCost(com.oracle.truffle.api.nodes.NodeCost) CacheExpression(com.oracle.truffle.dsl.processor.model.CacheExpression) Assumption(com.oracle.truffle.api.Assumption) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) Cached(com.oracle.truffle.api.dsl.Cached) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) ElementUtils.isObject(com.oracle.truffle.dsl.processor.java.ElementUtils.isObject) Modifier(javax.lang.model.element.Modifier) Child(com.oracle.truffle.api.nodes.Node.Child) NodeInterface(com.oracle.truffle.api.nodes.NodeInterface) AssumptionExpression(com.oracle.truffle.dsl.processor.model.AssumptionExpression)

Example 13 with Node

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

the class FlatNodeGenFactory method createInsertAccessor.

private CodeExecutableElement createInsertAccessor(boolean array) {
    CodeTypeParameterElement tVar = new CodeTypeParameterElement("T", context.getType(Node.class));
    TypeMirror type = tVar.createMirror(null, null);
    if (array) {
        type = new ArrayCodeTypeMirror(type);
    }
    CodeExecutableElement insertAccessor = new CodeExecutableElement(modifiers(FINAL), type, INSERT_ACCESSOR_NAME);
    insertAccessor.getParameters().add(new CodeVariableElement(type, "node"));
    insertAccessor.getTypeParameters().add(tVar);
    insertAccessor.createBuilder().startReturn().string("super.insert(node)").end();
    return insertAccessor;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) Node(com.oracle.truffle.api.nodes.Node) CodeTypeParameterElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeParameterElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)

Example 14 with Node

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

the class NodeUtilTest method testRecursiveIterator.

@Test
public void testRecursiveIterator() {
    TestRootNode root = new TestRootNode();
    TestForEachNode testForEachNode = new TestForEachNode(1);
    root.child0 = testForEachNode;
    TestNode testNode1 = new TestNode();
    testForEachNode.firstChild = testNode1;
    TestNode testNode2 = new TestNode();
    testForEachNode.children[0] = testNode2;
    TestNode testNode3 = new TestNode();
    testForEachNode.lastChild = testNode3;
    root.adoptChildren();
    int count = 0;
    Iterable<Node> iterable = () -> NodeUtil.makeRecursiveIterator(testForEachNode);
    for (Node node : iterable) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(4, count);
    Assert.assertEquals(1, testForEachNode.visited);
    Assert.assertEquals(1, testNode1.visited);
    Assert.assertEquals(1, testNode2.visited);
    Assert.assertEquals(1, testNode3.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Example 15 with Node

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

the class NodeUtilTest method testChildrenArray.

@Test
public void testChildrenArray() {
    // 2 children in the array
    TestForEachNode test2children = new TestForEachNode(2);
    TestNode both1 = new TestNode();
    TestNode both2 = new TestNode();
    test2children.children[0] = both1;
    test2children.children[1] = both2;
    int count = 0;
    for (Node node : test2children.getChildren()) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(2, count);
    Assert.assertEquals(1, both1.visited);
    Assert.assertEquals(1, both2.visited);
    // First null
    TestNode testChild1 = new TestNode();
    test2children.children[0] = null;
    test2children.children[1] = testChild1;
    count = 0;
    for (Node node : test2children.getChildren()) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(1, count);
    Assert.assertEquals(1, testChild1.visited);
    // Second null
    TestNode testChild2 = new TestNode();
    test2children.children[0] = testChild2;
    test2children.children[1] = null;
    count = 0;
    for (Node node : test2children.getChildren()) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(1, count);
    Assert.assertEquals(1, testChild2.visited);
    // Both null, go to next child
    TestNode otherChild = new TestNode();
    test2children.children[0] = null;
    test2children.children[1] = null;
    test2children.lastChild = otherChild;
    count = 0;
    for (Node node : test2children.getChildren()) {
        ((VisitableNode) node).visited++;
        count++;
    }
    Assert.assertEquals(1, count);
    Assert.assertEquals(1, otherChild.visited);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

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