Revert "Don't embed the dex code in the oat file if dex is uncompressed."

This reverts commit ae7e83817e546848ef6b2949dd9065b153e14316.

Reason for revert: Broken wrt/ preopted apps and stripping

Bug: 63920015
Bug: 70777774
Change-Id: I39580684d46fa57bd780d2d8bedd65a47d58cf5e
Test: m
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 9af6cf4..3c8eade 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -72,11 +72,6 @@
 ART_TEST_HOST_GTEST_MainStripped_DEX := $(basename $(ART_TEST_HOST_GTEST_Main_DEX))Stripped$(suffix $(ART_TEST_HOST_GTEST_Main_DEX))
 ART_TEST_TARGET_GTEST_MainStripped_DEX := $(basename $(ART_TEST_TARGET_GTEST_Main_DEX))Stripped$(suffix $(ART_TEST_TARGET_GTEST_Main_DEX))
 
-# Create rules for MainUncompressed, a copy of Main with the classes.dex uncompressed
-# for the dex2oat tests.
-ART_TEST_HOST_GTEST_MainUncompressed_DEX := $(basename $(ART_TEST_HOST_GTEST_Main_DEX))Uncompressed$(suffix $(ART_TEST_HOST_GTEST_Main_DEX))
-ART_TEST_TARGET_GTEST_MainUncompressed_DEX := $(basename $(ART_TEST_TARGET_GTEST_Main_DEX))Uncompressed$(suffix $(ART_TEST_TARGET_GTEST_Main_DEX))
-
 $(ART_TEST_HOST_GTEST_MainStripped_DEX): $(ART_TEST_HOST_GTEST_Main_DEX)
 	cp $< $@
 	$(call dexpreopt-remove-classes.dex,$@)
@@ -85,16 +80,6 @@
 	cp $< $@
 	$(call dexpreopt-remove-classes.dex,$@)
 
