@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 offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset;
int offset = fillArrayInstr.getCodeOffset(); int targetAddress = codeAddress + offset;
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()); }
public static ImmutableInstruction31t of(Instruction31t instruction) { if (instruction instanceof ImmutableInstruction31t) { return (ImmutableInstruction31t)instruction; } return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), instruction.getCodeOffset()); }
@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); }
@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); }
@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); }
public static ImmutableInstruction31t of(Instruction31t instruction) { if (instruction instanceof ImmutableInstruction31t) { return (ImmutableInstruction31t)instruction; } return new ImmutableInstruction31t( instruction.getOpcode(), instruction.getRegisterA(), instruction.getCodeOffset()); }
@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); }
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); } }
public void write(@Nonnull Instruction31t instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterA()); writer.writeInt(instruction.getCodeOffset()); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void write(@Nonnull Instruction31t instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterA()); writer.writeInt(instruction.getCodeOffset()); } catch (IOException ex) { throw new RuntimeException(ex); } }
@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()); }
@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()); }
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) {
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;
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) {
methodDef.findSwitchPayload(this.codeAddress + ((Instruction31t)instruction).getCodeOffset(), payloadOpcode); } catch (InvalidSwitchPayload ex) {