jitzygote: Special case system server to keep the JIT queue at fork.

Temporary measure until we have a system server specific profile.

Test: m
Bug: 119800099

(cherry picked from commit 0d54cfb1a696bfe9795bdee3653c130747b97fcc)

Change-Id: Ib7a12c1752872df3a881dc10da9772827ed22b77
Merged-In: I58da2d96ec355e26f872b67b021c3b3dba26e2b4
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index dd07545..3087ccc 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -937,7 +937,7 @@
   }
 }
 
-void Jit::PostForkChildAction(bool is_zygote) {
+void Jit::PostForkChildAction(bool is_system_server, bool is_zygote) {
   if (is_zygote) {
     // Remove potential tasks that have been inherited from the zygote. Child zygotes
     // currently don't need the whole boot image compiled (ie webview_zygote).
@@ -959,8 +959,12 @@
       !Runtime::Current()->GetInstrumentation()->AreExitStubsInstalled());
 
   if (thread_pool_ != nullptr) {
-    // Remove potential tasks that have been inherited from the zygote.
-    thread_pool_->RemoveAllTasks(Thread::Current());
+    if (!is_system_server) {
+      // Remove potential tasks that have been inherited from the zygote.
+      // We keep the queue for system server, as not having those methods compiled
+      // impacts app startup.
+      thread_pool_->RemoveAllTasks(Thread::Current());
+    }
 
     // Resume JIT compilation.
     thread_pool_->CreateThreads();
diff --git a/runtime/jit/jit.h b/runtime/jit/jit.h
index f48ad46..15cdacb 100644
--- a/runtime/jit/jit.h
+++ b/runtime/jit/jit.h
@@ -296,7 +296,7 @@
   void Start();
 
   // Transition to a child state.
-  void PostForkChildAction(bool is_zygote);
+  void PostForkChildAction(bool is_system_server, bool is_zygote);
 
   // Prepare for forking.
   void PreZygoteFork();
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index ab30a10..77ec795 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -324,7 +324,7 @@
           /* is_system_server= */ false, is_zygote);
     }
     // This must be called after EnableDebugFeatures.
-    runtime->GetJit()->PostForkChildAction(is_zygote);
+    runtime->GetJit()->PostForkChildAction(is_system_server, is_zygote);
   }
 
   // Update tracing.
diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc
index 0031e14..a0b2f1e 100644
--- a/test/common/runtime_state.cc
+++ b/test/common/runtime_state.cc
@@ -373,7 +373,7 @@
   // Mimic the transition behavior a zygote fork would have.
   jit->PreZygoteFork();
   jit->GetCodeCache()->PostForkChildAction(/*is_system_server=*/ false, /*is_zygote=*/ false);
-  jit->PostForkChildAction(/*is_zygote=*/ false);
+  jit->PostForkChildAction(/*is_system_server=*/ false, /*is_zygote=*/ false);
 }
 
 extern "C" JNIEXPORT void JNICALL Java_Main_deoptimizeBootImage(JNIEnv*, jclass) {