-$(ART_TEST_HOST_GTEST_MainUncompressed_DEX): $(ART_TEST_HOST_GTEST_Main_DEX) $(ZIPALIGN)
-	cp $< $@
-	$(call uncompress-dexs, $@)
-	$(call align-package, $@)
-
-$(ART_TEST_TARGET_GTEST_MainUncompressed_DEX): $(ART_TEST_TARGET_GTEST_Main_DEX) $(ZIPALIGN)
-	cp $< $@
-	$(call uncompress-dexs, $@)
-	$(call align-package, $@)
-
 ART_TEST_GTEST_VerifierDeps_SRC := $(abspath $(wildcard $(LOCAL_PATH)/VerifierDeps/*.smali))
 ART_TEST_GTEST_VerifierDepsMulti_SRC := $(abspath $(wildcard $(LOCAL_PATH)/VerifierDepsMulti/*.smali))
 ART_TEST_HOST_GTEST_VerifierDeps_DEX := $(dir $(ART_TEST_HOST_GTEST_Main_DEX))$(subst Main,VerifierDeps,$(basename $(notdir $(ART_TEST_HOST_GTEST_Main_DEX))))$(suffix $(ART_TEST_HOST_GTEST_Main_DEX))
@@ -125,7 +110,7 @@
 ART_GTEST_dex_cache_test_DEX_DEPS := Main Packages MethodTypes
 ART_GTEST_dex_file_test_DEX_DEPS := GetMethodSignature Main Nested MultiDex
 ART_GTEST_dexlayout_test_DEX_DEPS := ManyMethods
-ART_GTEST_dex2oat_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) ManyMethods Statics VerifierDeps MainUncompressed
+ART_GTEST_dex2oat_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) ManyMethods Statics VerifierDeps
 ART_GTEST_dex2oat_image_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS) Statics VerifierDeps
 ART_GTEST_exception_test_DEX_DEPS := ExceptionHandle
 ART_GTEST_image_test_DEX_DEPS := ImageLayoutA ImageLayoutB DefaultMethods
@@ -711,8 +696,6 @@
 $(foreach dir,$(GTEST_DEX_DIRECTORIES), $(eval ART_TEST_HOST_GTEST_$(dir)_DEX :=))
 ART_TEST_HOST_GTEST_MainStripped_DEX :=
 ART_TEST_TARGET_GTEST_MainStripped_DEX :=
-ART_TEST_HOST_GTEST_MainUncompressed_DEX :=
-ART_TEST_TARGET_GTEST_MainUncompressed_DEX :=
 ART_TEST_GTEST_VerifierDeps_SRC :=
 ART_TEST_HOST_GTEST_VerifierDeps_DEX :=
 ART_TEST_TARGET_GTEST_VerifierDeps_DEX :=
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index d1cb175..0ca3c8f 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -401,12 +401,6 @@
     Thread* self, const CompilerDriver& driver, Handle<mirror::ClassLoader> class_loader,
     const DexFile& dex_file, const DexFile::ClassDef& class_def)
     REQUIRES_SHARED(Locks::mutator_lock_) {
-  // When the dex file is uncompressed in the APK, we do not generate a copy in the .vdex
-  // file. As a result, dex2oat will map the dex file read-only, and we only need to check
-  // that to know if we can do quickening.
-  if (dex_file.GetContainer() != nullptr && dex_file.GetContainer()->IsReadOnly()) {
-    return optimizer::DexToDexCompilationLevel::kDontDexToDexCompile;
-  }
   auto* const runtime = Runtime::Current();
   DCHECK(driver.GetCompilerOptions().IsQuickeningCompilationEnabled());
   const char* descriptor = dex_file.GetClassDescriptor(class_def);
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index eab15b9..d2141e8 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -102,13 +102,13 @@
 
   ~CompilerDriver();
 
-  // Set dex files associated with the oat file being compiled.
+  // Set dex files that will be stored in the oat file after being compiled.
   void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
 
   // Set dex files classpath.
   void SetClasspathDexFiles(const std::vector<const DexFile*>& dex_files);
 
-  // Get dex files associated with the the oat file being compiled.
+  // Get dex file that will be stored in the oat file after being compiled.
   ArrayRef<const DexFile* const> GetDexFilesForOatFile() const {
     return ArrayRef<const DexFile* const>(dex_files_for_oat_file_);
   }
@@ -528,7 +528,7 @@
 
   bool support_boot_image_fixup_;
 
-  // List of dex files associates with the oat file.
+  // List of dex files that will be stored in the oat file.
   std::vector<const DexFile*> dex_files_for_oat_file_;
 
   CompiledMethodStorage compiled_method_storage_;
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 3f4904b..27bec1d 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1550,7 +1550,7 @@
       for (size_t i = 0, size = oat_writers_.size(); i != size; ++i) {
         rodata_.push_back(elf_writers_[i]->StartRoData());
         // Unzip or copy dex files straight to the oat file.
-        std::vector<std::unique_ptr<MemMap>> opened_dex_files_map;
+        std::unique_ptr<MemMap> opened_dex_files_map;
         std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
         // No need to verify the dex file for:
         // 1) Dexlayout since it does the verification. It also may not pass the verification since
@@ -1570,16 +1570,14 @@
           return dex2oat::ReturnCode::kOther;
         }
         dex_files_per_oat_file_.push_back(MakeNonOwningPointerVector(opened_dex_files));
-        if (opened_dex_files_map.empty()) {
-          DCHECK(opened_dex_files.empty());
-        } else {
-          for (std::unique_ptr<MemMap>& map : opened_dex_files_map) {
-            opened_dex_files_maps_.push_back(std::move(map));
-          }
+        if (opened_dex_files_map != nullptr) {
+          opened_dex_files_maps_.push_back(std::move(opened_dex_files_map));
           for (std::unique_ptr<const DexFile>& dex_file : opened_dex_files) {
             dex_file_oat_index_map_.emplace(dex_file.get(), i);
             opened_dex_files_.push_back(std::move(dex_file));
           }
+        } else {
+          DCHECK(opened_dex_files.empty());
         }
       }
     }
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 41f2c70..ad287b0 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -1513,19 +1513,4 @@
   EXPECT_LT(dedupe_size, no_dedupe_size);
 }
 
-TEST_F(Dex2oatTest, UncompressedTest) {
-  std::unique_ptr<const DexFile> dex(OpenTestDexFile("MainUncompressed"));
-  std::string out_dir = GetScratchDir();
-  const std::string base_oat_name = out_dir + "/base.oat";
-  GenerateOdexForTest(dex->GetLocation(),
-                      base_oat_name,
-                      CompilerFilter::Filter::kQuicken,
-                      { },
-                      true,  // expect_success
-                      false,  // use_fd
-                      [](const OatFile& o) {
-                        CHECK(!o.ContainsDexCode());
-                      });
-}
-
 }  // namespace art
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index 208297b..cedbccf 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -253,7 +253,7 @@
       }
 
       std::vector<OutputStream*> rodata;
-      std::vector<std::unique_ptr<MemMap>> opened_dex_files_maps;
+      std::vector<std::unique_ptr<MemMap>> opened_dex_files_map;
       std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
       // Now that we have finalized key_value_store_, start writing the oat file.
       for (size_t i = 0, size = oat_writers.size(); i != size; ++i) {
@@ -266,7 +266,7 @@
                                             dex_file->GetLocation().c_str(),
                                             dex_file->GetLocationChecksum());
 
-        std::vector<std::unique_ptr<MemMap>> cur_opened_dex_files_maps;
+        std::unique_ptr<MemMap> cur_opened_dex_files_map;
         std::vector<std::unique_ptr<const DexFile>> cur_opened_dex_files;
         bool dex_files_ok = oat_writers[i]->WriteAndOpenDexFiles(
             vdex_files[i].GetFile(),
@@ -276,14 +276,12 @@
             &key_value_store,
             /* verify */ false,           // Dex files may be dex-to-dex-ed, don't verify.
             /* update_input_vdex */ false,
-            &cur_opened_dex_files_maps,
+            &cur_opened_dex_files_map,
             &cur_opened_dex_files);
         ASSERT_TRUE(dex_files_ok);
 
-        if (!cur_opened_dex_files_maps.empty()) {
-          for (std::unique_ptr<MemMap>& cur_map : cur_opened_dex_files_maps) {
-            opened_dex_files_maps.push_back(std::move(cur_map));
-          }
+        if (cur_opened_dex_files_map != nullptr) {
+          opened_dex_files_map.push_back(std::move(cur_opened_dex_files_map));
           for (std::unique_ptr<const DexFile>& cur_dex_file : cur_opened_dex_files) {
             // dex_file_oat_index_map_.emplace(dex_file.get(), i);
             opened_dex_files.push_back(std::move(cur_dex_file));
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 9e61c42..293078a 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -363,7 +363,6 @@
     compiler_driver_(nullptr),
     image_writer_(nullptr),
     compiling_boot_image_(compiling_boot_image),
-    only_contains_uncompressed_zip_entries_(false),
     dex_files_(nullptr),
     vdex_size_(0u),
     vdex_dex_files_offset_(0u),
@@ -637,7 +636,7 @@
     SafeMap<std::string, std::string>* key_value_store,
     bool verify,
     bool update_input_vdex,
-    /*out*/ std::vector<std::unique_ptr<MemMap>>* opened_dex_files_map,
+    /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
     /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files) {
   CHECK(write_state_ == WriteState::kAddingDexFileSources);
 
@@ -646,7 +645,7 @@
      return false;
   }
 
-  std::vector<std::unique_ptr<MemMap>> dex_files_map;
+  std::unique_ptr<MemMap> dex_files_map;
   std::vector<std::unique_ptr<const DexFile>> dex_files;
 
   // Initialize VDEX and OAT headers.
@@ -3288,28 +3287,14 @@
 
   vdex_dex_files_offset_ = vdex_size_;
 
-  only_contains_uncompressed_zip_entries_ = true;
+  // Write dex files.
   for (OatDexFile& oat_dex_file : oat_dex_files_) {
-    if (!oat_dex_file.source_.IsZipEntry()) {
-      only_contains_uncompressed_zip_entries_ = false;
-      break;
-    }
-    ZipEntry* entry = oat_dex_file.source_.GetZipEntry();
-    if (!entry->IsUncompressed() || !entry->IsAlignedToDexHeader()) {
-      only_contains_uncompressed_zip_entries_ = false;
-      break;
+    if (!WriteDexFile(out, file, &oat_dex_file, update_input_vdex)) {
+      return false;
     }
   }
 
-  if (!only_contains_uncompressed_zip_entries_) {
-    // Write dex files.
-    for (OatDexFile& oat_dex_file : oat_dex_files_) {
-      if (!WriteDexFile(out, file, &oat_dex_file, update_input_vdex)) {
-        return false;
-      }
-    }
-  }
-
+  CloseSources();
   return true;
 }
 
@@ -3631,7 +3616,7 @@
 bool OatWriter::OpenDexFiles(
     File* file,
     bool verify,
-    /*out*/ std::vector<std::unique_ptr<MemMap>>* opened_dex_files_map,
+    /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
     /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files) {
   TimingLogger::ScopedTiming split("OpenDexFiles", timings_);
 
@@ -3640,43 +3625,6 @@
     return true;
   }
 
-  if (only_contains_uncompressed_zip_entries_) {
-    std::vector<std::unique_ptr<const DexFile>> dex_files;
-    std::vector<std::unique_ptr<MemMap>> maps;
-    for (OatDexFile& oat_dex_file : oat_dex_files_) {
-      std::string error_msg;
-      MemMap* map = oat_dex_file.source_.GetZipEntry()->MapDirectlyFromFile(
-          oat_dex_file.dex_file_location_data_, &error_msg);
-      if (map == nullptr) {
-        LOG(ERROR) << error_msg;
-        return false;
-      }
-      maps.emplace_back(map);
-      // Now, open the dex file.
-      dex_files.emplace_back(DexFileLoader::Open(map->Begin(),
-                                                 map->Size(),
-                                                 oat_dex_file.GetLocation(),
-                                                 oat_dex_file.dex_file_location_checksum_,
-                                                 /* oat_dex_file */ nullptr,
-                                                 verify,
-                                                 verify,
-                                                 &error_msg));
-      if (dex_files.back() == nullptr) {
-        LOG(ERROR) << "Failed to open dex file from oat file. File: " << oat_dex_file.GetLocation()
-                   << " Error: " << error_msg;
-        return false;
-      }
-      oat_dex_file.class_offsets_.resize(dex_files.back()->GetHeader().class_defs_size_);
-    }
-    *opened_dex_files_map = std::move(maps);
-    *opened_dex_files = std::move(dex_files);
-    CloseSources();
-    return true;
-  }
-  // We could have closed the sources at the point of writing the dex files, but to
-  // make it consistent with the case we're not writing the dex files, we close them now.
-  CloseSources();
-
   size_t map_offset = oat_dex_files_[0].dex_file_offset_;
   size_t length = vdex_size_ - map_offset;
 
@@ -3735,7 +3683,7 @@
     oat_dex_file.class_offsets_.resize(dex_files.back()->GetHeader().class_defs_size_);
   }
 
-  opened_dex_files_map->push_back(std::move(dex_files_map));
+  *opened_dex_files_map = std::move(dex_files_map);
   *opened_dex_files = std::move(dex_files);
   return true;
 }
diff --git a/dex2oat/linker/oat_writer.h b/dex2oat/linker/oat_writer.h
index 3e9f463..4055878 100644
--- a/dex2oat/linker/oat_writer.h
+++ b/dex2oat/linker/oat_writer.h
@@ -173,7 +173,7 @@
                             SafeMap<std::string, std::string>* key_value_store,
                             bool verify,
                             bool update_input_vdex,
-                            /*out*/ std::vector<std::unique_ptr<MemMap>>* opened_dex_files_map,
+                            /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
                             /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
   bool WriteQuickeningInfo(OutputStream* vdex_out);
   bool WriteVerifierDeps(OutputStream* vdex_out, verifier::VerifierDeps* verifier_deps);
@@ -300,7 +300,7 @@
                     bool update_input_vdex);
   bool OpenDexFiles(File* file,
                     bool verify,
-                    /*out*/ std::vector<std::unique_ptr<MemMap>>* opened_dex_files_map,
+                    /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
                     /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
 
   size_t InitOatHeader(InstructionSet instruction_set,
@@ -367,8 +367,6 @@
   const CompilerDriver* compiler_driver_;
   ImageWriter* image_writer_;
   const bool compiling_boot_image_;
-  // Whether the dex files being compiled are all uncompressed in the APK.
-  bool only_contains_uncompressed_zip_entries_;
 
   // note OatFile does not take ownership of the DexFiles
   const std::vector<const DexFile*>* dex_files_;
diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc
index f4dfcd6..fec05cc 100644
--- a/dex2oat/linker/oat_writer_test.cc
+++ b/dex2oat/linker/oat_writer_test.cc
@@ -186,7 +186,7 @@
         oat_file);
     elf_writer->Start();
     OutputStream* oat_rodata = elf_writer->StartRoData();
-    std::vector<std::unique_ptr<MemMap>> opened_dex_files_maps;
+    std::unique_ptr<MemMap> opened_dex_files_map;
     std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
     if (!oat_writer.WriteAndOpenDexFiles(vdex_file,
                                          oat_rodata,
@@ -195,7 +195,7 @@
                                          &key_value_store,
                                          verify,
                                          /* update_input_vdex */ false,
-                                         &opened_dex_files_maps,
+                                         &opened_dex_files_map,
                                          &opened_dex_files)) {
       return false;
     }
@@ -251,9 +251,7 @@
       return false;
     }
 
