Make compiling an apex image explicit.

And when compiling an apex image, discard dex files not present
in an apex.

Test: m
Bug: 119800099
Change-Id: Ie91c5b8d271783f04e4c1501f315a3ec59137475
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 5373435..540b8a6 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -930,6 +930,14 @@
 }
 
 bool CompilerDriver::ShouldCompileBasedOnProfile(const MethodReference& method_ref) const {
+  // If compiling the apex image, filter out methods not in an apex file (the profile used
+  // for boot classpath is the same between the apex image and the boot image, so it includes
+  /// framewkro methods).
+  if (compiler_options_->IsApexBootImage() &&
+      !android::base::StartsWith(method_ref.dex_file->GetLocation(), "/apex")) {
+    return false;
+  }
+
   // Profile compilation info may be null if no profile is passed.
   if (!CompilerFilter::DependsOnProfile(compiler_options_->GetCompilerFilter())) {
     // Use the compiler filter instead of the presence of profile_compilation_info_ since
@@ -950,6 +958,7 @@
     LOG(INFO) << "[ProfileGuidedCompilation] "
         << (result ? "Compiled" : "Skipped") << " method:" << method_ref.PrettyMethod(true);
   }
+
   return result;
 }