Revert "Revert "Integrate ClassLoaderContext check in OatFileAssistant::GetBestOatFile.""

This reverts commit 656fdcd7f2aa9920ecd464dbb59d284e17969baa.

Bug: 176960283

Reason for revert: Racy code fixed in https://android-review.googlesource.com/c/platform/art/+/1678727

Change-Id: I7561aa8fad060bd076006dd4b1fbffc076834635
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index e771dcc..50b54af 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -80,6 +80,10 @@
     // dex file, but is out of date with respect to the boot image.
     kOatBootImageOutOfDate,
 
+    // kOatContextOutOfDate - The context in the oat file is out of date with
+    // respect to the class loader context.
+    kOatContextOutOfDate,
+
     // kOatUpToDate - The oat file is completely up to date with respect to
     // the dex file and boot image.
     kOatUpToDate,
@@ -107,6 +111,7 @@
   // only oat files from /system loaded executable.
   OatFileAssistant(const char* dex_location,
                    const InstructionSet isa,
+                   ClassLoaderContext* context,
                    bool load_executable,
                    bool only_load_system_executable = false);
 
@@ -115,6 +120,7 @@
   // Otherwise, dex_location will be used to construct necessary filenames.
   OatFileAssistant(const char* dex_location,
                    const InstructionSet isa,
+                   ClassLoaderContext* context,
                    bool load_executable,
                    bool only_load_system_executable,
                    int vdex_fd,
@@ -142,8 +148,6 @@
   // the oat location. Returns a negative status code if the status refers to
   // the oat file in the odex location.
   int GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
-                      ClassLoaderContext* context,
-                      const std::vector<int>& context_fds,
                       bool profile_changed = false,
                       bool downgrade = false);
 
@@ -227,6 +231,10 @@
   // Returns the status of the oat file for the dex location.
   OatStatus OatFileStatus();
 
+  OatStatus GetBestStatus() {
+    return GetBestInfo().Status();
+  }
+
   // Constructs the odex file name for the given dex location.
   // Returns true on success, in which case odex_filename is set to the odex
   // file name.
@@ -262,6 +270,8 @@
   // anonymous dex file(s) created by AnonymousDexVdexLocation.
   static bool IsAnonymousVdexBasename(const std::string& basename);
 
+  bool ClassLoaderContextIsOkay(const OatFile& oat_file) const;
+
  private:
   class OatFileInfo {
    public:
@@ -294,8 +304,6 @@
     // downgrade should be true if the purpose of dexopt is to downgrade the
     // compiler filter.
     DexOptNeeded GetDexOptNeeded(CompilerFilter::Filter target_compiler_filter,
-                                 ClassLoaderContext* context,
-                                 const std::vector<int>& context_fds,
                                  bool profile_changed,
                                  bool downgrade);
 
@@ -338,8 +346,6 @@
     // compiler filter.
     bool CompilerFilterIsOkay(CompilerFilter::Filter target, bool profile_changed, bool downgrade);
 
-    bool ClassLoaderContextIsOkay(ClassLoaderContext* context, const std::vector<int>& context_fds);
-
     // Release the loaded oat file.
     // Returns null if the oat file hasn't been loaded.
     //
@@ -407,6 +413,8 @@
 
   std::string dex_location_;
 
+  ClassLoaderContext* context_;
+
   // Whether or not the parent directory of the dex file is writable.
   bool dex_parent_writable_ = false;