Remove pvm_exec call from odrefresh

This change removes the proof-of-concept that let odrefresh on Android
schedule dex2oat runs in the VM using pvm_exec. Also removed
--use-compilation-os=$CID flag.

Bug: 211977683
Test: atest art_standalone_odrefresh_tests
Test: atest ComposHostTestCases
Change-Id: Iaf35c933dd6719d31e1641454a537699de5bfda6
diff --git a/odrefresh/odr_config.h b/odrefresh/odr_config.h
index 855b7a2..9a8b6ba 100644
--- a/odrefresh/odr_config.h
+++ b/odrefresh/odr_config.h
@@ -66,7 +66,6 @@
   std::string system_server_classpath_;
   std::string system_server_compiler_filter_;
   ZygoteKind zygote_kind_;
-  int compilation_os_address_ = 0;
   std::string boot_classpath_;
   std::string artifact_dir_;
   time_t max_execution_seconds_ = kMaximumExecutionSeconds;
@@ -148,8 +147,6 @@
   const std::string& GetSystemServerCompilerFilter() const {
     return system_server_compiler_filter_;
   }
-  bool UseCompilationOs() const { return compilation_os_address_ != 0; }
-  int GetCompilationOsAddress() const { return compilation_os_address_; }
   const std::string& GetStagingDir() const {
     return staging_dir_;
   }
@@ -176,7 +173,6 @@
     refresh_ = value;
   }
   void SetIsa(const InstructionSet isa) { isa_ = isa; }
-  void SetCompilationOsAddress(int address) { compilation_os_address_ = address; }
   void SetMaxExecutionSeconds(int seconds) { max_execution_seconds_ = seconds; }
   void SetMaxChildProcessSeconds(int seconds) { max_child_process_seconds_ = seconds; }
 
diff --git a/odrefresh/odr_dexopt.cc b/odrefresh/odr_dexopt.cc
index 99e0814..34e10c2 100644
--- a/odrefresh/odr_dexopt.cc
+++ b/odrefresh/odr_dexopt.cc
@@ -19,7 +19,6 @@
 #include <vector>
 
 #include "android-base/logging.h"
-#include <android-base/result.h>
 #include "android-base/strings.h"
 #include "exec_utils.h"
 #include "log/log.h"
@@ -34,7 +33,6 @@
 
 using aidl::com::android::art::DexoptBcpExtArgs;
 using aidl::com::android::art::DexoptSystemServerArgs;
-using android::base::Result;
 
 namespace {
 
@@ -48,173 +46,37 @@
   return exec_utils->ExecAndReturnCode(cmdline, timeout_secs, timed_out, error_msg);
 }
 