-    for (std::unique_ptr<MemMap>& map : opened_dex_files_maps) {
-      opened_dex_files_maps_.emplace_back(std::move(map));
-    }
+    opened_dex_files_maps_.emplace_back(std::move(opened_dex_files_map));
     for (std::unique_ptr<const DexFile>& dex_file : opened_dex_files) {
       opened_dex_files_.emplace_back(dex_file.release());
     }
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 73b8c30..944a308 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -1032,10 +1032,6 @@
   ALWAYS_INLINE const StandardDexFile* AsStandardDexFile() const;
   ALWAYS_INLINE const CompactDexFile* AsCompactDexFile() const;
 
-  DexFileContainer* GetContainer() const {
-    return container_.get();
-  }
-
  protected:
   DexFile(const uint8_t* base,
           size_t size,
diff --git a/runtime/dex_file_loader.cc b/runtime/dex_file_loader.cc
index 6d4bbf1..bc92769 100644
--- a/runtime/dex_file_loader.cc
+++ b/runtime/dex_file_loader.cc
@@ -379,7 +379,7 @@
 
   std::unique_ptr<MemMap> map;
   if (zip_entry->IsUncompressed()) {
-    if (!zip_entry->IsAlignedToDexHeader()) {
+    if (!zip_entry->IsAlignedTo(alignof(DexFile::Header))) {
       // Do not mmap unaligned ZIP entries because
       // doing so would fail dex verification which requires 4 byte alignment.
       LOG(WARNING) << "Can't mmap dex file " << location << "!" << entry_name << " directly; "
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 1d05399..c82df71 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -594,6 +594,14 @@
                                 dex_file_location.c_str());
       return false;
     }
+    if (UNLIKELY(dex_file_offset == 0U)) {
+      *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with zero dex "
+                                    "file offset",
+                                GetLocation().c_str(),
+                                i,
+                                dex_file_location.c_str());
+      return false;
+    }
     if (UNLIKELY(dex_file_offset > DexSize())) {
       *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with dex file "
                                     "offset %u > %zu",
@@ -604,36 +612,20 @@
                                 DexSize());
       return false;
     }
