@Nonnull private BuilderInstruction31t newBuilderInstruction31t(@Nonnull MethodLocation location, int[] codeAddressToIndex, @Nonnull Instruction31t instruction) { int codeAddress = location.getCodeAddress(); Label newLabel; if (instruction.getOpcode() != Opcode.FILL_ARRAY_DATA) { // if it's a sparse switch or packed switch newLabel = newSwitchPayloadReferenceLabel(location, codeAddressToIndex, codeAddress + instruction.getCodeOffset()); } else { newLabel = newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()); } return new BuilderInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), newLabel); }
int destRegister = fillArrayInstr.getRegisterA(); int offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset;
@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); }
int offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset;
instructions.add(new ArrayFill(instLoc, ((Instruction31t)inst).getRegisterA(), ((Instruction31t)inst).getCodeOffset(), TypeReference.findOrCreate(myClass.getClassLoader().getReference(), arrayElementType.getName().toString()), inst.getOpcode(), this)); break; instructions.add(new Switch(instLoc, ((Instruction31t)inst).getRegisterA(), ((Instruction31t)inst).getCodeOffset(), inst.getOpcode(), this)); break;
targetOffset = endOffset; effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits(); targetOffset = endOffset; effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits();
case PACKED_SWITCH: int baseAddress = methodDef.getPackedSwitchBaseAddress( this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case SPARSE_SWITCH: baseAddress = methodDef.getSparseSwitchBaseAddress( this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case FILL_ARRAY_DATA: try { methodDef.findPayloadOffset(this.codeAddress + ((Instruction31t)instruction).getCodeOffset(), Opcode.ARRAY_PAYLOAD); } catch (InvalidSwitchPayload ex) {
public static ImmutableInstruction31t of(Instruction31t instruction) { if (instruction instanceof ImmutableInstruction31t) { return (ImmutableInstruction31t)instruction; } return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), instruction.getCodeOffset()); }
instructions.add(new ArrayFill(instLoc, ((Instruction31t)inst).getRegisterA(), ((Instruction31t)inst).getCodeOffset(), TypeReference.findOrCreate(myClass.getClassLoader().getReference(), arrayElementType.getName().toString()), inst.getOpcode(), this)); break; instructions.add(new Switch(instLoc, ((Instruction31t)inst).getRegisterA(), ((Instruction31t)inst).getCodeOffset(), inst.getOpcode(), this)); break;
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { BuilderInstruction instruction = (BuilderInstruction) location.getInstruction(); int address = instruction.getLocation().getCodeAddress(); int returnAddress = address + instruction.getCodeUnits(); MethodLocation returnLocation = addressToLocation.get(returnAddress); int branchOffset = ((OffsetInstruction) instruction).getCodeOffset(); int childAddress = address + branchOffset; MethodLocation child = addressToLocation.get(childAddress); Instruction31t instr = (Instruction31t) location.getInstruction(); int register = instr.getRegisterA(); return new FillArrayDataOp(location, child, returnLocation, register); } }
@Test public void testPayloadAlignmentAddNopWithReferent() { MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10); Label label = implBuilder.getLabel("array_payload"); implBuilder.addInstruction(new BuilderInstruction31t(Opcode.FILL_ARRAY_DATA, 0, label)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addLabel("array_payload"); implBuilder.addInstruction(new BuilderArrayPayload(4, null)); List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions()); checkInstructions(instructions, new Opcode[]{Opcode.FILL_ARRAY_DATA, Opcode.MOVE, Opcode.MOVE, Opcode.MOVE, Opcode.MOVE, Opcode.NOP, Opcode.ARRAY_PAYLOAD}); Instruction31t referent = (Instruction31t)instructions.get(0); Assert.assertEquals(8, referent.getCodeOffset()); }
public static ImmutableInstruction31t of(Instruction31t instruction) { if (instruction instanceof ImmutableInstruction31t) { return (ImmutableInstruction31t)instruction; } return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), instruction.getCodeOffset()); }
int interestingRegister = arrayFill.getRegisterA(); int curCounter = instCounter - 1;
@Test public void testPayloadAlignmentRemoveNopWithReferent() { MethodImplementationBuilder implBuilder = new MethodImplementationBuilder(10); Label label = implBuilder.getLabel("array_payload"); implBuilder.addInstruction(new BuilderInstruction31t(Opcode.FILL_ARRAY_DATA, 0, label)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction12x(Opcode.MOVE, 0, 0)); implBuilder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); implBuilder.addLabel("array_payload"); implBuilder.addInstruction(new BuilderArrayPayload(4, null)); List<Instruction> instructions = Lists.newArrayList(implBuilder.getMethodImplementation().getInstructions()); checkInstructions(instructions, new Opcode[]{Opcode.FILL_ARRAY_DATA, Opcode.MOVE, Opcode.MOVE, Opcode.MOVE, Opcode.ARRAY_PAYLOAD}); Instruction31t referent = (Instruction31t)instructions.get(0); Assert.assertEquals(6, referent.getCodeOffset()); }
public static ImmutableInstruction31t of(Instruction31t instruction) { if (instruction instanceof ImmutableInstruction31t) { return (ImmutableInstruction31t)instruction; } return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), instruction.getCodeOffset()); }
int interestingRegister = arrayFill.getRegisterA(); int curCounter = instCounter - 1;
case PACKED_SWITCH: int baseAddress = methodDef.getPackedSwitchBaseAddress(this.codeAddress + ((Instruction31t) instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case SPARSE_SWITCH: baseAddress = methodDef.getSparseSwitchBaseAddress(this.codeAddress + ((Instruction31t) instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case FILL_ARRAY_DATA: try { methodDef.findPayloadOffset(this.codeAddress + ((Instruction31t) instruction).getCodeOffset(), Opcode.ARRAY_PAYLOAD); } catch (MethodDefinition.InvalidSwitchPayload ex) {
public void write(@Nonnull Instruction31t instruction) { try { writer.write(instruction.getOpcode().value); writer.write(instruction.getRegisterA()); writer.writeInt(instruction.getCodeOffset()); } catch (IOException ex) { throw new RuntimeException(ex); } }
targetOffset = endOffset; effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits(); targetOffset = endOffset; effectiveInstructions.set(i, new ImmutableInstruction31t(opcode, ((Instruction31t)instruction).getRegisterA(), targetOffset-codeOffset)); effectiveInstructions.add(payloadInstruction); endOffset += payloadInstruction.getCodeUnits();
case PACKED_SWITCH: int baseAddress = methodDef.getPackedSwitchBaseAddress( this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case SPARSE_SWITCH: baseAddress = methodDef.getSparseSwitchBaseAddress( this.codeAddress + ((Instruction31t)instruction).getCodeOffset()); if (baseAddress == -1) { validPayload = false; case FILL_ARRAY_DATA: try { methodDef.findPayloadOffset(this.codeAddress + ((Instruction31t)instruction).getCodeOffset(), Opcode.ARRAY_PAYLOAD); } catch (InvalidSwitchPayload ex) {