Refactor vdex file writing.

Instead of unzipping dex files to the vdex file using a file
descriptor, reserve space in the vdex file and mmap it to
memory and unzip dex files to memory. Postpone any flushes
until after we have finalized the contents, then flush the
contents without header, then store and flush the header.

Testing with a certain big app on aosp_taimen-userdebug and
using --dump-timings to show the timing for different phases
of compilation shows significant improvements. The time of
"Write Dex files" goes from ~1s down to ~0.3s and also the
"OpenDexFiles" is reduced from ~0.3s to ~0.2s. The latter is
presumably caused by having the memory pages already filled
with data because this change does not touch that code. The
"dex2oat Write VDEX" phase time does not significantly
change but it has an impact on the time of the enclosing
"dex2oat Oat" phase, increasing it by up to ~0.2s.

This change also prepares for future improvements, such as
doing the dex file extraction on multiple threads (one task
per dex file, helping with multi-dex), or tuning when we
flush the vdex file contents (dex file data could be
flushed with an msync() on a separate thread while we're
running the "dex2oat Compile" phase but that could be
counter-productive for dex-to-dex compilation as we would
potentially write the bytecode twice).

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: aosp_taimen-userdebug boots.
Bug: 34201138
Change-Id: I9dbc2b0b4e3bf1e3b2cbf78957356e1d4ca23f66
8 files changed