ExecutionGraphIterator(ExecutionGraph graph) { stack = new ArrayDeque<>(); ExecutionNode rootNode = graph.getRoot(); if (rootNode != null) { stack.push(rootNode); } }
public static String graph(ExecutionGraph graph) { ExecutionNode node = graph.getRoot(); StringBuilder sb = new StringBuilder("digraph {\n"); getGraph(node, graph, sb, new ArrayList<>()); sb.append("labelloc=\"t\"\n"); sb.append("label=\"").append(graph.getMethod()).append("\";\n"); sb.append('}'); return sb.toString(); }
ExecutionGraph execute(ExecutionGraph graph) throws VirtualMachineException { TIntIntMap addressToVisitCount = new TIntIntHashMap(); VirtualMethod method = graph.getMethod(); ExecutionNode node = graph.getRoot(); int callDepth = node.getCallDepth(); if (node.getCallDepth() > getMaxCallDepth()) {
@Test public void testHasExpectedGraph() { ExecutionNode child = buildNode(CHILD_ADDRESS, CHILD_NODE_STR, CHILD_STATE_STR); when(child.getChildren()).thenReturn(new LinkedList<ExecutionNode>()); ExecutionNode root = buildNode(ROOT_ADDRESS, ROOT_NODE_STR, ROOT_STATE_STR); List<ExecutionNode> children = new LinkedList<ExecutionNode>(); children.add(child); when(root.getChildren()).thenReturn(children); VirtualMethod localMethod = mock(VirtualMethod.class); when(localMethod.toString()).thenReturn(METHOD_SIGNATURE); ExecutionGraph graph = mock(ExecutionGraph.class); when(graph.getRoot()).thenReturn(root); when(graph.getMethod()).thenReturn(localMethod); when(graph.getNodeIndex(root)).thenReturn(0); when(graph.getNodeIndex(child)).thenReturn(0); String digraph = ExecutionGrapher.graph(graph); StringBuilder sb = new StringBuilder("digraph {\n"); sb.append("\"@").append(ROOT_ADDRESS).append(".0 :: ").append(ROOT_NODE_STR).append('\n'); sb.append(ROOT_STATE_STR).append("\" -> "); sb.append("\"@").append(CHILD_ADDRESS).append(".0 :: ").append(CHILD_NODE_STR).append('\n'); sb.append(CHILD_STATE_STR).append("\"\n"); sb.append("labelloc=\"t\"\n"); sb.append("label=\"").append(METHOD_SIGNATURE).append("\";"); sb.append("\n}"); String expected = sb.toString(); assertEquals(expected, digraph); }
public ExecutionGraph execute(VirtualMethod virtualMethod, ExecutionContext calleeContext, ExecutionContext callerContext, int[] parameterRegisters) throws VirtualMachineException { if (!virtualMethod.hasImplementation()) { log.warn("Attempting to execute method without implementation: {}", virtualMethod); return null; } if (callerContext != null) { inheritClassStates(callerContext, calleeContext); } calleeContext.staticallyInitializeClassIfNecessary(virtualMethod.getDefiningClass()); ExecutionGraph graph = spawnInstructionGraph(virtualMethod); ExecutionNode rootNode = new ExecutionNode(graph.getRoot()); rootNode.setContext(calleeContext); graph.addNode(rootNode); ExecutionGraph execution = methodExecutor.execute(graph); if ((execution != null) && (callerContext != null)) { collapseMultiverse(virtualMethod, graph, callerContext, parameterRegisters); } return execution; }
@Test public void hasExpectedToString() { ExecutionGraph graph = VMTester.execute(CLASS_NAME, "simpleLoop()V"); ExecutionNode node = graph.getRoot(); MethodState state = node.getContext().getMethodState(); String expected = "params: 0, locals: 2\nv0: type=I, value=0"; assertEquals(expected, state.toString()); } }