private boolean reserveRegisters(Dop[] opcodes) {
    boolean reservedCountExpanded = false;
    int oldReservedCount = (reservedCount < 0) ? 0 : reservedCount;

    /*
     * Call calculateReservedCount() and then perform register
     * reservation, repeatedly until no new reservations happen.
     */
    for (; ; ) {
      int newReservedCount = calculateReservedCount(opcodes);
      if (oldReservedCount >= newReservedCount) {
        break;
      }

      reservedCountExpanded = true;

      int reservedDifference = newReservedCount - oldReservedCount;
      int size = insns.size();

      for (int i = 0; i < size; i++) {
        /*
         * CodeAddress instance identity is used to link
         * TargetInsns to their targets, so it is
         * inappropriate to make replacements, and they don't
         * have registers in any case. Hence, the instanceof
         * test below.
         */
        DalvInsn insn = insns.get(i);
        if (!(insn instanceof CodeAddress)) {
          /*
           * No need to call this.set() since the format and
           * other info are the same.
           */
          insns.set(i, insn.withRegisterOffset(reservedDifference));
        }
      }

      oldReservedCount = newReservedCount;
    }

    reservedCount = oldReservedCount;

    return reservedCountExpanded;
  }
Helper for {@link #finishProcessingAndGetList}, which figures out how many reserved registers
are required and then reserving them. It also updates the given {@code opcodes} array so as to
avoid extra work when constructing the massaged instruction list.

@param opcodes {@code non-null;} array of per-instruction opcode selections
@return true if reservedCount is expanded, false otherwise
android/android_framework/dex-maker/src/main/java/com/android/dx/dex/code/OutputFinisher.java