public void setMethodState(MethodState mState) { context.setMethodState(mState); }
public void setParent(ExecutionContext parent) { setShallowParent(parent); MethodState childMethodState = parent.getMethodState().getChild(this); setMethodState(childMethodState); }
private static void setupMethodState(ExecutionContext context, Map<Integer, HeapItem> registerToItem, int registerCount) { MethodState mState = new MethodState(context, registerCount); for (Entry<Integer, HeapItem> entry : registerToItem.entrySet()) { Integer register = entry.getKey(); HeapItem item = entry.getValue(); mState.pokeRegister(register, item); } context.setMethodState(mState); }
public ExecutionContext spawnRootContext(VirtualMethod method, @Nullable ExecutionContext callerContext, int callerAddress) { if (!method.hasImplementation()) { // Native or abstract methods have no implementation. Shouldn't be executing them. throw new IllegalArgumentException("No implementation for " + method); } ExecutionContext spawnedContext = new ExecutionContext(this, method); ClassState templateClassState = TemplateStateFactory.forClass(spawnedContext, method.getDefiningClass()); spawnedContext.setClassState(templateClassState); MethodState templateMethodState = TemplateStateFactory.forMethod(spawnedContext); spawnedContext.setMethodState(templateMethodState); if (callerContext != null) { spawnedContext.registerCaller(callerContext, callerAddress); } return spawnedContext; }
private ExecutionContext buildNonLocalCalleeContext(ExecutionContext callerContext) { ExecutionContext calleeContext = new ExecutionContext(vm, method); int parameterSize = method.getParameterSize(); int registerCount = parameterSize; MethodState calleeMethodState = new MethodState(calleeContext, registerCount, method.getParameterTypeNames().size(), parameterSize); assignCalleeMethodArguments(callerContext.getMethodState(), calleeMethodState); calleeContext.setMethodState(calleeMethodState); calleeContext.registerCaller(callerContext, getAddress()); return calleeContext; }
@Test public void methodStateForVirtualMethodCreatedCorrectly() throws VirtualMachineException { String methodDescriptor = "someString()Ljava/lang/String;"; VirtualMethod method = vm.getClassManager().getMethod(CLASS_NAME, methodDescriptor); ExecutionContext spawnedContext = new ExecutionContext(vm, method); ClassState templateClassState = TemplateStateFactory.forClass(spawnedContext, method.getDefiningClass()); spawnedContext.setClassState(templateClassState); MethodState templateMethodState = TemplateStateFactory.forMethod(spawnedContext); spawnedContext.setMethodState(templateMethodState); assertEquals(2, templateMethodState.getRegisterCount()); assertEquals(1, templateMethodState.getParameterCount()); int instanceRegister = templateMethodState.getParameterStart(); assertEquals(1, instanceRegister); HeapItem instanceItem = templateMethodState.peekRegister(instanceRegister); assertEquals(CLASS_NAME, instanceItem.getType()); assertEquals(UnknownValue.class, instanceItem.getValue().getClass()); }
@Test public void methodStateForObjectInitializationMethodCreatedCorrectly() throws VirtualMachineException { String methodDescriptor = "<init>()V"; VirtualMethod method = vm.getClassManager().getMethod(CLASS_NAME, methodDescriptor); ExecutionContext spawnedContext = new ExecutionContext(vm, method); ClassState templateClassState = TemplateStateFactory.forClass(spawnedContext, method.getDefiningClass()); spawnedContext.setClassState(templateClassState); MethodState templateMethodState = TemplateStateFactory.forMethod(spawnedContext); spawnedContext.setMethodState(templateMethodState); assertEquals(1, templateMethodState.getRegisterCount()); assertEquals(1, templateMethodState.getParameterCount()); int instanceRegister = templateMethodState.getParameterStart(); assertEquals(0, instanceRegister); HeapItem instanceItem = templateMethodState.peekRegister(instanceRegister); assertEquals(CLASS_NAME, instanceItem.getType()); assertEquals(UninitializedInstance.class, instanceItem.getValue().getClass()); }