Don't pass empty profile to OatWriter

Doing so causes dexlayout to run and unnecessarily increases dex2oat
time. This change passes null if the profile is empty to fix this.

Bug: 77719042
Test: test-art-host

(cherry picked from commit cc2cd98c21f77c8ae368988d380827811be2dc9d)

Merged-In: Id663d2cbf32dae57f0b562a1f5263293869727d7
Change-Id: I4599f4784c7d2ac3f5e759249226ca9d155efc31
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index e217769..d2a8154 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -2524,7 +2524,10 @@
                                                              compiler_options_.get(),
                                                              oat_file.get()));
       elf_writers_.back()->Start();
-      const bool do_oat_writer_layout = DoDexLayoutOptimizations() || DoOatLayoutOptimizations();
+      bool do_oat_writer_layout = DoDexLayoutOptimizations() || DoOatLayoutOptimizations();
+      if (profile_compilation_info_ != nullptr && profile_compilation_info_->IsEmpty()) {
+        do_oat_writer_layout = false;
+      }
       oat_writers_.emplace_back(new linker::OatWriter(
           IsBootImage(),
           timings_,
diff --git a/runtime/jit/profile_compilation_info.h b/runtime/jit/profile_compilation_info.h
index f8334ce..79cb461 100644
--- a/runtime/jit/profile_compilation_info.h
+++ b/runtime/jit/profile_compilation_info.h
@@ -440,6 +440,9 @@
   // the method returns false. Otherwise it returns true.
   bool UpdateProfileKeys(const std::vector<std::unique_ptr<const DexFile>>& dex_files);
 
+  // Checks if the profile is empty.
+  bool IsEmpty() const;
+
  private:
   enum ProfileLoadStatus {
     kProfileLoadWouldOverwiteData,
@@ -587,9 +590,6 @@
   // the key or the checksum mismatches.
   const DexFileData* FindDexData(const DexFile* dex_file) const;
 
-  // Checks if the profile is empty.
-  bool IsEmpty() const;
-
   // Inflate the input buffer (in_buffer) of size in_size. It returns a buffer of
   // compressed data for the input buffer of "compressed_data_size" size.
   std::unique_ptr<uint8_t[]> DeflateBuffer(const uint8_t* in_buffer,