public HeapItem readResultRegister() { HeapItem item = readRegister(ResultRegister, METHOD_HEAP); return item; }
public HeapItem readRegister(int register) { return readRegister(register, METHOD_HEAP); }
public HeapItem readReturnRegister() { return readRegister(ReturnRegister); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(register); mState.assignReturnRegister(item); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(register); mState.assignThrowRegister(item); }
@Override public void execute(ExecutionNode node, ExecutionContext context) { MethodState mState = context.getMethodState(); HeapItem valueItem = mState.readRegister(valueRegister); HeapItem instanceItem = mState.readRegister(instanceRegister); mState.assignRegister(instanceRegister, instanceItem); }
private static void moveRegister(MethodState mState, int toRegister, int fromRegister) { HeapItem item = mState.readRegister(fromRegister); mState.assignRegister(toRegister, item); }
@Override public void execute(ExecutionNode node, MethodState mState) { // Use result register to store value to compare. Comparison is handled by payload op. HeapItem item = mState.readRegister(register); mState.assignResultRegister(item); // If switch "falls through", will need the immediate op after this. mState.setPseudoInstructionReturnLocation(child); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(register); // Mark register as assigned because next op will be payload, and it uses assigned register in this op to // determine target register for payload. mState.assignRegister(register, item); // It needs to know return address when finished since payload ops do not continue to next address. mState.setPseudoInstructionReturnLocation(returnLocation); }
@Override public void execute(ExecutionNode node, ExecutionContext context) { // TODO: https://github.com/CalebFenton/simplify/issues/22 MethodState mState = context.getMethodState(); HeapItem instanceItem = mState.readRegister(instanceRegister); String type = fieldDescriptor.split(":")[1]; mState.assignRegister(destRegister, HeapItem.newUnknown(type)); }
@Override public void execute(ExecutionNode node, ExecutionContext context) { MethodState mState = context.getMethodState(); HeapItem item = mState.readRegister(valueRegister); // TODO: check if this is <clinit> and only allow static final fields to be initialized here vm.getStaticFieldAccessor().putField(context, actualField, item); }
public static void setRegisterMock(MethodState mState, int register, Object value, String type) { HeapItem item = mock(HeapItem.class); when(item.getValue()).thenReturn(value); if (CommonTypes.INTEGER.equals(type) && value instanceof Number) { when(item.asInteger()).thenReturn((Integer) value); } else if (value instanceof UnknownValue) { when(item.isUnknown()).thenReturn(true); } when(item.getComponentBase()).thenReturn(ClassNameUtils.getComponentBase(type)); when(item.getType()).thenReturn(type); when(mState.readRegister(eq(register))).thenReturn(item); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem lhsItem = mState.readRegister(lhsRegister); HeapItem rhsItem = mState.readRegister(rhsRegister); HeapItem item; if (lhsItem.isUnknown() || rhsItem.isUnknown()) { item = HeapItem.newUnknown("I"); } else { Number lhs = (Number) lhsItem.getValue(); Number rhs = (Number) rhsItem.getValue(); assert lhs.getClass() == rhs.getClass(); assert lhsItem.getType().equals(rhsItem.getType()); int cmp = cmp(lhs, rhs); item = new HeapItem(cmp, "I"); } mState.assignRegister(destRegister, item); }
@Test public void testIGetReturnsUnknownValueOfCorrectType() { when(instruction.getOpcode()).thenReturn(Opcode.IPUT); op = (IPutOp) opFactory.create(location, addressToLocation, vm); op.execute(node, ectx); verify(mState, times(1)).readRegister(eq(REGISTER_A)); verify(mState, times(1)).readRegister(eq(REGISTER_B)); verify(mState, times(1)).assignRegister(eq(REGISTER_B), any(HeapItem.class)); assertEquals("iput r" + REGISTER_A + ", r" + REGISTER_B + ", Lsome/class;->someMethod:I", op.toString()); }
private void doTest(Number... values) { when(instruction.getOpcode()).thenReturn(Opcode.FILLED_NEW_ARRAY_RANGE); when(((VariableRegisterInstruction) instruction).getRegisterCount()).thenReturn(values.length); when(((RegisterRangeInstruction) instruction).getStartRegister()).thenReturn(0); int[] expected = new int[values.length]; for (int i = 0; i < expected.length; i++) { expected[i] = values[i].intValue(); HeapItem item = mock(HeapItem.class); when(item.getValue()).thenReturn(expected[i]); when(item.getType()).thenReturn("I"); when(mState.readRegister(i)).thenReturn(item); } op = (FilledNewArrayOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); for (int i = 0; i < expected.length; i++) { verify(mState, times(1)).readRegister(eq(i)); } verify(mState, times(1)).assignResultRegister(eq(expected), eq("[I")); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem lengthItem = mState.readRegister(lengthRegister); Object instance = buildInstance(lengthItem); if (instance instanceof Throwable) { node.setException((Throwable) instance); node.clearChildren(); return; } else { node.clearExceptions(); } mState.assignRegister(destRegister, instance, arrayType); }
@Test public void testIGetReturnsUnknownValueOfCorrectType() { when(instruction.getOpcode()).thenReturn(Opcode.IGET); op = (IGetOp) opFactory.create(location, addressToLocation, vm); op.execute(node, ectx); verify(mState, times(1)).readRegister(eq(REGISTER_B)); verify(mState, times(1)).assignRegister(eq(REGISTER_A), setItem.capture()); assertEquals(UnknownValue.class, setItem.getValue().getValue().getClass()); assertEquals("I", setItem.getValue().getType()); assertEquals("iget r" + REGISTER_A + ", r" + REGISTER_B + ", Lsome/class;->someMethod:I", op.toString()); }
@Test public void testUnknownValueGivesUnknownArray() { when(instruction.getOpcode()).thenReturn(Opcode.FILLED_NEW_ARRAY); when(((VariableRegisterInstruction) instruction).getRegisterCount()).thenReturn(2); when(itemD.getValue()).thenReturn(new UnknownValue()); when(itemD.isUnknown()).thenReturn(true); when(itemC.getValue()).thenReturn(3); op = (FilledNewArrayOp) opFactory.create(location, addressToLocation, vm); op.execute(node, mState); verify(mState, times(1)).readRegister(eq(REGISTER_D)); verify(mState, times(1)).readRegister(eq(REGISTER_C)); ArgumentCaptor<HeapItem> setItem = ArgumentCaptor.forClass(HeapItem.class); verify(mState, times(1)).assignResultRegister(setItem.capture()); assertEquals(UnknownValue.class, setItem.getValue().getValue().getClass()); assertEquals("[I", setItem.getValue().getType()); assertEquals("filled-new-array {r0, r1}, [I", op.toString()); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(srcRegister); HeapItem resultItem; String type = getResultTypeName(getName()); if (item.isUnknown()) { resultItem = HeapItem.newUnknown(type); } else { Object resultValue = perform(item.getValue(), getName()); resultItem = new HeapItem(resultValue, type); } mState.assignRegister(destRegister, resultItem); }
@Override public void execute(ExecutionNode node, MethodState mState) { HeapItem item = mState.readRegister(targetRegister); boolean isInstance = isInstance(item, castType, classManager); if (isInstance) { node.clearExceptions(); mState.assignRegister(targetRegister, item.getValue(), castType.getName()); } else { // E.g. java.lang.ClassCastException: java.lang.String cannot be cast to java.io.File String error = ClassNameUtils.internalToBinary(item.getType()) + " cannot be cast to " + castType.getBinaryName(); Throwable exception = exceptionFactory.build(this, ClassCastException.class, error); node.setException(exception); if (!item.isUnknown()) { // Exception is certain to happen since we had all class information // exception is certain. node.clearChildren(); } } }