ART: Conditionally remove loaded-oat-count check

In the case of the system server, oat files may be loaded before the
check applies.

Bug: 128688902
Test: m
Test: manual
Merged-In: I1c12463e905115e858cc0c52711dd82a4f06425d
Change-Id: I1c12463e905115e858cc0c52711dd82a4f06425d
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index 7194f9e..dd76ce5 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -290,7 +290,7 @@
   }
 
   if ((runtime_flags & ONLY_USE_SYSTEM_OAT_FILES) != 0 || is_system_server) {
-    runtime->GetOatFileManager().SetOnlyUseSystemOatFiles();
+    runtime->GetOatFileManager().SetOnlyUseSystemOatFiles(!is_system_server);
     runtime_flags &= ~ONLY_USE_SYSTEM_OAT_FILES;
   }
 
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 5aa1ea2..b03551b 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -642,9 +642,11 @@
   return dex_files;
 }
 
-void OatFileManager::SetOnlyUseSystemOatFiles() {
+void OatFileManager::SetOnlyUseSystemOatFiles(bool assert_no_files_loaded) {
   ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
-  CHECK_EQ(oat_files_.size(), GetBootOatFiles().size());
+  if (assert_no_files_loaded) {
+    CHECK_EQ(oat_files_.size(), GetBootOatFiles().size());
+  }
   only_use_system_oat_files_ = true;
 }
 
diff --git a/runtime/oat_file_manager.h b/runtime/oat_file_manager.h
index 99e1b73..9c6c04b 100644
--- a/runtime/oat_file_manager.h
+++ b/runtime/oat_file_manager.h
@@ -101,7 +101,7 @@
 
   void DumpForSigQuit(std::ostream& os);
 
-  void SetOnlyUseSystemOatFiles();
+  void SetOnlyUseSystemOatFiles(bool assert_no_files_loaded);
 
  private:
   enum class CheckCollisionResult {
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 33ec088..8223fb8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1693,7 +1693,7 @@
 
   // Set OnlyUseSystemOatFiles only after boot classpath has been set up.
   if (runtime_options.Exists(Opt::OnlyUseSystemOatFiles)) {
-    oat_file_manager_->SetOnlyUseSystemOatFiles();
+    oat_file_manager_->SetOnlyUseSystemOatFiles(/*assert_no_files_loaded=*/ true);
   }
 
   return true;