private void plus(TableOfContents contents, boolean exact) {
      idsDefs +=
          contents.stringIds.size * SizeOf.STRING_ID_ITEM
              + contents.typeIds.size * SizeOf.TYPE_ID_ITEM
              + contents.protoIds.size * SizeOf.PROTO_ID_ITEM
              + contents.fieldIds.size * SizeOf.MEMBER_ID_ITEM
              + contents.methodIds.size * SizeOf.MEMBER_ID_ITEM
              + contents.classDefs.size * SizeOf.CLASS_DEF_ITEM;
      mapList = SizeOf.UINT + (contents.sections.length * SizeOf.MAP_ITEM);
      typeList += fourByteAlign(contents.typeLists.byteCount); // We count each dex's
      // typelists section as realigned on 4 bytes, because each typelist of each dex's
      // typelists section is aligned on 4 bytes. If we didn't, there is a case where each
      // size of both dex's typelists section is a multiple of 2 but not a multiple of 4,
      // and the sum of both sizes is a multiple of 4 but would not be sufficient to write
      // each typelist aligned on 4 bytes.
      stringData += contents.stringDatas.byteCount;
      annotationsDirectory += contents.annotationsDirectories.byteCount;
      annotationsSet += contents.annotationSets.byteCount;
      annotationsSetRefList += contents.annotationSetRefLists.byteCount;

      if (exact) {
        code += contents.codes.byteCount;
        classData += contents.classDatas.byteCount;
        encodedArray += contents.encodedArrays.byteCount;
        annotation += contents.annotations.byteCount;
        debugInfo += contents.debugInfos.byteCount;
      } else {
        // at most 1/4 of the bytes in a code section are uleb/sleb
        code += (int) Math.ceil(contents.codes.byteCount * 1.25);
        // at most 2/3 of the bytes in a class data section are uleb/sleb that may change
        // (assuming the worst case that section contains only methods and no fields)
        classData += (int) Math.ceil(contents.classDatas.byteCount * 1.67);
        // all of the bytes in an encoding arrays section may be uleb/sleb
        encodedArray += contents.encodedArrays.byteCount * 2;
        // all of the bytes in an annotations section may be uleb/sleb
        annotation += (int) Math.ceil(contents.annotations.byteCount * 2);
        // all of the bytes in a debug info section may be uleb/sleb. The additive constant
        // is a fudge factor observed to be required when merging small
        // DEX files (b/68483205).
        debugInfo += contents.debugInfos.byteCount * 2 + 8;
      }
    }
Compute sizes for merging several dexes.
android/android_framework/dex-maker/src/main/java/com/android/dx/merge/DexMerger.java