Clear shared method bit when doing boot image profiling.

Otherwise, the profile saver thinks all methods in the boot image are
hot.

Test: 595-profile-saving
Bug: 223366272
Change-Id: Ieff95a6fe11cabfa9b3ccf1364b8dae080d08cf8
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 64adc55..c8dbc75 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1983,6 +1983,16 @@
   }
 
   if (!runtime->IsAotCompiler()) {
+    // If we are profiling the boot classpath, disable the shared memory for
+    // boot image method optimization. We need to disable it before doing
+    // ResetCounter below, as counters of shared memory method always hold the
+    // "hot" value.
+    if (runtime->GetJITOptions()->GetProfileSaverOptions().GetProfileBootClassPath()) {
+      header.VisitPackedArtMethods([&](ArtMethod& method) REQUIRES_SHARED(Locks::mutator_lock_) {
+        method.ClearMemorySharedMethod();
+      }, space->Begin(), image_pointer_size_);
+    }
+
     ScopedTrace trace("AppImage:UpdateCodeItemAndNterp");
     bool can_use_nterp = interpreter::CanRuntimeUseNterp();
     uint16_t hotness_threshold = runtime->GetJITOptions()->GetWarmupThreshold();
@@ -3762,7 +3772,8 @@
     }
   }
 
-  if (Runtime::Current()->IsZygote()) {
+  if (Runtime::Current()->IsZygote() &&
+      !Runtime::Current()->GetJITOptions()->GetProfileSaverOptions().GetProfileBootClassPath()) {
     dst->SetMemorySharedMethod();
   }
 }