Support system server ART-profiling

We don't have to map the code cache as executable if we only want to save
profiles. This enables system server profiling without disabling SElinux
to bypass the jit code cache exec-mapping.

Test: m test-art-host
      boot a device with system server profiling enabled.
Bug: 73313191

Change-Id: I7f25a905e0b23456183e39e58ad8f4b829ddf0c5
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index f86b7a0..b8775b8 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -861,7 +861,11 @@
 }
 
 void Runtime::InitNonZygoteOrPostFork(
-    JNIEnv* env, bool is_system_server, NativeBridgeAction action, const char* isa) {
+    JNIEnv* env,
+    bool is_system_server,
+    NativeBridgeAction action,
+    const char* isa,
+    bool profile_system_server) {
   is_zygote_ = false;
 
   if (is_native_bridge_loaded_) {
@@ -884,8 +888,15 @@
   heap_->ResetGcPerformanceInfo();
 
   // We may want to collect profiling samples for system server, but we never want to JIT there.
-  if ((!is_system_server || !jit_options_->UseJitCompilation()) &&
-      !safe_mode_ &&
+  if (is_system_server) {
+    jit_options_->SetUseJitCompilation(false);
+    jit_options_->SetSaveProfilingInfo(profile_system_server);
+    if (profile_system_server) {
+      jit_options_->SetWaitForJitNotificationsToSaveProfile(false);
+      VLOG(profiler) << "Enabling system server profiles";
+    }
+  }
+  if (!safe_mode_ &&
       (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo()) &&
       jit_ == nullptr) {
     // Note that when running ART standalone (not zygote, nor zygote fork),