Add logic for calculating offsets during writing

Delete all the offset related layout logic, move the logic to
writing. Layout is now controlled by changing the order of the data
vectors.

Calculate all offsets during writing instead of reading. This allows
more flexible layout optimizations without needing to be as careful
about offsets in other sections changing.

Maintained logic for using existing offsets in the case where
changing the layout is not required.

Areas to improve:
How to size the memmap, do we want 2 passes? Currently the algorithm
reserves 10% extra space in case required. This is sufficient for top
1000 apps in the play store. Will consider a two pass approach later.

Bug: 63756964
Bug: 68948395
Bug: 68867570
Bug: 68864106
Bug: 68864168

Test: test/testrunner/testrunner.py --host -j40
Test: test-art-host-gtest
Test: Dexlayout speed profile top 1000 apps

Change-Id: I7dee869da3a010559547f8cfdf93e9aa4c3f47ff
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index bd8583b..ad287b0 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1332,10 +1332,10 @@
         code_section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeUnused)];
 
     // All the sections should be non-empty.
-    EXPECT_GT(section_hot_code.size_, 0u);
-    EXPECT_GT(section_sometimes_used.size_, 0u);
-    EXPECT_GT(section_startup_only.size_, 0u);
-    EXPECT_GT(section_unused.size_, 0u);
+    EXPECT_GT(section_hot_code.Size(), 0u);
+    EXPECT_GT(section_sometimes_used.Size(), 0u);
+    EXPECT_GT(section_startup_only.Size(), 0u);
+    EXPECT_GT(section_unused.Size(), 0u);
 
     // Open the dex file since we need to peek at the code items to verify the layout matches what
     // we expect.
@@ -1364,18 +1364,18 @@
       const bool is_post_startup = ContainsElement(post_methods, method_idx);
       if (is_hot) {
         // Hot is highest precedence, check that the hot methods are in the hot section.
-        EXPECT_LT(code_item_offset - section_hot_code.offset_, section_hot_code.size_);
+        EXPECT_TRUE(section_hot_code.Contains(code_item_offset));
         ++hot_count;
       } else if (is_post_startup) {
         // Post startup is sometimes used section.
-        EXPECT_LT(code_item_offset - section_sometimes_used.offset_, section_sometimes_used.size_);
+        EXPECT_TRUE(section_sometimes_used.Contains(code_item_offset));
         ++post_startup_count;
       } else if (is_startup) {
         // Startup at this point means not hot or post startup, these must be startup only then.
-        EXPECT_LT(code_item_offset - section_startup_only.offset_, section_startup_only.size_);
+        EXPECT_TRUE(section_startup_only.Contains(code_item_offset));
         ++startup_count;
       } else {
-        if (code_item_offset - section_unused.offset_ < section_unused.size_) {
+        if (section_unused.Contains(code_item_offset)) {
           // If no flags are set, the method should be unused ...
           ++unused_count;
         } else {