public void removeInstruction(int index) { if (index >= instructionList.size() - 1) { throw new IndexOutOfBoundsException(); } MethodLocation toRemove = instructionList.get(index); toRemove.instruction = null; MethodLocation next = instructionList.get(index + 1); toRemove.mergeInto(next); instructionList.remove(index); int codeAddress = toRemove.codeAddress; for (int i = index; i < instructionList.size(); i++) { MethodLocation location = instructionList.get(i); location.index = i; location.codeAddress = codeAddress; Instruction instruction = location.getInstruction(); if (instruction != null) { codeAddress += instruction.getCodeUnits(); } else { assert i == instructionList.size() - 1; } } this.fixInstructions = true; }
public void replaceInstruction(int index, @Nonnull BuilderInstruction replacementInstruction) { if (index >= instructionList.size() - 1) { throw new IndexOutOfBoundsException(); } MethodLocation replaceLocation = instructionList.get(index); replacementInstruction.location = replaceLocation; BuilderInstruction old = replaceLocation.instruction; assert old != null; old.location = null; replaceLocation.instruction = replacementInstruction; // TODO: factor out index/address fix up loop int codeAddress = replaceLocation.codeAddress + replaceLocation.instruction.getCodeUnits(); for (int i = index + 1; i < instructionList.size(); i++) { MethodLocation location = instructionList.get(i); location.codeAddress = codeAddress; Instruction instruction = location.getInstruction(); if (instruction != null) { codeAddress += instruction.getCodeUnits(); } else { assert i == instructionList.size() - 1; } } this.fixInstructions = true; }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { Instruction11x instr = (Instruction11x) location.getInstruction(); int register = instr.getRegisterA(); return new ReturnOp(location, register); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { Instruction11x instr = (Instruction11x) location.getInstruction(); int register = instr.getRegisterA(); return new ThrowOp(location, register); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { ArrayPayload instr = (ArrayPayload) location.getInstruction(); int elementWidth = instr.getElementWidth(); List<Number> arrayElements = instr.getArrayElements(); return new FillArrayDataPayloadOp(location, elementWidth, arrayElements); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); int address = location.getCodeAddress(); int branchOffset = ((OffsetInstruction) location.getInstruction()).getCodeOffset(); int targetAddress = address + branchOffset; MethodLocation target = addressToLocation.get(targetAddress); Instruction31t instr = (Instruction31t) location.getInstruction(); int register = instr.getRegisterA(); return new SwitchOp(location, child, target, register); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int destRegister = ((OneRegisterInstruction) instruction).getRegisterA(); return new MonitorEnterOp(location, child, destRegister); } }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int destRegister = ((OneRegisterInstruction) instruction).getRegisterA(); return new MonitorExitOp(location, child, destRegister); } }
public Op create(MethodLocation location) { Instruction instruction = location.getInstruction(); Opcode opcode = instruction.getOpcode(); OpFactory opFactory = getOpFactory(opcode); return opFactory.create(location, addressToLocation, vm); }
public static MethodLocation getNextLocation(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation) { int address = location.getCodeAddress(); int nextAddress = address + location.getInstruction().getCodeUnits(); return addressToLocation.get(nextAddress); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); Label target = ((BuilderOffsetInstruction) instruction).getTarget(); int targetAddress = target.getCodeAddress(); MethodLocation child = addressToLocation.get(targetAddress); return new GotoOp(location, child); } }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction12x instr = (Instruction12x) location.getInstruction(); int destRegister = instr.getRegisterA(); int srcRegister = instr.getRegisterB(); return new UnaryMathOp(location, child, destRegister, srcRegister); }
private BuilderInstruction buildInstruction22t(Opcode opcode, int offset) { BuilderInstruction instruction = mock(BuilderInstruction.class, withSettings().extraInterfaces(Instruction22t.class)); when(location.getInstruction()).thenReturn(instruction); when(instruction.getLocation()).thenReturn(location); when(instruction.getCodeUnits()).thenReturn(0); when(instruction.getOpcode()).thenReturn(opcode); when(((Instruction22t) instruction).getRegisterA()).thenReturn(ARG1_REGISTER); when(((Instruction22t) instruction).getRegisterB()).thenReturn(ARG2_REGISTER); when(((Instruction22t) instruction).getCodeOffset()).thenReturn(offset); return instruction; }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction12x instr = (Instruction12x) location.getInstruction(); int destRegister = instr.getRegisterA(); int arrayRegister = instr.getRegisterB(); return new ArrayLengthOp(location, child, destRegister, arrayRegister, vm.getExceptionFactory()); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction22c instr = (Instruction22c) location.getInstruction(); int destRegister = instr.getRegisterA(); int instanceRegister = instr.getRegisterB(); FieldReference reference = (FieldReference) instr.getReference(); String fieldDescriptor = ReferenceUtil.getFieldDescriptor(reference); return new IGetOp(location, child, destRegister, instanceRegister, fieldDescriptor, vm); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction21c instr = (Instruction21c) location.getInstruction(); int destRegister = instr.getRegisterA(); TypeReference typeRef = (TypeReference) instr.getReference(); String className = typeRef.getType(); VirtualClass virtualClass = vm.getClassManager().getVirtualClass(className); return new NewInstanceOp(location, child, destRegister, virtualClass, vm); }
@Override public NewArrayOp create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction22c instr = (Instruction22c) location.getInstruction(); int destRegister = instr.getRegisterA(); int sizeRegister = instr.getRegisterB(); String arrayType = ReferenceUtil.getReferenceString(instr.getReference()); return new NewArrayOp(location, child, destRegister, sizeRegister, arrayType, vm.getClassLoader()); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction23x instr = (Instruction23x) location.getInstruction(); int putRegister = instr.getRegisterA(); int arrayRegister = instr.getRegisterB(); int indexRegister = instr.getRegisterC(); return new APutOp(location, child, putRegister, arrayRegister, indexRegister, vm.getClassManager(), vm.getExceptionFactory()); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction22c instr = (Instruction22c) location.getInstruction(); int destRegister = instr.getRegisterA(); int arg1Register = instr.getRegisterB(); TypeReference typeReference = (TypeReference) instr.getReference(); VirtualType referenceType = vm.getClassManager().getVirtualType(typeReference); return new InstanceOfOp(location, child, destRegister, arg1Register, referenceType, vm); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction21c instr = (Instruction21c) location.getInstruction(); int destRegister = instr.getRegisterA(); FieldReference fieldReference = (FieldReference) instr.getReference(); VirtualClass fieldClass = vm.getClassManager().getVirtualClass(fieldReference.getDefiningClass()); VirtualField actualField = fieldClass.getField(fieldReference.getName()); return new SGetOp(location, child, destRegister, fieldReference, actualField, vm); }