Call dex2oat and runtime hooks when creating / loading oat/dex files.

Test: m
Bug: 162715919
Bug: 134558686
Change-Id: I293310106b8dcd7bec22d8790fd5f72b315776a8
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 8bb8bd6..6e484b7 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -93,6 +93,7 @@
 #include "oat.h"
 #include "oat_file.h"
 #include "oat_file_assistant.h"
+#include "palette/palette.h"
 #include "profile/profile_compilation_info.h"
 #include "runtime.h"
 #include "runtime_options.h"
@@ -1699,6 +1700,16 @@
       callbacks_->SetVerifierDeps(new verifier::VerifierDeps(dex_files));
     }
 
+    // Now that the FDs have been setup, report that we're starting the
+    // compilation.
+    PaletteHooks* hooks = nullptr;
+    if (PaletteGetHooks(&hooks) == PaletteStatus::kOkay) {
+      hooks->NotifyStartDex2oatCompilation(zip_fd_,
+                                           IsAppImage() ? app_image_fd_ : image_fd_,
+                                           oat_fd_,
+                                           output_vdex_fd_);
+    }
+
     return dex2oat::ReturnCode::kNoFailure;
   }
 
@@ -2122,6 +2133,16 @@
       }
     }
 
+    // Now that the files have been written to, report that we're starting the
+    // compilation.
+    PaletteHooks* hooks = nullptr;
+    if (PaletteGetHooks(&hooks) == PaletteStatus::kOkay) {
+      hooks->NotifyEndDex2oatCompilation(zip_fd_,
+                                         IsAppImage() ? app_image_fd_ : image_fd_,
+                                         oat_fd_,
+                                         output_vdex_fd_);
+    }
+
     return true;
   }
 
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index bf32f3e..3467a57 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4287,6 +4287,11 @@
     // remembered sets and generational GCs.
     WriteBarrier::ForEveryFieldWrite(h_class_loader.Get());
   }
+  PaletteHooks* hooks = nullptr;
+  VLOG(class_linker) << "Registered dex file " << dex_file.GetLocation();
+  if (PaletteGetHooks(&hooks) == PaletteStatus::kOkay) {
+    hooks->NotifyDexFileLoaded(dex_file.GetLocation().c_str());
+  }
   return h_dex_cache.Get();
 }
 
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 85992ea..8c6d872 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -65,6 +65,13 @@
 static constexpr bool kEnableAppImage = true;
 
 const OatFile* OatFileManager::RegisterOatFile(std::unique_ptr<const OatFile> oat_file) {
+  // Use class_linker vlog to match the log for dex file registration.
+  VLOG(class_linker) << "Registered oat file " << oat_file->GetLocation();
+  PaletteHooks* hooks = nullptr;
+  if (PaletteGetHooks(&hooks) == PaletteStatus::kOkay) {
+    hooks->NotifyOatFileLoaded(oat_file->GetLocation().c_str());
+  }
+
   WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
   CHECK(!only_use_system_oat_files_ ||
         LocationIsOnSystem(oat_file->GetLocation().c_str()) ||