-class OdrDexoptLocal final : public OdrDexopt {
- public:
-  static OdrDexoptLocal* Create(const std::string& dex2oat_path,
-                                std::unique_ptr<ExecUtils> exec_utils) {
-    return new OdrDexoptLocal(dex2oat_path, std::move(exec_utils));
-  }
-
-  int DexoptBcpExtension(const DexoptBcpExtArgs& args,
-                         time_t timeout_secs,
-                         /*out*/ bool* timed_out,
-                         /*out*/ std::string* error_msg) override {
-    std::vector<std::string> cmdline = { dex2oat_path_ };
-    auto result = art::AddDex2oatArgsFromBcpExtensionArgs(args, cmdline);
-    if (!result.ok()) {
-      LOG(ERROR) << "Dexopt (local) failed: " << result.error().message() << ", cmdline: "
-                 << android::base::Join(cmdline, ' ');
-      return -1;
-    }
-    return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
-  }
-
-  int DexoptSystemServer(const DexoptSystemServerArgs& args,
-                         time_t timeout_secs,
-                         /*out*/ bool* timed_out,
-                         /*out*/ std::string* error_msg) override {
-    std::vector<std::string> cmdline = { dex2oat_path_ };
-    auto result = art::AddDex2oatArgsFromSystemServerArgs(args, cmdline);
-    if (!result.ok()) {
-      LOG(ERROR) << "Dexopt (local) failed: " << result.error().message() << ", cmdline: "
-                 << android::base::Join(cmdline, ' ');
-      return -1;
-    }
-    return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
-  }
-
- private:
-  OdrDexoptLocal(const std::string& dex2oat_path, std::unique_ptr<ExecUtils> exec_utils)
-      : dex2oat_path_(dex2oat_path), exec_utils_(std::move(exec_utils)) {}
-
-  std::string dex2oat_path_;
-  std::unique_ptr<ExecUtils> exec_utils_;
-};
-
-class OdrDexoptCompilationOS final : public OdrDexopt {
- public:
-  static OdrDexoptCompilationOS* Create(int cid, std::unique_ptr<ExecUtils> exec_utils) {
-    return new OdrDexoptCompilationOS(cid, std::move(exec_utils));
-  }
-
-  int DexoptBcpExtension(const DexoptBcpExtArgs& args,
-                         time_t timeout_secs,
-                         /*out*/ bool* timed_out,
-                         /*out*/ std::string* error_msg) override {
-    std::vector<int> input_fds, output_fds;
-    collectFdsFromDexoptBcpExtensionArgs(input_fds, output_fds, args);
-
-    std::vector<std::string> cmdline;
-    AppendPvmExecArgs(cmdline, input_fds, output_fds);
-
-    // Original dex2oat flags
-    cmdline.push_back("/apex/com.android.art/bin/dex2oat64");
-    auto result = AddDex2oatArgsFromBcpExtensionArgs(args, cmdline);
-    if (!result.ok()) {
-      LOG(ERROR) << "Dexopt (CompOS) failed: " << result.error().message() << ", cmdline: "
-                 << android::base::Join(cmdline, ' ');
-      return -1;
-    }
-
-    return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
-  }
-
-  int DexoptSystemServer(const DexoptSystemServerArgs& args,
-                         time_t timeout_secs,
-                         /*out*/ bool* timed_out,
-                         /*out*/ std::string* error_msg) override {
-    std::vector<int> input_fds, output_fds;
-    collectFdsFromDexoptSystemServerArgs(input_fds, output_fds, args);
-
-    std::vector<std::string> cmdline;
-    AppendPvmExecArgs(cmdline, input_fds, output_fds);
-
-    // Original dex2oat flags
-    cmdline.push_back("/apex/com.android.art/bin/dex2oat64");
-    auto result = AddDex2oatArgsFromSystemServerArgs(args, cmdline);
-    if (!result.ok()) {
-      LOG(ERROR) << "Dexopt (CompOS) failed: " << result.error().message() << ", cmdline: "
-                 << android::base::Join(cmdline, ' ');
-      return -1;
-    }
-
-    LOG(DEBUG) << "DexoptSystemServer cmdline: " << android::base::Join(cmdline, ' ')
-               << " [timeout " << timeout_secs << "s]";
-    return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
-  }
-
- private:
-  OdrDexoptCompilationOS(int cid, std::unique_ptr<ExecUtils> exec_utils)
-      : cid_(cid), exec_utils_(std::move(exec_utils)) {}
-
-  void AppendPvmExecArgs(/*inout*/ std::vector<std::string>& cmdline,
-                         const std::vector<int>& input_fds,
-                         const std::vector<int>& output_fds) {
-    cmdline.emplace_back("/apex/com.android.compos/bin/pvm_exec");
-    cmdline.emplace_back("--cid=" + std::to_string(cid_));
-    cmdline.emplace_back("--in-fd=" + android::base::Join(input_fds, ','));
-    cmdline.emplace_back("--out-fd=" + android::base::Join(output_fds, ','));
-    cmdline.emplace_back("--");
-  }
-
-  void collectFdsFromDexoptBcpExtensionArgs(/*inout*/ std::vector<int>& input_fds,
-                                            /*inout*/ std::vector<int>& output_fds,
-                                            const DexoptBcpExtArgs& args) {
-    // input
-    insertOnlyNonNegative(input_fds, args.dexFds);
-    insertIfNonNegative(input_fds, args.profileFd);
-    insertIfNonNegative(input_fds, args.dirtyImageObjectsFd);
-    insertOnlyNonNegative(input_fds, args.bootClasspathFds);
-    // output
-    insertIfNonNegative(output_fds, args.imageFd);
-    insertIfNonNegative(output_fds, args.vdexFd);
-    insertIfNonNegative(output_fds, args.oatFd);
-  }
-
-  void collectFdsFromDexoptSystemServerArgs(/*inout*/ std::vector<int>& input_fds,
-                                            /*inout*/ std::vector<int>& output_fds,
-                                            const DexoptSystemServerArgs& args) {
-    // input
-    insertIfNonNegative(input_fds, args.dexFd);
-    insertIfNonNegative(input_fds, args.profileFd);
-    insertOnlyNonNegative(input_fds, args.bootClasspathFds);
-    insertOnlyNonNegative(input_fds, args.bootClasspathImageFds);
-    insertOnlyNonNegative(input_fds, args.bootClasspathVdexFds);
-    insertOnlyNonNegative(input_fds, args.bootClasspathOatFds);
-    insertOnlyNonNegative(input_fds, args.classloaderFds);
-    // output
-    insertIfNonNegative(output_fds, args.imageFd);
-    insertIfNonNegative(output_fds, args.vdexFd);
-    insertIfNonNegative(output_fds, args.oatFd);
-  }
-
-  void insertIfNonNegative(/*inout*/ std::vector<int>& vec, int n) {
-    if (n < 0) {
-      return;
-    }
-    vec.emplace_back(n);
-  }
-
-  void insertOnlyNonNegative(/*inout*/ std::vector<int>& vec, const std::vector<int>& ns) {
-    std::copy_if(ns.begin(), ns.end(), std::back_inserter(vec), [](int n) { return n >= 0; });
-  }
-
-  int cid_;
-  std::unique_ptr<ExecUtils> exec_utils_;
-};
-
 }  // namespace
 
