Example #1
0
  private static ExecutionContext buildInitializedContext(
      VirtualMachine vm, String methodSignature, VMState state) {
    VirtualMethod method = vm.getClassManager().getMethod(methodSignature);
    ExecutionContext context = vm.spawnRootContext(method);
    int registerCount = context.getMethodState().getRegisterCount();
    setupMethodState(context, state.getRegisters(), registerCount);
    setupClassStates(context, vm, state.getFields());

    return context;
  }
Example #2
0
 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);
 }
Example #3
0
 private static void setupClassStates(
     ExecutionContext context,
     VirtualMachine vm,
     Map<String, Map<String, HeapItem>> classNameToFieldDescriptorToItem) {
   ClassManager classManager = vm.getClassManager();
   for (Entry<String, Map<String, HeapItem>> entry : classNameToFieldDescriptorToItem.entrySet()) {
     String className = entry.getKey();
     VirtualClass virtualClass = classManager.getVirtualClass(className);
     Map<String, HeapItem> fieldDescriptorToItem = entry.getValue();
     ClassState cState = context.peekClassState(virtualClass);
     for (Entry<String, HeapItem> fieldNameAndTypeToItem : fieldDescriptorToItem.entrySet()) {
       String fieldNameAndType = fieldNameAndTypeToItem.getKey();
       String fieldName = fieldNameAndType.split(":")[0];
       VirtualField field = virtualClass.getField(fieldName);
       HeapItem item = fieldNameAndTypeToItem.getValue();
       cState.pokeField(field, item);
     }
     context.initializeClass(cState, SideEffect.Level.NONE);
   }
 }
Example #4
0
 @Override
 public void execute(ExecutionNode node, ExecutionContext ectx) {
   HeapItem item = vm.getStaticFieldAccessor().getField(ectx, fieldDescriptor);
   MethodState mState = ectx.getMethodState();
   mState.assignRegister(destRegister, item);
 }