private void visitForward(NodeBitMap visited, Node node) { if (node != null && !visited.isMarked(node)) { visited.mark(node); if (node.predecessor() != null) { visitForward(visited, node.predecessor()); } if (node instanceof MergeNode) { // make sure that the cfg predecessors of a MergeNode are processed first MergeNode merge = (MergeNode) node; for (int i = 0; i < merge.forwardEndCount(); i++) { visitForward(visited, merge.forwardEndAt(i)); } } for (Node input : node.inputs()) { visitForward(visited, input); } if (node instanceof LoopBeginNode) { LoopBeginNode loopBegin = (LoopBeginNode) node; for (LoopEndNode loopEnd : loopBegin.loopEnds()) { visitForward(visited, loopEnd); } } nodes.add(node); } }
private void visitBackward(NodeBitMap visited, Node node) { if (node != null && !visited.isMarked(node)) { visited.mark(node); for (Node successor : node.successors()) { visitBackward(visited, successor); } for (Node usage : node.usages()) { visitBackward(visited, usage); } nodes.add(node); } }
/** * Gets an approximate source code location for a node if possible. * * @return the StackTraceElements if an approximate source location is found, null otherwise */ public static StackTraceElement[] approxSourceStackTraceElement(Node node) { ArrayList<StackTraceElement> elements = new ArrayList<>(); Node n = node; while (n != null) { if (n instanceof MethodCallTargetNode) { elements.add(((MethodCallTargetNode) n).targetMethod().asStackTraceElement(-1)); n = ((MethodCallTargetNode) n).invoke().asNode(); } if (n instanceof StateSplit) { FrameState state = ((StateSplit) n).stateAfter(); while (state != null) { ResolvedJavaMethod method = state.method(); if (method != null) { elements.add(method.asStackTraceElement(state.bci - 1)); } state = state.outerFrameState(); } break; } n = n.predecessor(); } return elements.toArray(new StackTraceElement[elements.size()]); }