profman: Record all dex files in boot image profile.

(cherry picked from commit 9c7b1e7073f3c309e8b0023974aa9136b22f4b2e)

Test: m  # and check boot-profile.prof with hexdump.
Test: Manual; use jitzygote system properties and check that
      dex2oat is compiling expected dex files for the boot
      image extention during zygote start.
Bug: 177980172
Merged-In: I2cb0ae90d2d06a1b65fd1abe6ff437cbbb9884b6
Change-Id: I12ec941c113ff095b2fd21b6585b2572f5df9891
diff --git a/profman/profman.cc b/profman/profman.cc
index 56c504b..1968468 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -1735,6 +1735,17 @@
     bool for_boot_image = GetOutputProfileType() == OutputProfileType::kBoot;
     ProfileCompilationInfo info(for_boot_image);
 
+    if (for_boot_image) {
+      // Add all dex files to the profile. This is needed for jitzygote to indicate
+      // which dex files are part of the boot image extension to compile in memory.
+      for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
+        if (info.FindOrAddDexFile(*dex_file) == info.MaxProfileIndex()) {
+          LOG(ERROR) << "Failed to add dex file to boot image profile: " << dex_file->GetLocation();
+          return -1;
+        }
+      }
+    }
+
     for (const auto& line : *user_lines) {
       ProcessLine(dex_files, line, &info);
     }