# HG changeset patch # User Stefan Rumzucker # Date 1446815946 -3600 # Node ID 91a0b42ea9ed3c47c0dc0087ffbe412746fe6d0f # Parent 225483fd8f3b8f1dd227e2d6ff1a02b2671ff085 Refactoring of GraphDumper. diff -r 225483fd8f3b -r 91a0b42ea9ed graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/AbstractMethodScopeDumper.java --- a/graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/AbstractMethodScopeDumper.java Fri Nov 06 17:44:38 2015 +0100 +++ b/graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/AbstractMethodScopeDumper.java Fri Nov 06 14:19:06 2015 +0100 @@ -77,12 +77,14 @@ protected void openScope(MethodContext.Item item) throws IOException { int debugId = item.getDebugId(); - pathStack.push(debugId != -1 ? debugId : pathCounter); + int id = debugId != -1 ? debugId : pathCounter; + + pathStack.push(id); itemIdStack.push(itemIdCounter); pathCounter = 0; itemIdCounter = 0; - processMethod(item.getMethod(), item.getName()); + processMethod(item.getMethod(), id, item.getName()); } @SuppressWarnings("unused") @@ -96,8 +98,9 @@ } } - protected void processMethod(JavaMethod method, String name) throws IOException { + protected void processMethod(JavaMethod method, int id, String name) throws IOException { DataDict dataDict = new DataDict(); + dataDict.put("id", id); dataDict.put("name", name); if (method instanceof ResolvedJavaMethod) { diff -r 225483fd8f3b -r 91a0b42ea9ed graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/GraphDumper.java --- a/graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/GraphDumper.java Fri Nov 06 17:44:38 2015 +0100 +++ b/graal/com.oracle.graal.salver/src/com/oracle/graal/salver/dumper/GraphDumper.java Fri Nov 06 14:19:06 2015 +0100 @@ -77,7 +77,7 @@ nodeClassCategoryMap.put(VirtualState.class, "State"); nodeClassCategoryMap.put(PhiNode.class, "Phi"); nodeClassCategoryMap.put(ProxyNode.class, "Proxy"); - // nodeClassCategoryMap.put(Object.class, "Floating"); + // nodeClassCategoryMap.put(Node.class, "Floating"); } @Override @@ -116,20 +116,6 @@ } } - ControlFlowGraph cfg = null; - List blocks = null; - NodeMap nodeToBlock = null; - BlockMap> blockToNodes = null; - - if (schedule != null) { - cfg = schedule.getCFG(); - if (cfg != null) { - blocks = cfg.getBlocks(); - nodeToBlock = schedule.getNodeToBlockMap(); - blockToNodes = schedule.getBlockToNodesMap(); - } - } - DataDict dataDict = new DataDict(); dataDict.put("id", nextItemId()); dataDict.put("name", name); @@ -137,15 +123,19 @@ DataDict graphDict = new DataDict(); dataDict.put("graph", graphDict); - processNodes(graphDict, graph.getNodes(), nodeToBlock, cfg); + processNodes(graphDict, graph.getNodes(), schedule); - if (blocks != null && blockToNodes != null) { - processBlocks(graphDict, blocks, blockToNodes); + if (schedule != null) { + ControlFlowGraph cfg = schedule.getCFG(); + if (cfg != null) { + List blocks = cfg.getBlocks(); + processBlocks(graphDict, blocks, schedule); + } } serializeAndFlush(createEventDictWithId("graph", dataDict)); } - private static void processNodes(DataDict graphDict, NodeIterable nodes, NodeMap nodeToBlock, ControlFlowGraph cfg) { + private static void processNodes(DataDict graphDict, NodeIterable nodes, SchedulePhase schedule) { Map, Integer> classMap = new HashMap<>(); DataList classList = new DataList(); @@ -161,44 +151,52 @@ NodeClass nodeClass = node.getNodeClass(); DataDict nodeDict = new DataDict(); + nodeList.add(nodeDict); + nodeDict.put("id", getNodeId(node)); nodeDict.put("class", getNodeClassId(classMap, classList, nodeClass)); - if (nodeToBlock != null) { - if (nodeToBlock.isNew(node)) { - nodeDict.put("block", -1); - } else { - Block block = nodeToBlock.get(node); - if (block != null) { - nodeDict.put("block", block.getId()); - } - } + if (schedule != null) { + processNodeSchedule(nodeDict, node, schedule); } - if (cfg != null && PrintGraphProbabilities.getValue() && node instanceof FixedNode) { - try { - nodeDict.put("probability", cfg.blockFor(node).probability()); - } catch (Throwable t) { - nodeDict.put("probability", t); - } + DataDict propertyDict = new DataDict(); + node.getDebugProperties(propertyDict); + + if (!propertyDict.isEmpty()) { + nodeDict.put("properties", propertyDict); } - Map debugProperties = node.getDebugProperties(); - if (!debugProperties.isEmpty()) { - DataDict propertyDict = new DataDict(); - nodeDict.put("properties", propertyDict); - for (Map.Entry entry : debugProperties.entrySet()) { - propertyDict.put(entry.getKey().toString(), entry.getValue()); - } - } - - nodeList.add(nodeDict); appendEdges(edgeList, node, Type.Inputs); appendEdges(edgeList, node, Type.Successors); } } - private static void processBlocks(DataDict graphDict, List blocks, BlockMap> blockToNodes) { + private static void processNodeSchedule(DataDict nodeDict, Node node, SchedulePhase schedule) { + NodeMap nodeToBlock = schedule.getNodeToBlockMap(); + if (nodeToBlock != null) { + if (nodeToBlock.isNew(node)) { + nodeDict.put("block", -1); + } else { + Block block = nodeToBlock.get(node); + if (block != null) { + nodeDict.put("block", block.getId()); + } + } + } + + ControlFlowGraph cfg = schedule.getCFG(); + if (cfg != null && PrintGraphProbabilities.getValue() && node instanceof FixedNode) { + try { + nodeDict.put("probability", cfg.blockFor(node).probability()); + } catch (Throwable t) { + nodeDict.put("probability", t); + } + } + } + + private static void processBlocks(DataDict graphDict, List blocks, SchedulePhase schedule) { + BlockMap> blockToNodes = schedule.getBlockToNodesMap(); DataList blockList = new DataList(); graphDict.put("blocks", blockList); @@ -206,6 +204,8 @@ List nodes = blockToNodes.get(block); if (nodes != null) { DataDict blockDict = new DataDict(); + blockList.add(blockDict); + blockDict.put("id", block.getId()); DataList nodeList = new DataList(); @@ -215,13 +215,14 @@ nodeList.add(getNodeId(node)); } - DataList successorList = new DataList(); - blockDict.put("successors", successorList); - for (Block successor : block.getSuccessors()) { - successorList.add(successor.getId()); + List successors = block.getSuccessors(); + if (successors != null && !successors.isEmpty()) { + DataList successorList = new DataList(); + blockDict.put("successors", successorList); + for (Block successor : successors) { + successorList.add(successor.getId()); + } } - - blockList.add(blockDict); } } } @@ -332,10 +333,18 @@ for (int i = 0; i < edges.getCount(); i++) { DataDict edgeDict = new DataDict(); String name = edges.getName(i); + Class fieldClass = edges.getType(i); edgeDict.put("name", name); - edgeDict.put("jtype", edges.getType(i).getName()); + edgeDict.put("jtype", fieldClass.getName()); + if (NodeList.class.isAssignableFrom(fieldClass)) { + edgeDict.put("isList", true); + } if (type == Type.Inputs) { - edgeDict.put("type", ((InputEdges) edges).getInputType(i)); + InputEdges inputEdges = ((InputEdges) edges); + edgeDict.put("type", inputEdges.getInputType(i)); + if (inputEdges.isOptional(i)) { + edgeDict.put("isOptional", true); + } } edgeInfoDict.put(name, edgeDict); }