Mercurial > hg > graal-jvmci-8
changeset 9540:438bde0e12ba
Merge.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 03 May 2013 16:28:53 +0200 |
parents | 05c523b6633b (diff) cf9b3e717bda (current diff) |
children | 4bd247fc3625 |
files | |
diffstat | 3 files changed, 96 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java Fri May 03 15:21:52 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/GraphPrintVisitor.java Fri May 03 16:28:53 2013 +0200 @@ -334,7 +334,7 @@ // default handler createElementForNode(node); - List<Object> children = NodeUtil.findNodeChildren(node); + List<Node> children = NodeUtil.findNodeChildren((Node) node); for (Object child : children) { if (child == null) { continue;
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Fri May 03 15:21:52 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java Fri May 03 16:28:53 2013 +0200 @@ -29,6 +29,9 @@ import sun.misc.*; +import com.oracle.truffle.api.nodes.Node.Child; +import com.oracle.truffle.api.nodes.Node.Children; + /** * Utility class that manages the special access methods for node instances. */ @@ -73,15 +76,13 @@ } // Node fields - if (Node.class.isAssignableFrom(field.getType())) { - if (!field.getName().equals("parent")) { - nodeFieldOffsetsList.add(unsafe.objectFieldOffset(field)); - nodeFieldClassesList.add(field.getType()); - } else { - parentOffsetTemp = unsafe.objectFieldOffset(field); - parentClassTmp = field.getType(); - } - } else if (field.getType().getComponentType() != null && Node.class.isAssignableFrom(field.getType().getComponentType())) { + if (Node.class.isAssignableFrom(field.getType()) && field.getName().equals("parent")) { + parentOffsetTemp = unsafe.objectFieldOffset(field); + parentClassTmp = field.getType(); + } else if (Node.class.isAssignableFrom(field.getType()) && field.getAnnotation(Child.class) != null) { + nodeFieldOffsetsList.add(unsafe.objectFieldOffset(field)); + nodeFieldClassesList.add(field.getType()); + } else if (field.getType().getComponentType() != null && Node.class.isAssignableFrom(field.getType().getComponentType()) && field.getAnnotation(Children.class) != null) { nodeArrayFieldOffsetsList.add(unsafe.objectFieldOffset(field)); nodeArrayFieldClassesList.add(field.getType()); } else { @@ -251,18 +252,18 @@ return (T) clone; } - public static List<Object> findNodeChildren(Object node) { - List<Object> nodes = new ArrayList<>(); + public static List<Node> findNodeChildren(Node node) { + List<Node> nodes = new ArrayList<>(); NodeClass nodeClass = NodeClass.get(node.getClass()); for (long fieldOffset : nodeClass.nodeFieldOffsets) { Object child = unsafe.getObject(node, fieldOffset); if (child != null) { - nodes.add(child); + nodes.add((Node) child); } } for (long fieldOffset : nodeClass.nodeArrayFieldOffsets) { - Object[] children = (Object[]) unsafe.getObject(node, fieldOffset); + Node[] children = (Node[]) unsafe.getObject(node, fieldOffset); if (children != null) { nodes.addAll(Arrays.asList(children)); } @@ -386,10 +387,8 @@ } @SuppressWarnings("unchecked") - public static <T> T findFirstNodeInstance(Object root, Class<T> clazz) { - List<Object> childNodes = findNodeChildren(root); - - for (Object childNode : childNodes) { + public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { + for (Node childNode : findNodeChildren(root)) { if (clazz.isInstance(childNode)) { return (T) childNode; } else { @@ -474,8 +473,16 @@ } public static String printTreeToString(Node node) { + return printTreeToString(node, false); + } + + private static String printTreeToString(Node node, boolean compact) { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - printTree(new PrintStream(byteOut), node); + if (compact) { + printCompactTree(new PrintStream(byteOut), node); + } else { + printTree(new PrintStream(byteOut), node); + } try { byteOut.flush(); } catch (IOException e) { @@ -494,6 +501,61 @@ printTree(p, node, new NodeTreeResolver()); } + public static String printCompactTreeToString(Node node) { + return printTreeToString(node, true); + } + + public static void printCompactTree(PrintStream p, Node node) { + printCompactTree(p, null, node, 1); + } + + private static void printCompactTree(PrintStream p, Node parent, Node node, int level) { + if (node == null) { + return; + } + for (int i = 0; i < level; i++) { + p.print(" "); + } + if (parent == null) { + p.println(node.getClass().getSimpleName()); + } else { + String fieldName = null; + Field[] fields = NodeUtil.getAllFields(parent.getClass()); + try { + for (Field field : fields) { + field.setAccessible(true); + Object value = field.get(parent); + if (value == node) { + fieldName = field.getName(); + break; + } else if (value instanceof Node[]) { + int index = 0; + for (Node arrayNode : (Node[]) value) { + if (arrayNode == node) { + fieldName = field.getName() + "[" + index + "]"; + break; + } + index++; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + if (fieldName == null) { + fieldName = "unknownField"; + } + p.print(fieldName); + p.print(" = "); + p.println(node.getClass().getSimpleName()); + } + + for (Node child : node.getChildren()) { + printCompactTree(p, node, child, level + 1); + } + } + /** * Prints a human readable form of a tree to the given {@link PrintStream}. The * {@link TreeResolver} interface needs to be implemented to specify how the method can read the @@ -639,12 +701,12 @@ @Override public boolean isChildObject(Field f) { - return Node.class.isAssignableFrom(f.getType()); + return Node.class.isAssignableFrom(f.getType()) && f.getAnnotation(Child.class) != null; } @Override public boolean isChildArrayObject(Field f) { - return f.getType().getComponentType() != null && Node.class.isAssignableFrom(f.getType().getComponentType()); + return f.getType().getComponentType() != null && Node.class.isAssignableFrom(f.getType().getComponentType()) && f.getAnnotation(Children.class) != null; } @Override
--- a/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Fri May 03 15:21:52 2013 +0200 +++ b/graal/com.oracle.truffle.codegen.processor/src/com/oracle/truffle/codegen/processor/node/NodeCodeGenerator.java Fri May 03 16:28:53 2013 +0200 @@ -1460,8 +1460,7 @@ List<ActualParameter> executeParameters = new ArrayList<>(); for (ActualParameter sourceParameter : executable.getParameters()) { - NodeChildData field = specialization.getNode().findChild(sourceParameter.getSpecification().getName()); - if (field == null) { + if (!sourceParameter.getSpecification().isSignature()) { continue; } @@ -1645,21 +1644,24 @@ for (ActualParameter targetParameter : targetParameters) { NodeChildData field = sourceNode.findChild(targetParameter.getSpecification().getName()); - if (field == null) { + if (!targetParameter.getSpecification().isSignature()) { continue; } + TypeData targetType = targetParameter.getTypeSystemType(); - - ExecutableTypeData targetExecutable = field.findExecutableType(getContext(), targetType); + ExecutableTypeData targetExecutable = null; + if (field != null) { + targetExecutable = field.findExecutableType(getContext(), targetType); + } ActualParameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName()); String targetVariableName = valueName(targetParameter); CodeTree executionExpression = null; - if (cast || sourceParameter != null) { + if ((sourceParameter != null && cast) || sourceParameter != null) { TypeData sourceType = sourceParameter.getTypeSystemType(); - if (!sourceType.needsCastTo(getContext(), targetType)) { - if (field.isShortCircuit() && sourceParameter != null) { + if (targetExecutable == null || !sourceType.needsCastTo(getContext(), targetType)) { + if (field != null && field.isShortCircuit() && sourceParameter != null) { builder.tree(createShortCircuitValue(builder, specialization, field, targetParameter.getPreviousParameter(), unexpectedParameter)); } builder.startStatement(); @@ -1667,8 +1669,10 @@ builder.string(valueName(targetParameter)).string(" = "); builder.tree(CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter))); builder.end(); + continue; } else { - executionExpression = createExpectExecutableType(sourceNode, sourceType, targetExecutable, CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter))); + CodeTree valueTree = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter)); + executionExpression = createExpectExecutableType(sourceNode, sourceType, targetExecutable, valueTree); } } else if (sourceParameter == null) { executionExpression = createExecuteChildExpression(builder, field, targetParameter, unexpectedParameter);