Only special case boot image extension for class initialization.

Special case for the mainline extension, which didn't use to get its
classes initialized.

Bug: 274077782

Test: test.py
Change-Id: I1bb92d262c8bedb0ffefd5fa322fa8155d10ceb7
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 3ad696b..23bbe14 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -2179,13 +2179,16 @@
         bool too_many_encoded_fields = (!is_boot_image && !is_boot_image_extension) &&
             klass->NumStaticFields() > kMaxEncodedFields;
 
+        bool have_profile = (compiler_options.GetProfileCompilationInfo() != nullptr) &&
+            !compiler_options.GetProfileCompilationInfo()->IsEmpty();
         // If the class was not initialized, we can proceed to see if we can initialize static
         // fields. Limit the max number of encoded fields.
         if (!klass->IsInitialized() &&
             (is_app_image || is_boot_image || is_boot_image_extension) &&
             try_initialize_with_superclasses && !too_many_encoded_fields &&
             compiler_options.IsImageClass(descriptor) &&
-            compiler_options.IsAotCompilationEnabled()) {
+            // TODO(b/274077782): remove this test.
+            (have_profile || !is_boot_image_extension)) {
           bool can_init_static_fields = false;
           if (is_boot_image || is_boot_image_extension) {
             // We need to initialize static fields, we only do this for image classes that aren't
diff --git a/test/generate-boot-image/generate-boot-image.cc b/test/generate-boot-image/generate-boot-image.cc
index f22bad4..1b3eccf 100644
--- a/test/generate-boot-image/generate-boot-image.cc
+++ b/test/generate-boot-image/generate-boot-image.cc
@@ -109,9 +109,9 @@
   android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
 
   std::string dir = "";
-  // Set the compiler filter to `speed-profile` by default to make test preparation
-  // faster and behave like normal boot image generation.
-  std::string compiler_filter = "speed-profile";
+  // Set the compiler filter to `verify` by default to make test preparation
+  // faster.
+  std::string compiler_filter = "verify";
   for (int i = 1; i < argc; i++) {
     std::string_view arg{argv[i]};
     if (android::base::ConsumePrefix(&arg, "--output-dir=")) {