public void setPseudoInstructionReturnLocation(MethodLocation location) { // Pseudo instructions like array-data-payload need return addresses. pokeRegister(ReturnAddressRegister, location, METHOD_HEAP); }
public void assignReturnRegister(HeapItem item) { pokeRegister(ReturnRegister, item, METHOD_HEAP); }
public void assignThrowRegister(HeapItem item) { pokeRegister(ThrowRegister, item, METHOD_HEAP); }
public void pokeRegister(int register, HeapItem item) { pokeRegister(register, item, METHOD_HEAP); }
public void assignReturnRegister(Object value, String type) { pokeRegister(ReturnRegister, new HeapItem(value, type), METHOD_HEAP); }
public void pokeRegister(int register, Object value, String type) { pokeRegister(register, new HeapItem(value, type)); }
public void assignExceptionRegister(Throwable exception) { String className = ClassNameUtils.toInternal(exception.getClass()); HeapItem item = new HeapItem(exception, className); pokeRegister(ExceptionRegister, item, METHOD_HEAP); }
public void assignParameter(int parameterRegister, HeapItem item) { assignRegister(parameterRegister, item, METHOD_HEAP); boolean mutable = !item.isImmutable(); if (mutable) { pokeRegister(parameterRegister, item, MUTABLE_PARAMETER_HEAP); mutableParameters.add(parameterRegister); } }
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); }
@Override public void execute(ExecutionNode node, MethodState mState) { MethodState parent = mState.getParent(); int targetRegister = parent.getRegistersAssigned()[0]; // Peek rather than read. This pseudo-instruction shouldn't count as an actual usage for the optimizer. HeapItem arrayItem = mState.peekRegister(targetRegister); if (!arrayItem.isUnknown()) { Object array = arrayItem.getValue(); Class<?> expectedClass = array.getClass().getComponentType(); for (int i = 0; i < arrayElements.size(); i++) { Number number = arrayElements.get(i); Object value = getProperValue(number, expectedClass); Array.set(array, i, value); } // Poke rather than assign for the optimizer. mState.pokeRegister(targetRegister, arrayItem); } MethodLocation returnLocation = mState.getParent().getPseudoInstructionReturnInstruction(); node.setChildLocations(returnLocation); }
private static ExecutionContextMethod test(VirtualMachine vm, ExecutionContext context, String fieldName, String callingMethodSignature, boolean setAccessible) throws Exception { // Setup caller context ExecutionContext callerContext = vm.spawnRootContext(callingMethodSignature); Field callerContextField = ExecutionContext.class.getDeclaredField("callerContext"); callerContextField.setAccessible(true); callerContextField.set(context, callerContext); // Setup actual field to use as parameter ClassLoader classLoader = vm.getClassLoader(); Class<?> klazz = classLoader.loadClass(DUMMY_CLASS_NAME_BINARY); Constructor<?> ctor = klazz.getDeclaredConstructor(); ctor.setAccessible(true); Object instance = ctor.newInstance(); Field field = instance.getClass().getDeclaredField(fieldName); field.setAccessible(setAccessible); // Setup method state and arguments HeapItem fieldItem = new HeapItem(field, "Ljava/lang/reflect/Field;"); HeapItem instanceItem = new HeapItem(instance, DUMMY_CLASS_NAME); MethodState methodState = context.getMethodState(); methodState.pokeRegister(0, fieldItem); methodState.pokeRegister(1, instanceItem); ExecutionContextMethod fieldGet = new java_lang_reflect_Field_get(); fieldGet.execute(vm, null, context); return fieldGet; }
callerMethodState.pokeRegister(register, item);