Search in sources :

Example 1 with NodeClass

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

the class TruffleTreeDumpHandler method findNamedNodeChildren.

@SuppressWarnings("deprecation")
private static LinkedHashMap<String, Node> findNamedNodeChildren(Node node) {
    LinkedHashMap<String, Node> nodes = new LinkedHashMap<>();
    NodeClass nodeClass = NodeClass.get(node);
    for (com.oracle.truffle.api.nodes.NodeFieldAccessor field : findNodeFields(nodeClass)) {
        if (isChildField(nodeClass, field)) {
            Object value = findFieldObject(nodeClass, field, node);
            if (value != null) {
                nodes.put(findFieldName(nodeClass, field), (Node) value);
            }
        } else if (isChildrenField(nodeClass, field)) {
            Object value = findFieldObject(nodeClass, field, node);
            if (value != null) {
                Object[] children = (Object[]) value;
                for (int i = 0; i < children.length; i++) {
                    if (children[i] != null) {
                        nodes.put(findFieldName(nodeClass, field) + "[" + i + "]", (Node) children[i]);
                    }
                }
            }
        }
    }
    return nodes;
}
Also used : NodeClass(com.oracle.truffle.api.nodes.NodeClass) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with NodeClass

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

the class Target_com_oracle_truffle_api_nodes_Node method registerUnsafeAccess.

@SuppressWarnings("deprecation")
private void registerUnsafeAccess(DuringAnalysisAccessImpl access, Class<? extends Node> clazz) {
    if (registeredClasses.contains(clazz)) {
        return;
    }
    registeredClasses.add(clazz);
    NodeClass nodeClass = NodeClass.get(clazz);
    for (com.oracle.truffle.api.nodes.NodeFieldAccessor accessor : nodeClass.getFields()) {
        Field field;
        try {
            field = accessor.getDeclaringClass().getDeclaredField(accessor.getName());
        } catch (NoSuchFieldException ex) {
            throw shouldNotReachHere(ex);
        }
        if (accessor.getKind() == com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind.PARENT || accessor.getKind() == com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind.CHILD || accessor.getKind() == com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind.CHILDREN) {
            /*
                 * It's a field which represents an edge in the graph. Such fields are written with
                 * Unsafe in the NodeClass, e.g. when making changes in the graph.
                 */
            // TODO register unsafe accessed Truffle nodes in a separate partition?
            access.registerAsUnsafeWritten(field);
        }
        if (accessor.getKind() == com.oracle.truffle.api.nodes.NodeFieldAccessor.NodeFieldKind.DATA) {
            /*
                 * It's a normal non-child data field of the node. Such fields are written with
                 * Unsafe in the NodeUtil.deepCopyImpl.
                 */
            access.registerAsFrozenUnsafeAccessed(field);
        }
        /* All other fields are only read with Unsafe. */
        access.registerAsAccessed(field);
    }
    access.requireAnalysisIteration();
}
Also used : NodeClass(com.oracle.truffle.api.nodes.NodeClass) Field(java.lang.reflect.Field)

Example 3 with NodeClass

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

the class TruffleTreeDumpHandler method readNodeProperties.

@SuppressWarnings("deprecation")
private static void readNodeProperties(ASTNode astNode, Node node) {
    NodeClass nodeClass = NodeClass.get(node);
    for (com.oracle.truffle.api.nodes.NodeFieldAccessor field : findNodeFields(nodeClass)) {
        if (isDataField(nodeClass, field)) {
            String key = findFieldName(nodeClass, field);
            Object value = findFieldValue(nodeClass, field, node);
            astNode.properties.put(key, value);
        }
    }
}
Also used : NodeClass(com.oracle.truffle.api.nodes.NodeClass)

Example 4 with NodeClass

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

the class Target_com_oracle_truffle_api_nodes_Node method get.

@Substitute
public static NodeClass get(Class<?> clazz) {
    CompilerAsserts.neverPartOfCompilation();
    NodeClass nodeClass = (NodeClass) DynamicHub.fromClass(clazz).getMetaType();
    if (nodeClass == null) {
        throw shouldNotReachHere("Unknown node class: " + clazz.getName());
    }
    return nodeClass;
}
Also used : NodeClass(com.oracle.truffle.api.nodes.NodeClass) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

NodeClass (com.oracle.truffle.api.nodes.NodeClass)4 Substitute (com.oracle.svm.core.annotate.Substitute)1 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)1 Node (com.oracle.truffle.api.nodes.Node)1 RootNode (com.oracle.truffle.api.nodes.RootNode)1 Field (java.lang.reflect.Field)1 LinkedHashMap (java.util.LinkedHashMap)1