Move dex_files_for_oat_file_ to CompilerOptions.

A step toward removing the CompilerDriver dependency from
several classes, including HSharpening and ImageWriter.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I364ef66511fdf855cb11b12c818a40572b037727
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 7491173..52c767f 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -40,6 +40,7 @@
 #include "oat_quick_method_header.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread-current-inl.h"
+#include "utils/atomic_dex_ref_map-inl.h"
 
 namespace art {
 
@@ -332,4 +333,10 @@
   image_reservation_.reset();
 }
 
+void CommonCompilerTest::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
+  compiler_options_->dex_files_for_oat_file_ = dex_files;
+  compiler_driver_->compiled_classes_.AddDexFiles(dex_files);
+  compiler_driver_->dex_to_dex_compiler_.SetDexFiles(dex_files);
+}
+
 }  // namespace art
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index 46b59a3..f070bbb 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -33,6 +33,7 @@
 class CompilerDriver;
 class CompilerOptions;
 class CumulativeLogger;
+class DexFile;
 class ProfileCompilationInfo;
 class VerificationResults;
 
@@ -93,6 +94,8 @@
 
   void UnreserveImageSpace();
 
+  void SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files);
+
   Compiler::Kind compiler_kind_ = Compiler::kOptimizing;
   std::unique_ptr<CompilerOptions> compiler_options_;
   std::unique_ptr<VerificationResults> verification_results_;
diff --git a/compiler/dex/dex_to_dex_decompiler_test.cc b/compiler/dex/dex_to_dex_decompiler_test.cc
index 76250d2..4f83d60 100644
--- a/compiler/dex/dex_to_dex_decompiler_test.cc
+++ b/compiler/dex/dex_to_dex_decompiler_test.cc
@@ -47,7 +47,7 @@
     // the results for all the dex files, not just the results for the current dex file.
     down_cast<QuickCompilerCallbacks*>(Runtime::Current()->GetCompilerCallbacks())->SetVerifierDeps(
         new verifier::VerifierDeps(GetDexFiles(class_loader)));
-    compiler_driver_->SetDexFilesForOatFile(GetDexFiles(class_loader));
+    SetDexFilesForOatFile(GetDexFiles(class_loader));
     compiler_driver_->CompileAll(class_loader, GetDexFiles(class_loader), &timings);
   }
 
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index ed4fb6f..66a8a57 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -885,8 +885,12 @@
                                 const std::vector<const DexFile*>& dex_files,
                                 TimingLogger* timings) {
   CheckThreadPools();
+
   VLOG(compiler) << "Before precompile " << GetMemoryUsageString(false);
 
+  compiled_classes_.AddDexFiles(GetCompilerOptions().GetDexFilesForOatFile());
+  dex_to_dex_compiler_.SetDexFiles(GetCompilerOptions().GetDexFilesForOatFile());
+
   // Precompile:
   // 1) Load image classes.
   // 2) Resolve all classes.
@@ -1948,7 +1952,8 @@
     // Create per-thread VerifierDeps to avoid contention on the main one.
     // We will merge them after verification.
     for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
-      worker->GetThread()->SetVerifierDeps(new verifier::VerifierDeps(dex_files_for_oat_file_));
+      worker->GetThread()->SetVerifierDeps(
+          new verifier::VerifierDeps(GetCompilerOptions().GetDexFilesForOatFile()));
     }
   }
 
@@ -1973,7 +1978,7 @@
     for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
       verifier::VerifierDeps* thread_deps = worker->GetThread()->GetVerifierDeps();
       worker->GetThread()->SetVerifierDeps(nullptr);
-      verifier_deps->MergeWith(*thread_deps, dex_files_for_oat_file_);
+      verifier_deps->MergeWith(*thread_deps, GetCompilerOptions().GetDexFilesForOatFile());
       delete thread_deps;
     }
     Thread::Current()->SetVerifierDeps(nullptr);
@@ -2846,7 +2851,7 @@
       if (kIsDebugBuild) {
         // Check to make sure it's not a dex file for an oat file we are compiling since these
         // should always succeed. These do not include classes in for used libraries.
-        for (const DexFile* dex_file : GetDexFilesForOatFile()) {
+        for (const DexFile* dex_file : GetCompilerOptions().GetDexFilesForOatFile()) {
           CHECK_NE(ref.dex_file, dex_file) << ref.dex_file->GetLocation();
         }
       }
@@ -2945,17 +2950,6 @@
   return oss.str();
 }
 
