Revert^2 "Fix CompilerDriver's handling of boot image extension."

This reverts commit 96d8585ebb9e21fc27a59ddd4173ca62ad93c194.

Fixed verification from oat files when compiling a boot
image extension. Normal verification can fail if the
primary boot image is quickened.

Test: `art/tools/buildbot-build.sh --target` with master-art manifest
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 119800099
Bug: 144751090
Change-Id: Ibc4e7ab1ec8451c9b5c87b6e87ab9807ac22e284
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index f1e7d8c..e23bedf 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1936,6 +1936,8 @@
     if (!IsBootImage() && !IsBootImageExtension()) {
       class_loader =
           class_loader_context_->CreateClassLoader(compiler_options_->dex_files_for_oat_file_);
+    }
+    if (!IsBootImage()) {
       callbacks_->SetDexFiles(&dex_files);
     }
 
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 4721796..f3c103b 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -326,9 +326,9 @@
   CheckThreadPools();
 
   if (GetCompilerOptions().IsBootImage()) {
-    // We don't need to setup the intrinsics for non boot image compilation, as
-    // those compilations will pick up a boot image that have the ArtMethod already
-    // set with the intrinsics flag.
+    // All intrinsics must be in the primary boot image, so we don't need to setup
+    // the intrinsics for any other compilation, as those compilations will pick up
+    // a boot image that have the ArtMethod already set with the intrinsics flag.
     InitializeIntrinsics();
   }
   // Compile:
@@ -888,7 +888,8 @@
   Verify(class_loader, dex_files, timings, verification_results);
   VLOG(compiler) << "Verify: " << GetMemoryUsageString(false);
 
-  if (GetCompilerOptions().IsForceDeterminism() && GetCompilerOptions().IsBootImage()) {
+  if (GetCompilerOptions().IsForceDeterminism() &&
+      (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension())) {
     // Resolve strings from const-string. Do this now to have a deterministic image.
     ResolveConstStrings(dex_files, /*only_startup_strings=*/ false, timings);
     VLOG(compiler) << "Resolve const-strings: " << GetMemoryUsageString(false);
@@ -1744,7 +1745,7 @@
 
   ParallelCompilationManager context(class_linker, class_loader, this, &dex_file, dex_files,
                                      thread_pool);
-  if (GetCompilerOptions().IsBootImage()) {
+  if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) {
     // For images we resolve all types, such as array, whereas for applications just those with
     // classdefs are resolved by ResolveClassFieldsAndMethods.
     TimingLogger::ScopedTiming t("Resolve Types", timings);
@@ -1888,7 +1889,7 @@
   // the existing `verifier_deps` is not valid anymore, create a new one for
   // non boot image compilation. The verifier will need it to record the new dependencies.
   // Then dex2oat can update the vdex file with these new dependencies.
-  if (!GetCompilerOptions().IsBootImage()) {
+  if (!GetCompilerOptions().IsBootImage() && !GetCompilerOptions().IsBootImageExtension()) {
     // Dex2oat creates the verifier deps.
     // Create the main VerifierDeps, and set it to this thread.
     verifier::VerifierDeps* verifier_deps =
@@ -1918,7 +1919,7 @@
                   timings);
   }
 
-  if (!GetCompilerOptions().IsBootImage()) {
+  if (!GetCompilerOptions().IsBootImage() && !GetCompilerOptions().IsBootImageExtension()) {
     // Merge all VerifierDeps into the main one.
     verifier::VerifierDeps* verifier_deps = Thread::Current()->GetVerifierDeps();
     for (ThreadPoolWorker* worker : parallel_thread_pool_->GetWorkers()) {
@@ -2034,7 +2035,8 @@
       //   --abort-on-hard-verifier-error --abort-on-soft-verifier-error
       // which is the default build system configuration.
       if (kIsDebugBuild) {
-        if (manager_->GetCompiler()->GetCompilerOptions().IsBootImage()) {
+        if (manager_->GetCompiler()->GetCompilerOptions().IsBootImage() ||
+            manager_->GetCompiler()->GetCompilerOptions().IsBootImageExtension()) {
           if (!klass->IsResolved() || klass->IsErroneous()) {
             LOG(FATAL) << "Boot classpath class " << klass->PrettyClass()
                        << " failed to resolve/is erroneous: state= " << klass->GetStatus();
@@ -2569,8 +2571,10 @@
   ParallelCompilationManager context(class_linker, jni_class_loader, this, &dex_file, dex_files,
                                      init_thread_pool);
 
-  if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsAppImage()) {
-    // Set the concurrency thread to 1 to support initialization for App Images since transaction
+  if (GetCompilerOptions().IsBootImage() ||
+      GetCompilerOptions().IsBootImageExtension() ||
+      GetCompilerOptions().IsAppImage()) {
+    // Set the concurrency thread to 1 to support initialization for images since transaction
     // doesn't support multithreading now.
     // TODO: remove this when transactional mode supports multithreading.
     init_thread_count = 1U;
@@ -2640,7 +2644,9 @@
     CHECK(dex_file != nullptr);
     InitializeClasses(class_loader, *dex_file, dex_files, timings);
   }
-  if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsAppImage()) {
+  if (GetCompilerOptions().IsBootImage() ||
+      GetCompilerOptions().IsBootImageExtension() ||
+      GetCompilerOptions().IsAppImage()) {
     // Make sure that we call EnsureIntiailized on all the array classes to call
     // SetVerificationAttempted so that the access flags are set. If we do not do this they get
     // changed at runtime resulting in more dirty image pages.
@@ -2652,7 +2658,7 @@
     Runtime::Current()->GetClassLinker()->VisitClassesWithoutClassesLock(&visitor);
     visitor.FillAllIMTAndConflictTables();
   }
-  if (GetCompilerOptions().IsBootImage()) {
+  if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) {
     // Prune garbage objects created during aborted transactions.
     Runtime::Current()->GetHeap()->CollectGarbage(/* clear_soft_references= */ true);
   }
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index b813117..438d5cb 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4957,10 +4957,6 @@
   // tell us about the latter.
   if (Runtime::Current()->IsAotCompiler()) {
     CompilerCallbacks* callbacks = Runtime::Current()->GetCompilerCallbacks();
-    // Are we compiling the bootclasspath?
-    if (callbacks->IsBootImage()) {
-      return false;
-    }
     // We are compiling an app (not the image).
     if (!callbacks->CanUseOatStatusForVerification(klass.Ptr())) {
       return false;