/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. * * @since 0.8 or earlier */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. * * @since 0.8 or earlier */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
protected void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists || NodeUtil.findAnnotation(node.getClass(), GraphDuplicate.class) != null) { Element nodeElem = dom.createElement("node"); nodeElem.setAttribute("id", !exists ? oldOrNextId(node) : nextId()); nodeMap.put(node, nodeElem); Element properties = dom.createElement("properties"); nodeElem.appendChild(properties); nodesElement.appendChild(nodeElem); setNodeProperty(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", "")); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", node.getClass().getSimpleName()); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
final void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists) { int nodeId = !exists ? oldOrNextId(node) : nextId(); nodeMap.put(node, new NodeElement(nodeId)); String className = NodeUtil.className(node.getClass()); setNodeProperty(node, "name", dropNodeSuffix(className)); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", className); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
final void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists) { int nodeId = !exists ? oldOrNextId(node) : nextId(); nodeMap.put(node, new NodeElement(nodeId)); String className = NodeUtil.className(node.getClass()); setNodeProperty(node, "name", dropNodeSuffix(className)); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", className); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
if (nodeInfo == null || nodeInfo.cost() == NodeCost.MONOMORPHIC /* the default */) { clazz.add(createGetCostMethod());