public void initializeClass(ClassState cState, SideEffect.Level level) { setClassState(cState); setClassInitialized(cState.getVirtualClass(), level); }
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; }
public ClassState peekClassState(VirtualType virtualClass) { ExecutionContext ancestor = getAncestorWithClass(virtualClass); if (ancestor == null) { // VirtualClass has not been initialized; build template and cache it locally to track initialization state ClassState templateClassState = TemplateStateFactory.forClass(this, virtualClass); setClassState(templateClassState); return templateClassState; } else if (ancestor != this) { ClassState ancestorClassState = ancestor.peekClassState(virtualClass); ClassState cState = ancestorClassState.getChild(this); SideEffect.Level level = ancestor.getClassSideEffectLevel(virtualClass); // Must initialize, because the ancestor probably just has the template class state. initializeClass(cState, level); return cState; } return classToStatus.get(virtualClass).getClassState(); }
@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()); }
@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()); }