Refactor code around JIT creation.

- Create the JIT early on.
- Have dedicated zygote spaces, that get assign after the fork.
- Re-parse compiler options after fork to take into account customization
  of debug flags by the child.

Currently, we only create the thread pool in the child, so the zygote
isn't jitting yet.

Bug: 119800099
Test: test.py, device boots
Change-Id: I591ce933ebf54a67937ab1d05206534f55ef2f65
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 19c1623..292a424 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -791,6 +791,8 @@
     if (!jit::Jit::LoadCompilerLibrary(&error_msg)) {
       LOG(WARNING) << "Failed to load JIT compiler with error " << error_msg;
     }
+    CreateJitCodeCache(/*rwx_memory_allowed=*/true);
+    CreateJit();
   }
 
   // Send the start phase event. We have to wait till here as this is when the main thread peer
@@ -894,15 +896,8 @@
     }
   }
 
-  if (jit_ == nullptr) {
-    // The system server's code cache was initialized specially. For other zygote forks or
-    // processes create it now.
-    if (!is_system_server) {
-      CreateJitCodeCache(/*rwx_memory_allowed=*/true);
-    }
-    // Note that when running ART standalone (not zygote, nor zygote fork),
-    // the jit may have already been created.
-    CreateJit();
+  if (jit_ != nullptr) {
+    jit_->CreateThreadPool();
   }
 
   // Create the thread pools.
@@ -2493,16 +2488,11 @@
     return;
   }
 
-  // SystemServer has execmem blocked by SELinux so can not use RWX page permissions after the
-  // cache initialized.
-  jit_options_->SetRWXMemoryAllowed(rwx_memory_allowed);
-
   std::string error_msg;
   bool profiling_only = !jit_options_->UseJitCompilation();
-  jit_code_cache_.reset(jit::JitCodeCache::Create(jit_options_->GetCodeCacheInitialCapacity(),
-                                                  jit_options_->GetCodeCacheMaxCapacity(),
-                                                  profiling_only,
-                                                  jit_options_->RWXMemoryAllowed(),
+  jit_code_cache_.reset(jit::JitCodeCache::Create(profiling_only,
+                                                  rwx_memory_allowed,
+                                                  IsZygote(),
                                                   &error_msg));
   if (jit_code_cache_.get() == nullptr) {
     LOG(WARNING) << "Failed to create JIT Code Cache: " << error_msg;