-// static
-std::unique_ptr<OdrDexopt> OdrDexopt::Create(const OdrConfig& config,
-                                             std::unique_ptr<ExecUtils> exec_utils) {
-  if (config.UseCompilationOs()) {
-    int cid = config.GetCompilationOsAddress();
-    return std::unique_ptr<OdrDexopt>(OdrDexoptCompilationOS::Create(cid, std::move(exec_utils)));
-  } else {
-    return std::unique_ptr<OdrDexopt>(OdrDexoptLocal::Create(config.GetDex2Oat(),
-                                                             std::move(exec_utils)));
+OdrDexopt::OdrDexopt(const OdrConfig& config, std::unique_ptr<ExecUtils> exec_utils)
+  : dex2oat_path_(config.GetDex2Oat()), exec_utils_(std::move(exec_utils)) {}
+
+int OdrDexopt::DexoptBcpExtension(const DexoptBcpExtArgs& args,
+                                  time_t timeout_secs,
+                                  /*out*/ bool* timed_out,
+                                  /*out*/ std::string* error_msg) {
+  std::vector<std::string> cmdline = { dex2oat_path_ };
+  auto result = art::AddDex2oatArgsFromBcpExtensionArgs(args, cmdline);
+  if (!result.ok()) {
+    LOG(ERROR) << "Dexopt (local) failed: " << result.error().message() << ", cmdline: "
+               << android::base::Join(cmdline, ' ');
+    return -1;
   }
+  return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
+}
+
+int OdrDexopt::DexoptSystemServer(const DexoptSystemServerArgs& args,
+                                  time_t timeout_secs,
+                                  /*out*/ bool* timed_out,
+                                  /*out*/ std::string* error_msg) {
+  std::vector<std::string> cmdline = { dex2oat_path_ };
+  auto result = art::AddDex2oatArgsFromSystemServerArgs(args, cmdline);
+  if (!result.ok()) {
+    LOG(ERROR) << "Dexopt (local) failed: " << result.error().message() << ", cmdline: "
+               << android::base::Join(cmdline, ' ');
+    return -1;
+  }
+  return ExecAndReturnCode(exec_utils_.get(), cmdline, timeout_secs, timed_out, error_msg);
 }
 
 }  // namespace odrefresh
diff --git a/odrefresh/odr_dexopt.h b/odrefresh/odr_dexopt.h
index 2db3b4a..1233e8b 100644
--- a/odrefresh/odr_dexopt.h
+++ b/odrefresh/odr_dexopt.h
@@ -37,19 +37,24 @@
 
 class OdrDexopt {
  public:
-  static std::unique_ptr<OdrDexopt> Create(const OdrConfig& confg,
-                                           std::unique_ptr<ExecUtils> exec_utils);
+  OdrDexopt(const OdrConfig& config, std::unique_ptr<ExecUtils> exec_utils);
+
+  OdrDexopt() {}  // Test only
 
   virtual ~OdrDexopt() {}
 
   virtual int DexoptBcpExtension(const DexoptBcpExtArgs& args,
                                  time_t timeout_secs,
                                  /*out*/ bool* timed_out,
-                                 /*out*/ std::string* error_msg) = 0;
+                                 /*out*/ std::string* error_msg);
   virtual int DexoptSystemServer(const DexoptSystemServerArgs& args,
                                  time_t timeout_secs,
                                  /*out*/ bool* timed_out,
-                                 /*out*/ std::string* error_msg) = 0;
+                                 /*out*/ std::string* error_msg);
+
+ private:
+  std::string dex2oat_path_;
+  std::unique_ptr<ExecUtils> exec_utils_;
 };
 
 }  // namespace odrefresh
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 767f406..d3cffc6 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -533,7 +533,7 @@
     : OnDeviceRefresh(config,
                       Concatenate({config.GetArtifactDirectory(), "/", kCacheInfoFile}),
                       std::make_unique<ExecUtils>(),
-                      OdrDexopt::Create(config, std::make_unique<ExecUtils>())) {}
+                      std::make_unique<OdrDexopt>(config, std::make_unique<ExecUtils>())) {}
 
 OnDeviceRefresh::OnDeviceRefresh(const OdrConfig& config,
                                  const std::string& cache_info_filename,
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 4e05bf5..8262805 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -129,13 +129,7 @@
   for (; n < argc - 1; ++n) {
     const char* arg = argv[n];
     std::string value;
-    if (ArgumentMatches(arg, "--use-compilation-os=", &value)) {
-      int cid;
-      if (!android::base::ParseInt(value, &cid)) {
-        ArgumentError("Failed to parse CID: %s", value.c_str());
-      }
-      config->SetCompilationOsAddress(cid);
-    } else if (ArgumentEquals(arg, "--compilation-os-mode")) {
+    if (ArgumentEquals(arg, "--compilation-os-mode")) {
       config->SetCompilationOsMode(true);
     } else if (ArgumentMatches(arg, "--dalvik-cache=", &value)) {
       art::OverrideDalvikCacheSubDirectory(value);
@@ -209,8 +203,6 @@
   UsageMsg("--partial-compilation            Only generate artifacts that are out-of-date or");
   UsageMsg("                                 missing.");
   UsageMsg("--no-refresh                     Do not refresh existing artifacts.");
-  UsageMsg("--use-compilation-os=<CID>       Run compilation in the VM with the given CID.");
-  UsageMsg("                                 (0 = do not use VM, -1 = use composd's VM)");
   UsageMsg("--compilation-os-mode            Indicate that odrefresh is running in Compilation");
   UsageMsg("                                 OS.");
   UsageMsg("--dalvik-cache=<DIR>             Write artifacts to .../<DIR> rather than");