public final void mergeUnsorted() {
      getSection(contentsOut).off = out.getPosition();

      List<UnsortedValue> all = new ArrayList<UnsortedValue>();
      for (int i = 0; i < dexes.length; i++) {
        all.addAll(readUnsortedValues(dexes[i], indexMaps[i]));
      }
      if (all.isEmpty()) {
        getSection(contentsOut).off = 0;
        getSection(contentsOut).size = 0;
        return;
      }
      Collections.sort(all);

      int outCount = 0;
      for (int i = 0; i < all.size(); ) {
        UnsortedValue e1 = all.get(i++);
        updateIndex(e1.offset, e1.indexMap, e1.index, outCount - 1);

        while (i < all.size() && e1.compareTo(all.get(i)) == 0) {
          UnsortedValue e2 = all.get(i++);
          updateIndex(e2.offset, e2.indexMap, e2.index, outCount - 1);
        }

        write(e1.value);
        outCount++;
      }

      getSection(contentsOut).size = outCount;
    }
Merges unsorted sections by reading them completely into memory and sorting in memory.
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java