-bool CompilerDriver::MayInlineInternal(const DexFile* inlined_from,
-                                       const DexFile* inlined_into) const {
-  // We're not allowed to inline across dex files if we're the no-inline-from dex file.
-  if (inlined_from != inlined_into &&
-      ContainsElement(compiler_options_->GetNoInlineFromDexFile(), inlined_from)) {
-    return false;
-  }
-
-  return true;
-}
-
 void CompilerDriver::InitializeThreadPools() {
   size_t parallel_count = parallel_thread_count_ > 0 ? parallel_thread_count_ - 1 : 0;
   parallel_thread_pool_.reset(
@@ -2968,12 +2962,6 @@
   single_thread_pool_.reset();
 }
 
-void CompilerDriver::SetDexFilesForOatFile(const std::vector<const DexFile*>& dex_files) {
-  dex_files_for_oat_file_ = dex_files;
-  compiled_classes_.AddDexFiles(dex_files);
-  dex_to_dex_compiler_.SetDexFiles(dex_files);
-}
-
 void CompilerDriver::SetClasspathDexFiles(const std::vector<const DexFile*>& dex_files) {
   classpath_classes_.AddDexFiles(dex_files);
 }
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 36e93a8..54e1f37 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -106,17 +106,9 @@
 
   ~CompilerDriver();
 
-  // Set dex files associated with the oat file 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.
-  ArrayRef<const DexFile* const> GetDexFilesForOatFile() const {
-    return ArrayRef<const DexFile* const>(dex_files_for_oat_file_);
-  }
-
   void CompileAll(jobject class_loader,
                   const std::vector<const DexFile*>& dex_files,
                   TimingLogger* timings)
@@ -354,13 +346,6 @@
   bool CanAssumeClassIsLoaded(mirror::Class* klass)
       REQUIRES_SHARED(Locks::mutator_lock_);
 
-  bool MayInline(const DexFile* inlined_from, const DexFile* inlined_into) const {
-    if (!kIsTargetBuild) {
-      return MayInlineInternal(inlined_from, inlined_into);
-    }
-    return true;
-  }
-
   const ProfileCompilationInfo* GetProfileCompilationInfo() const {
     return profile_compilation_info_;
   }
@@ -454,8 +439,6 @@
                const std::vector<const DexFile*>& dex_files,
                TimingLogger* timings);
 
-  bool MayInlineInternal(const DexFile* inlined_from, const DexFile* inlined_into) const;
-
   void InitializeThreadPools();
   void FreeThreadPools();
   void CheckThreadPools();
@@ -525,9 +508,6 @@
 
   bool support_boot_image_fixup_;
 
-  // List of dex files associates with the oat file.
-  std::vector<const DexFile*> dex_files_for_oat_file_;
-
   CompiledMethodStorage compiled_method_storage_;
 
   // Info for profile guided compilation.
diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc
index 491e61f..2eeb439 100644
--- a/compiler/driver/compiler_driver_test.cc
+++ b/compiler/driver/compiler_driver_test.cc
@@ -46,7 +46,7 @@
     TimingLogger timings("CompilerDriverTest::CompileAll", false, false);
     TimingLogger::ScopedTiming t(__FUNCTION__, &timings);
     dex_files_ = GetDexFiles(class_loader);
-    compiler_driver_->SetDexFilesForOatFile(dex_files_);;
+    SetDexFilesForOatFile(dex_files_);
     compiler_driver_->CompileAll(class_loader, dex_files_, &timings);
     t.NewTiming("MakeAllExecutable");
     MakeAllExecutable(class_loader);
@@ -331,7 +331,7 @@
     ASSERT_GT(dex_files.size(), 0u);
     dex_file = dex_files.front();
   }
-  compiler_driver_->SetDexFilesForOatFile(dex_files);
+  SetDexFilesForOatFile(dex_files);
   callbacks_->SetDoesClassUnloading(true, compiler_driver_.get());
   ClassReference ref(dex_file, 0u);
   // Test that the status is read from the compiler driver as expected.
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index 3d37b68..cc1af3e 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -38,6 +38,7 @@
       num_dex_methods_threshold_(kDefaultNumDexMethodsThreshold),
       inline_max_code_units_(kUnsetInlineMaxCodeUnits),
       no_inline_from_(),