-    const uint8_t* dex_file_pointer = nullptr;
-    if (UNLIKELY(dex_file_offset == 0U)) {
-      if (uncompressed_dex_files_ == nullptr) {
-        uncompressed_dex_files_.reset(new std::vector<std::unique_ptr<const DexFile>>());
-        // No dex files, load it from location.
-        if (!DexFileLoader::Open(dex_file_location.c_str(),
-                                 dex_file_location,
-                                 /* verify */ false,
-                                 /* verify_checksum */ false,
-                                 error_msg,
-                                 uncompressed_dex_files_.get())) {
-          return false;
-        }
-      }
-      dex_file_pointer = uncompressed_dex_files_.get()->at(i)->Begin();
-    } else {
-      if (UNLIKELY(DexSize() - dex_file_offset < sizeof(DexFile::Header))) {
-        *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with dex file "
-                                      "offset %u of %zu but the size of dex file header is %zu",
-                                  GetLocation().c_str(),
-                                  i,
-                                  dex_file_location.c_str(),
-                                  dex_file_offset,
-                                  DexSize(),
-                                  sizeof(DexFile::Header));
-        return false;
-      }
-      dex_file_pointer = DexBegin() + dex_file_offset;
+    if (UNLIKELY(DexSize() - dex_file_offset < sizeof(DexFile::Header))) {
+      *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with dex file "
+                                    "offset %u of %zu but the size of dex file header is %zu",
+                                GetLocation().c_str(),
+                                i,
+                                dex_file_location.c_str(),
+                                dex_file_offset,
+                                DexSize(),
+                                sizeof(DexFile::Header));
+      return false;
     }
 
