public ExecutionGraph spawnInstructionGraph(String className, String methodDescriptor) { VirtualMethod method = getClassManager().getVirtualClass(className).getMethod(methodDescriptor); return spawnInstructionGraph(method); }
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 hasExpectedTerminatingAddresses() { String methodDescriptor = "terminatingAddresses()V"; VirtualMethod method = virtualClass.getMethod(methodDescriptor); ExecutionGraph graph = vm.spawnInstructionGraph(method); int[] expected = new int[]{ 6, 7, 8, 9, 10, 12 }; int[] actual = graph.getTerminatingAddresses(); assertArrayEquals(expected, actual); }
VirtualMethod method = virtualClass.getMethod(METHOD_DESCRIPTOR); ExecutionGraph graph = vm.spawnInstructionGraph(method);
@Test public void monitorEnterHasExpectedTostring() { String methodDescriptor = "monitorExit()V"; VirtualMachine vm = VMTester.spawnVM(); ExecutionGraph graph = vm.spawnInstructionGraph(CLASS_NAME, methodDescriptor); ExecutionNode node = graph.getTemplateNode(1); assertEquals("monitor-exit r0", node.getOp().toString()); } }
@Test public void monitorEnterHasExpectedTostring() { String methodDescriptor = "monitorEnter()V"; VirtualMachine vm = VMTester.spawnVM(); ExecutionGraph graph = vm.spawnInstructionGraph(CLASS_NAME, methodDescriptor); ExecutionNode node = graph.getTemplateNode(1); assertEquals("monitor-enter r0", node.getOp().toString()); } }
@Test public void hasExpectedToString() { VirtualMachine vm = VMTester.spawnVM(); VirtualClass virtualClass = vm.getClassManager().getVirtualClass(CLASS_NAME); VirtualMethod method = virtualClass.getMethod("invokeReturnVoid()V"); ExecutionGraph graph = vm.spawnInstructionGraph(method); Op op = graph.getOp(0); assertEquals("invoke-static {}, " + CLASS_NAME + "->returnVoid()V", op.toString()); } }