+      dex_files_for_oat_file_(),
       image_classes_(),
       boot_image_(false),
       core_image_(false),
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 0709faf..908ff33 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -235,6 +235,10 @@
     return no_inline_from_;
   }
 
+  const std::vector<const DexFile*>& GetDexFilesForOatFile() const {
+    return dex_files_for_oat_file_;
+  }
+
   const HashSet<std::string>& GetImageClasses() const {
     return image_classes_;
   }
@@ -313,6 +317,9 @@
   // prefer vector<> over a lookup-oriented container, such as set<>.
   std::vector<const DexFile*> no_inline_from_;
 
+  // List of dex files associated with the oat file, empty for JIT.
+  std::vector<const DexFile*> dex_files_for_oat_file_;
+
   // Image classes, specifies the classes that will be included in the image if creating an image.
   // Must not be empty for real boot image, only for tests pretending to compile boot image.
   HashSet<std::string> image_classes_;
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index 7dd756e..72d53d2 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -126,7 +126,7 @@
 }
 
 bool HInliner::Run() {
-  if (compiler_driver_->GetCompilerOptions().GetInlineMaxCodeUnits() == 0) {
+  if (codegen_->GetCompilerOptions().GetInlineMaxCodeUnits() == 0) {
     // Inlining effectively disabled.
     return false;
   } else if (graph_->IsDebuggable()) {
@@ -731,7 +731,7 @@
         offline_profile.dex_references.size());
   for (size_t i = 0; i < offline_profile.dex_references.size(); i++) {
     bool found = false;
-    for (const DexFile* dex_file : compiler_driver_->GetDexFilesForOatFile()) {
+    for (const DexFile* dex_file : codegen_->GetCompilerOptions().GetDexFilesForOatFile()) {
       if (offline_profile.dex_references[i].MatchesDex(dex_file)) {
         dex_profile_index_to_dex_cache[i] =
             caller_compilation_unit_.GetClassLinker()->FindDexCache(self, *dex_file);
@@ -1418,6 +1418,22 @@
   return count;
 }
 
+static inline bool MayInline(const CompilerOptions& compiler_options,
+                             const DexFile& inlined_from,
+                             const DexFile& inlined_into) {
+  if (kIsTargetBuild) {
+    return true;
+  }
+
+  // We're not allowed to inline across dex files if we're the no-inline-from dex file.
+  if (!IsSameDexFile(inlined_from, inlined_into) &&
+      ContainsElement(compiler_options.GetNoInlineFromDexFile(), &inlined_from)) {
+    return false;
+  }
+
+  return true;
+}
+
 bool HInliner::TryBuildAndInline(HInvoke* invoke_instruction,
                                  ArtMethod* method,
                                  ReferenceTypeInfo receiver_type,
@@ -1439,8 +1455,9 @@
 
   // Check whether we're allowed to inline. The outermost compilation unit is the relevant
   // dex file here (though the transitivity of an inline chain would allow checking the calller).
-  if (!compiler_driver_->MayInline(method->GetDexFile(),
-                                   outer_compilation_unit_.GetDexFile())) {
+  if (!MayInline(codegen_->GetCompilerOptions(),
+                 *method->GetDexFile(),
+                 *outer_compilation_unit_.GetDexFile())) {
     if (TryPatternSubstitution(invoke_instruction, method, return_replacement)) {
       LOG_SUCCESS() << "Successfully replaced pattern of invoke "
                     << method->PrettyMethod();
@@ -1465,7 +1482,7 @@
     return false;
   }
 
-  size_t inline_max_code_units = compiler_driver_->GetCompilerOptions().GetInlineMaxCodeUnits();
+  size_t inline_max_code_units = codegen_->GetCompilerOptions().GetInlineMaxCodeUnits();
   if (accessor.InsnsSizeInCodeUnits() > inline_max_code_units) {
     LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedCodeItem)
         << "Method " << method->PrettyMethod()
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index ebac3f6..1e29c21 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -191,14 +191,14 @@
         desired_load_kind = HLoadClass::LoadKind::kBootImageLinkTimePcRelative;
       } else {
         // Not a boot image class.
-        DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
+        DCHECK(ContainsElement(compiler_options.GetDexFilesForOatFile(), &dex_file));
         desired_load_kind = HLoadClass::LoadKind::kBssEntry;
       }
     } else {
       is_in_boot_image = (klass != nullptr) &&
           runtime->GetHeap()->ObjectIsInBootImageSpace(klass.Get());
       if (runtime->UseJitCompilation()) {
-        DCHECK(!codegen->GetCompilerOptions().GetCompilePic());
+        DCHECK(!compiler_options.GetCompilePic());
         if (is_in_boot_image) {
           // TODO: Use direct pointers for all non-moving spaces, not just boot image. Bug: 29530787
           desired_load_kind = HLoadClass::LoadKind::kBootImageAddress;
@@ -331,14 +331,15 @@
         : hs.NewHandle(class_linker->FindDexCache(soa.Self(), dex_file));
     ObjPtr<mirror::String> string = nullptr;
 
-    if (codegen->GetCompilerOptions().IsBootImage()) {
+    const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
+    if (compiler_options.IsBootImage()) {
       // Compiling boot image. Resolve the string and allocate it if needed, to ensure
       // the string will be added to the boot image.
       DCHECK(!runtime->UseJitCompilation());
       string = class_linker->ResolveString(string_index, dex_cache);
       CHECK(string != nullptr);
       if (compiler_driver->GetSupportBootImageFixup()) {
-        DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file));
+        DCHECK(ContainsElement(compiler_options.GetDexFilesForOatFile(), &dex_file));
         desired_load_kind = HLoadString::LoadKind::kBootImageLinkTimePcRelative;
       } else {
         // compiler_driver_test. Do not sharpen.
diff --git a/compiler/verifier_deps_test.cc b/compiler/verifier_deps_test.cc
index 3fe2ec0..c223549 100644
--- a/compiler/verifier_deps_test.cc
+++ b/compiler/verifier_deps_test.cc
@@ -129,7 +129,7 @@
     for (const DexFile* dex_file : dex_files_) {
       compiler_driver_->GetVerificationResults()->AddDexFile(dex_file);
     }
-    compiler_driver_->SetDexFilesForOatFile(dex_files_);
+    SetDexFilesForOatFile(dex_files_);
   }
 
   void LoadDexFile(ScopedObjectAccess& soa) REQUIRES_SHARED(Locks::mutator_lock_) {
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 779128f..708f6ff 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -696,7 +696,7 @@
   }
 
   bool VerifyProfileData() {
-    return profile_compilation_info_->VerifyProfileData(dex_files_);
+    return profile_compilation_info_->VerifyProfileData(compiler_options_->dex_files_for_oat_file_);
   }
 
   void ParseInstructionSetVariant(const std::string& option, ParserOptions* parser_options) {
@@ -1491,8 +1491,8 @@
     if (profile_compilation_info_ != nullptr) {
       // TODO: The following comment looks outdated or misplaced.
       // Filter out class path classes since we don't want to include these in the image.
-      HashSet<std::string> image_classes =
-          profile_compilation_info_->GetClassDescriptors(dex_files_);
+      HashSet<std::string> image_classes = profile_compilation_info_->GetClassDescriptors(
+          compiler_options_->dex_files_for_oat_file_);
       VLOG(compiler) << "Loaded " << image_classes.size()
                      << " image class descriptors from profile";
       if (VLOG_IS_ON(compiler)) {
@@ -1653,10 +1653,11 @@
       }
     }
 
-    dex_files_ = MakeNonOwningPointerVector(opened_dex_files_);
+    compiler_options_->dex_files_for_oat_file_ = MakeNonOwningPointerVector(opened_dex_files_);
+    const std::vector<const DexFile*>& dex_files = compiler_options_->dex_files_for_oat_file_;
 
     // If we need to downgrade the compiler-filter for size reasons.
-    if (!IsBootImage() && IsVeryLarge(dex_files_)) {
+    if (!IsBootImage() && IsVeryLarge(dex_files)) {
       // Disable app image to make sure dex2oat unloading is enabled.
       compiler_options_->DisableAppImage();
 
@@ -1689,7 +1690,7 @@
     CHECK(driver_ == nullptr);
     // If we use a swap file, ensure we are above the threshold to make it necessary.
     if (swap_fd_ != -1) {
-      if (!UseSwap(IsBootImage(), dex_files_)) {
+      if (!UseSwap(IsBootImage(), dex_files)) {
         close(swap_fd_);
         swap_fd_ = -1;
         VLOG(compiler) << "Decided to run without swap.";
@@ -1732,7 +1733,7 @@
     // Verification results are only required for modes that have any compilation. Avoid
     // adding the dex files if possible to prevent allocating large arrays.
     if (verification_results_ != nullptr) {
-      for (const auto& dex_file : dex_files_) {
+      for (const auto& dex_file : dex_files) {
         // Pre-register dex files so that we can access verification results without locks during
         // compilation and verification.
         verification_results_->AddDexFile(dex_file);
@@ -1750,7 +1751,7 @@
   // Doesn't return the class loader since it's not meant to be used for image compilation.
   void CompileDexFilesIndividually() {
     CHECK(!IsImage()) << "Not supported with image";
-    for (const DexFile* dex_file : dex_files_) {
+    for (const DexFile* dex_file : compiler_options_->dex_files_for_oat_file_) {
       std::vector<const DexFile*> dex_files(1u, dex_file);
       VLOG(compiler) << "Compiling " << dex_file->GetLocation();
       jobject class_loader = CompileDexFiles(dex_files);
@@ -1781,7 +1782,7 @@
     // mode (to reduce RAM used by the compiler).
     return !IsImage() &&
         !update_input_vdex_ &&
-        dex_files_.size() > 1 &&
+        compiler_options_->dex_files_for_oat_file_.size() > 1 &&
         !CompilerFilter::IsAotCompilationEnabled(compiler_options_->GetCompilerFilter());
   }
 
@@ -1808,11 +1809,12 @@
         class_path_files = class_loader_context_->FlattenOpenedDexFiles();
       }
 
+      const std::vector<const DexFile*>& dex_files = compiler_options_->dex_files_for_oat_file_;
       std::vector<const DexFile*> no_inline_from_dex_files;
-      std::vector<const std::vector<const DexFile*>*> dex_file_vectors = {
+      const std::vector<const DexFile*>* dex_file_vectors[] = {
           &class_linker->GetBootClassPath(),
           &class_path_files,
-          &dex_files_
+          &dex_files
       };
       for (const std::vector<const DexFile*>* dex_file_vector : dex_file_vectors) {
         for (const DexFile* dex_file : *dex_file_vector) {
@@ -1851,7 +1853,6 @@
                                      thread_count_,
                                      swap_fd_,
                                      profile_compilation_info_.get()));
-    driver_->SetDexFilesForOatFile(dex_files_);
     if (!IsBootImage()) {
       driver_->SetClasspathDexFiles(class_loader_context_->FlattenOpenedDexFiles());
     }
@@ -1867,9 +1868,10 @@
     }
 
     // Setup vdex for compilation.
+    const std::vector<const DexFile*>& dex_files = compiler_options_->dex_files_for_oat_file_;
     if (!DoEagerUnquickeningOfVdex() && input_vdex_file_ != nullptr) {
       callbacks_->SetVerifierDeps(
-          new verifier::VerifierDeps(dex_files_, input_vdex_file_->GetVerifierDepsData()));
+          new verifier::VerifierDeps(dex_files, input_vdex_file_->GetVerifierDepsData()));
 
       // TODO: we unquicken unconditionally, as we don't know
       // if the boot image has changed. How exactly we'll know is under
@@ -1879,11 +1881,11 @@
       // We do not decompile a RETURN_VOID_NO_BARRIER into a RETURN_VOID, as the quickening
       // optimization does not depend on the boot image (the optimization relies on not
       // having final fields in a class, which does not change for an app).
-      input_vdex_file_->Unquicken(dex_files_, /* decompile_return_instruction */ false);
+      input_vdex_file_->Unquicken(dex_files, /* decompile_return_instruction */ false);
     } else {
       // Create the main VerifierDeps, here instead of in the compiler since we want to aggregate
       // the results for all the dex files, not just the results for the current dex file.
-      callbacks_->SetVerifierDeps(new verifier::VerifierDeps(dex_files_));
+      callbacks_->SetVerifierDeps(new verifier::VerifierDeps(dex_files));
     }
     // Invoke the compilation.
     if (compile_individually) {
@@ -1891,7 +1893,7 @@
       // Return a null classloader since we already freed released it.
       return nullptr;
     }
-    return CompileDexFiles(dex_files_);
+    return CompileDexFiles(dex_files);
   }
 
   // Create the class loader, use it to compile, and return.
@@ -1900,7 +1902,8 @@
 
     jobject class_loader = nullptr;
     if (!IsBootImage()) {
-      class_loader = class_loader_context_->CreateClassLoader(dex_files_);
+      class_loader =
+          class_loader_context_->CreateClassLoader(compiler_options_->dex_files_for_oat_file_);
       callbacks_->SetDexFiles(&dex_files);
     }
 
@@ -2370,7 +2373,7 @@
     return dex_files_size >= min_dex_file_cumulative_size_for_swap_;
   }
 
-  bool IsVeryLarge(std::vector<const DexFile*>& dex_files) {
+  bool IsVeryLarge(const std::vector<const DexFile*>& dex_files) {
     size_t dex_files_size = 0;
     for (const auto* dex_file : dex_files) {
       dex_files_size += dex_file->GetHeader().file_size_;
@@ -2501,8 +2504,9 @@
   }
 
   void SaveDexInput() {
-    for (size_t i = 0; i < dex_files_.size(); ++i) {
-      const DexFile* dex_file = dex_files_[i];
+    const std::vector<const DexFile*>& dex_files = compiler_options_->dex_files_for_oat_file_;
+    for (size_t i = 0, size = dex_files.size(); i != size; ++i) {
+      const DexFile* dex_file = dex_files[i];
       std::string tmp_file_name(StringPrintf("/data/local/tmp/dex2oat.%d.%zd.dex",
                                              getpid(), i));
       std::unique_ptr<File> tmp_file(OS::CreateEmptyFile(tmp_file_name.c_str()));
@@ -2854,8 +2858,6 @@
   bool multi_image_;
   bool is_host_;
   std::string android_root_;
-  // Dex files we are compiling, does not include the class path dex files.
-  std::vector<const DexFile*> dex_files_;
   std::string no_inline_from_string_;
   CompactDexLevel compact_dex_level_ = kDefaultCompactDexLevel;
 
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h
index 2acdf25..66b37fb 100644
--- a/dex2oat/linker/image_test.h
+++ b/dex2oat/linker/image_test.h
@@ -63,9 +63,6 @@
   std::vector<ScratchFile> vdex_files;
   std::string image_dir;
 
-  void Compile(CompilerDriver* driver,
-               ImageHeader::StorageMode storage_mode);
-
   std::vector<size_t> GetImageObjectSectionSizes();
 
   ~CompilationHelper();
@@ -81,7 +78,7 @@
   void TestWriteRead(ImageHeader::StorageMode storage_mode);
 
   void Compile(ImageHeader::StorageMode storage_mode,
-               CompilationHelper& out_helper,
+               /*out*/ CompilationHelper& out_helper,
                const std::string& extra_dex = "",
                const std::initializer_list<std::string>& image_classes = {});
 
@@ -111,6 +108,8 @@
   }
 
  private:
+  void DoCompile(ImageHeader::StorageMode storage_mode, /*out*/ CompilationHelper& out_helper);
+
   HashSet<std::string> image_classes_;
 };
 
@@ -141,12 +140,13 @@
   return ret;
 }
 
-inline void CompilationHelper::Compile(CompilerDriver* driver,
-                                       ImageHeader::StorageMode storage_mode) {
+inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode,
+                                 /*out*/ CompilationHelper& out_helper) {
+  CompilerDriver* driver = compiler_driver_.get();
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   std::vector<const DexFile*> class_path = class_linker->GetBootClassPath();
 
-  for (const std::unique_ptr<const DexFile>& dex_file : extra_dex_files) {
+  for (const std::unique_ptr<const DexFile>& dex_file : out_helper.extra_dex_files) {
     {
       ScopedObjectAccess soa(Thread::Current());
       // Inject in boot class path so that the compiler driver can see it.
@@ -157,7 +157,7 @@
 
   // Enable write for dex2dex.
   for (const DexFile* dex_file : class_path) {
-    dex_file_locations.push_back(dex_file->GetLocation());
+    out_helper.dex_file_locations.push_back(dex_file->GetLocation());
     if (dex_file->IsReadOnly()) {
       dex_file->EnableWrite();
     }
@@ -168,31 +168,31 @@
     for (int i = 0; i < static_cast<int>(class_path.size()); ++i) {
       std::string cur_location =
           android::base::StringPrintf("%s-%d.art", location.GetFilename().c_str(), i);
-      image_locations.push_back(ScratchFile(cur_location));
+      out_helper.image_locations.push_back(ScratchFile(cur_location));
     }
   }
   std::vector<std::string> image_filenames;
-  for (ScratchFile& file : image_locations) {
+  for (ScratchFile& file : out_helper.image_locations) {
     std::string image_filename(GetSystemImageFilename(file.GetFilename().c_str(), kRuntimeISA));
     image_filenames.push_back(image_filename);
     size_t pos = image_filename.rfind('/');
     CHECK_NE(pos, std::string::npos) << image_filename;
-    if (image_dir.empty()) {
-      image_dir = image_filename.substr(0, pos);
-      int mkdir_result = mkdir(image_dir.c_str(), 0700);
-      CHECK_EQ(0, mkdir_result) << image_dir;
+    if (out_helper.image_dir.empty()) {
+      out_helper.image_dir = image_filename.substr(0, pos);
+      int mkdir_result = mkdir(out_helper.image_dir.c_str(), 0700);
+      CHECK_EQ(0, mkdir_result) << out_helper.image_dir;
     }
-    image_files.push_back(ScratchFile(OS::CreateEmptyFile(image_filename.c_str())));
+    out_helper.image_files.push_back(ScratchFile(OS::CreateEmptyFile(image_filename.c_str())));
   }
 
   std::vector<std::string> oat_filenames;
   std::vector<std::string> vdex_filenames;
   for (const std::string& image_filename : image_filenames) {
     std::string oat_filename = ReplaceFileExtension(image_filename, "oat");
-    oat_files.push_back(ScratchFile(OS::CreateEmptyFile(oat_filename.c_str())));
+    out_helper.oat_files.push_back(ScratchFile(OS::CreateEmptyFile(oat_filename.c_str())));
     oat_filenames.push_back(oat_filename);
     std::string vdex_filename = ReplaceFileExtension(image_filename, "vdex");
-    vdex_files.push_back(ScratchFile(OS::CreateEmptyFile(vdex_filename.c_str())));
+    out_helper.vdex_files.push_back(ScratchFile(OS::CreateEmptyFile(vdex_filename.c_str())));
     vdex_filenames.push_back(vdex_filename);
   }
 
@@ -224,7 +224,7 @@
       jobject class_loader = nullptr;
       TimingLogger timings("ImageTest::WriteRead", false, false);
       TimingLogger::ScopedTiming t("CompileAll", &timings);
-      driver->SetDexFilesForOatFile(class_path);
+      SetDexFilesForOatFile(class_path);
       driver->CompileAll(class_loader, class_path, &timings);
 
       t.NewTiming("WriteElf");
@@ -241,7 +241,7 @@
 
       std::vector<std::unique_ptr<ElfWriter>> elf_writers;
       std::vector<std::unique_ptr<OatWriter>> oat_writers;
-      for (ScratchFile& oat_file : oat_files) {
+      for (ScratchFile& oat_file : out_helper.oat_files) {
         elf_writers.emplace_back(CreateElfWriterQuick(driver->GetInstructionSet(),
                                                       driver->GetInstructionSetFeatures(),
                                                       &driver->GetCompilerOptions(),
@@ -270,7 +270,7 @@
         std::vector<std::unique_ptr<MemMap>> cur_opened_dex_files_maps;
         std::vector<std::unique_ptr<const DexFile>> cur_opened_dex_files;
         bool dex_files_ok = oat_writers[i]->WriteAndOpenDexFiles(
-            vdex_files[i].GetFile(),
+            out_helper.vdex_files[i].GetFile(),
             rodata.back(),
             driver->GetInstructionSet(),
             driver->GetInstructionSetFeatures(),
@@ -297,8 +297,8 @@
       bool image_space_ok = writer->PrepareImageAddressSpace(&timings);
       ASSERT_TRUE(image_space_ok);
 
-      DCHECK_EQ(vdex_files.size(), oat_files.size());
-      for (size_t i = 0, size = oat_files.size(); i != size; ++i) {
+      DCHECK_EQ(out_helper.vdex_files.size(), out_helper.oat_files.size());
+      for (size_t i = 0, size = out_helper.oat_files.size(); i != size; ++i) {
         MultiOatRelativePatcher patcher(driver->GetInstructionSet(),
                                         driver->GetInstructionSetFeatures(),
                                         driver->GetCompiledMethodStorage());
@@ -309,7 +309,7 @@
 
         std::unique_ptr<BufferedOutputStream> vdex_out =
             std::make_unique<BufferedOutputStream>(
-                std::make_unique<FileOutputStream>(vdex_files[i].GetFile()));
+                std::make_unique<FileOutputStream>(out_helper.vdex_files[i].GetFile()));
         oat_writer->WriteVerifierDeps(vdex_out.get(), nullptr);
         oat_writer->WriteQuickeningInfo(vdex_out.get());
         oat_writer->WriteChecksumsAndVdexHeader(vdex_out.get());
@@ -366,8 +366,7 @@
       const char* oat_filename = oat_filenames[i].c_str();
       std::unique_ptr<File> oat_file(OS::OpenFileReadWrite(oat_filename));
       ASSERT_TRUE(oat_file != nullptr);
-      bool success_fixup = ElfWriter::Fixup(oat_file.get(),
-                                            writer->GetOatDataBegin(i));
+      bool success_fixup = ElfWriter::Fixup(oat_file.get(), writer->GetOatDataBegin(i));
       ASSERT_TRUE(success_fixup);
       ASSERT_EQ(oat_file->FlushCloseOrErase(), 0) << "Could not flush and close oat file "
                                                   << oat_filename;
@@ -389,7 +388,7 @@
   if (!extra_dex.empty()) {
     helper.extra_dex_files = OpenTestDexFiles(extra_dex.c_str());
   }
-  helper.Compile(compiler_driver_.get(), storage_mode);
+  DoCompile(storage_mode, helper);
   if (image_classes.begin() != image_classes.end()) {
     // Make sure the class got initialized.
     ScopedObjectAccess soa(Thread::Current());
diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc
index b98dc68..bb730d3 100644
--- a/dex2oat/linker/image_writer.cc
+++ b/dex2oat/linker/image_writer.cc
@@ -442,7 +442,7 @@
   // Prepare dex cache array starts based on the ordering specified in the CompilerDriver.
   // Set the slot size early to avoid DCHECK() failures in IsImageBinSlotAssigned()
   // when AssignImageBinSlot() assigns their indexes out or order.
-  for (const DexFile* dex_file : compiler_driver_.GetDexFilesForOatFile()) {
+  for (const DexFile* dex_file : compiler_driver_.GetCompilerOptions().GetDexFilesForOatFile()) {
     auto it = dex_file_oat_index_map_.find(dex_file);
     DCHECK(it != dex_file_oat_index_map_.end()) << dex_file->GetLocation();
     ImageInfo& image_info = GetImageInfo(it->second);
@@ -1738,7 +1738,7 @@
   WorkStack work_stack;
 
   // Special case interned strings to put them in the image they are likely to be resolved from.
-  for (const DexFile* dex_file : compiler_driver_.GetDexFilesForOatFile()) {
+  for (const DexFile* dex_file : compiler_driver_.GetCompilerOptions().GetDexFilesForOatFile()) {
     auto it = dex_file_oat_index_map_.find(dex_file);
     DCHECK(it != dex_file_oat_index_map_.end()) << dex_file->GetLocation();
     const size_t oat_index = it->second;
diff --git a/dex2oat/linker/oat_writer_test.cc b/dex2oat/linker/oat_writer_test.cc
index 2bc286a..e43a7f3 100644
--- a/dex2oat/linker/oat_writer_test.cc
+++ b/dex2oat/linker/oat_writer_test.cc
@@ -409,7 +409,7 @@
   jobject class_loader = nullptr;
   if (kCompile) {
     TimingLogger timings2("OatTest::WriteRead", false, false);
-    compiler_driver_->SetDexFilesForOatFile(class_linker->GetBootClassPath());
+    SetDexFilesForOatFile(class_linker->GetBootClassPath());
     compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), &timings2);
   }
 
@@ -547,7 +547,7 @@
     ScopedObjectAccess soa(Thread::Current());
     class_linker->RegisterDexFile(*dex_file, soa.Decode<mirror::ClassLoader>(class_loader));
   }
-  compiler_driver_->SetDexFilesForOatFile(dex_files);
+  SetDexFilesForOatFile(dex_files);
   compiler_driver_->CompileAll(class_loader, dex_files, &timings);
 
   ScratchFile tmp_base, tmp_oat(tmp_base, ".oat"), tmp_vdex(tmp_base, ".vdex");