+    const uint8_t* dex_file_pointer = DexBegin() + dex_file_offset;
+
     const bool valid_magic = DexFileLoader::IsMagicValid(dex_file_pointer);
     if (UNLIKELY(!valid_magic)) {
       *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with invalid "
@@ -654,7 +646,7 @@
       return false;
     }
     const DexFile::Header* header = reinterpret_cast<const DexFile::Header*>(dex_file_pointer);
-    if (dex_file_offset != 0 && (DexSize() - dex_file_offset < header->file_size_)) {
+    if (DexSize() - dex_file_offset < header->file_size_) {
       *error_msg = StringPrintf("In oat file '%s' found OatDexFile #%zu for '%s' with dex file "
                                     "offset %u and size %u truncated at %zu",
                                 GetLocation().c_str(),
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 61daa95..36a4d7b 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -324,11 +324,6 @@
     return vdex_.get();
   }
 
-  // Whether the OatFile embeds the Dex code.
-  bool ContainsDexCode() const {
-    return uncompressed_dex_files_ == nullptr;
-  }
-
  protected:
   OatFile(const std::string& filename, bool executable);
 
@@ -394,10 +389,6 @@
   // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't.
   mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_);
 
-  // Cache of dex files mapped directly from a location, in case the OatFile does
-  // not embed the dex code.
-  std::unique_ptr<std::vector<std::unique_ptr<const DexFile>>> uncompressed_dex_files_;
-
   friend class gc::collector::DummyOatFile;  // For modifying begin_ and end_.
   friend class OatClass;
   friend class art::OatDexFile;
diff --git a/runtime/zip_archive.cc b/runtime/zip_archive.cc
index 279c0e4..f3d4d77 100644
--- a/runtime/zip_archive.cc
+++ b/runtime/zip_archive.cc
@@ -27,7 +27,6 @@
 #include "android-base/stringprintf.h"
 #include "ziparchive/zip_archive.h"
 
-#include "dex_file.h"
 #include "base/bit_utils.h"
 #include "base/unix_file/fd_file.h"
 
@@ -50,15 +49,11 @@
   return zip_entry_->method == kCompressStored;
 }
 
-bool ZipEntry::IsAlignedTo(size_t alignment) const {
+bool ZipEntry::IsAlignedTo(size_t alignment) {
   DCHECK(IsPowerOfTwo(alignment)) << alignment;
   return IsAlignedParam(zip_entry_->offset, static_cast<int>(alignment));
 }
 
-bool ZipEntry::IsAlignedToDexHeader() const {
-  return IsAlignedTo(alignof(DexFile::Header));
-}
-
 ZipEntry::~ZipEntry() {
   delete zip_entry_;
 }
diff --git a/runtime/zip_archive.h b/runtime/zip_archive.h
index ca7bbe9..821cc5c 100644
--- a/runtime/zip_archive.h
+++ b/runtime/zip_archive.h
@@ -58,8 +58,7 @@
   uint32_t GetCrc32();
 
   bool IsUncompressed();
-  bool IsAlignedTo(size_t alignment) const;
-  bool IsAlignedToDexHeader() const;
+  bool IsAlignedTo(size_t alignment);
 
  private:
   ZipEntry(ZipArchiveHandle handle,