odrefresh: Add an option to set the boot image compiler filter.

Bug: 233030966
Test: atest art_standalone_odrefresh_tests
Change-Id: I9ccba18efa3ae4a2e941f1503c473712c54569d1
diff --git a/odrefresh/odr_config.h b/odrefresh/odr_config.h
index ce46d9f..c3b0583 100644
--- a/odrefresh/odr_config.h
+++ b/odrefresh/odr_config.h
@@ -83,6 +83,7 @@
   InstructionSet isa_;
   std::string program_name_;
   std::string system_server_classpath_;
+  std::string boot_image_compiler_filter_;
   std::string system_server_compiler_filter_;
   ZygoteKind zygote_kind_;
   std::string boot_classpath_;
@@ -165,6 +166,9 @@
   const std::string& GetSystemServerClasspath() const {
     return system_server_classpath_;
   }
+  const std::string& GetBootImageCompilerFilter() const {
+    return boot_image_compiler_filter_;
+  }
   const std::string& GetSystemServerCompilerFilter() const {
     return system_server_compiler_filter_;
   }
@@ -201,6 +205,9 @@
     system_server_classpath_ = classpath;
   }
 
+  void SetBootImageCompilerFilter(const std::string& filter) {
+    boot_image_compiler_filter_ = filter;
+  }
   void SetSystemServerCompilerFilter(const std::string& filter) {
     system_server_compiler_filter_ = filter;
   }
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 272b8ef..0f0f7f1 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -1446,7 +1446,12 @@
     *error_msg = "Missing boot image profile";
     return false;
   }
-  args.emplace_back("--compiler-filter=speed-profile");
+  const std::string& compiler_filter = config_.GetBootImageCompilerFilter();
+  if (!compiler_filter.empty()) {
+    args.emplace_back("--compiler-filter=" + compiler_filter);
+  } else {
+    args.emplace_back("--compiler-filter=speed-profile");
+  }
 
   // Compile as a single image for fewer files and slightly less memory overhead.
   args.emplace_back("--single-image");
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 85557af..d0378e8 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -143,6 +143,8 @@
       config->SetArtifactDirectory(GetApexDataDalvikCacheDirectory(art::InstructionSet::kNone));
     } else if (ArgumentMatches(arg, "--zygote-arch=", &value)) {
       zygote = value;
+    } else if (ArgumentMatches(arg, "--boot-image-compiler-filter=", &value)) {
+      config->SetBootImageCompilerFilter(value);
     } else if (ArgumentMatches(arg, "--system-server-compiler-filter=", &value)) {
       config->SetSystemServerCompilerFilter(value);
     } else if (ArgumentMatches(arg, "--staging-dir=", &value)) {
@@ -225,6 +227,9 @@
   UsageMsg("--staging-dir=<DIR>              Write temporary artifacts to <DIR> rather than");
   UsageMsg("                                 .../staging");
   UsageMsg("--zygote-arch=<STRING>           Zygote kind that overrides ro.zygote");
+  UsageMsg("--boot-image-compiler-filter=<STRING>");
+  UsageMsg("                                 Compiler filter for the boot image. Default: ");
+  UsageMsg("                                 speed-profile");
   UsageMsg("--system-server-compiler-filter=<STRING>");
   UsageMsg("                                 Compiler filter that overrides");
   UsageMsg("                                 dalvik.vm.systemservercompilerfilter");
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index 69564a5..2457da5 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -255,11 +255,41 @@
                   Contains(Concatenate({"--dex-file=", framework_jar_})),
                   Contains(FlagContains("--dex-fd=", FdOf(core_oj_jar_))),
                   Contains(FlagContains("--dex-fd=", FdOf(framework_jar_))),
-                  Contains(FlagContains("--profile-file-fd=", FdOf(art_profile_))),
-                  Contains(FlagContains("--profile-file-fd=", FdOf(framework_profile_))),
                   Contains(Concatenate({"--oat-location=", dalvik_cache_dir_, "/x86_64/boot.oat"})),
-                  Contains(HasSubstr("--base=")),
-                  Contains("--compiler-filter=speed-profile"))))
+                  Contains(HasSubstr("--base=")))))
+      .WillOnce(Return(0));
+
+  EXPECT_EQ(odrefresh_->Compile(*metrics_,
+                                CompilationOptions{
+                                    .compile_boot_classpath_for_isas = {InstructionSet::kX86_64},
+                                }),
+            ExitCode::kCompilationSuccess);
+}
+
+TEST_F(OdRefreshTest, BootClasspathJarsWithExplicitCompilerFilter) {
+  config_.SetBootImageCompilerFilter("speed");
+
+  // Profiles should still be passed.
+  EXPECT_CALL(*mock_exec_utils_,
+              DoExecAndReturnCode(
+                  AllOf(Contains(FlagContains("--profile-file-fd=", FdOf(art_profile_))),
+                        Contains(FlagContains("--profile-file-fd=", FdOf(framework_profile_))),
+                        Contains("--compiler-filter=speed"))))
+      .WillOnce(Return(0));
+
+  EXPECT_EQ(odrefresh_->Compile(*metrics_,
+                                CompilationOptions{
+                                    .compile_boot_classpath_for_isas = {InstructionSet::kX86_64},
+                                }),
+            ExitCode::kCompilationSuccess);
+}
+
+TEST_F(OdRefreshTest, BootClasspathJarsWithDefaultCompilerFilter) {
+  EXPECT_CALL(*mock_exec_utils_,
+              DoExecAndReturnCode(
+                  AllOf(Contains(FlagContains("--profile-file-fd=", FdOf(art_profile_))),
+                        Contains(FlagContains("--profile-file-fd=", FdOf(framework_profile_))),
+                        Contains("--compiler-filter=speed-profile"))))
       .WillOnce(Return(0));
 
   EXPECT_EQ(odrefresh_->Compile(*metrics_,