Add JIT zygote hook

Bug: 19735273
Change-Id: I1983852e80010c344b45e0bb459de47c56adfce8
diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc
index c056adc..8395150 100644
--- a/runtime/native/dalvik_system_ZygoteHooks.cc
+++ b/runtime/native/dalvik_system_ZygoteHooks.cc
@@ -59,10 +59,11 @@
     DEBUG_ENABLE_ASSERT             = 1 << 2,
     DEBUG_ENABLE_SAFEMODE           = 1 << 3,
     DEBUG_ENABLE_JNI_LOGGING        = 1 << 4,
+    DEBUG_ENABLE_JIT                = 1 << 5,
   };
 
+  Runtime* const runtime = Runtime::Current();
   if ((debug_flags & DEBUG_ENABLE_CHECKJNI) != 0) {
-    Runtime* runtime = Runtime::Current();
     JavaVMExt* vm = runtime->GetJavaVM();
     if (!vm->IsCheckJniEnabled()) {
       LOG(INFO) << "Late-enabling -Xcheck:jni";
@@ -86,13 +87,26 @@
   }
   debug_flags &= ~DEBUG_ENABLE_DEBUGGER;
 
-  if ((debug_flags & DEBUG_ENABLE_SAFEMODE) != 0) {
+  const bool safe_mode = (debug_flags & DEBUG_ENABLE_SAFEMODE) != 0;
+  if (safe_mode) {
     // Ensure that any (secondary) oat files will be interpreted.
-    Runtime* runtime = Runtime::Current();
     runtime->AddCompilerOption("--compiler-filter=interpret-only");
     debug_flags &= ~DEBUG_ENABLE_SAFEMODE;
   }
 
+  if ((debug_flags & DEBUG_ENABLE_JIT) != 0) {
+    if (safe_mode) {
+      LOG(INFO) << "Not enabling JIT due to VM safe mode";
+    } else {
+      if (runtime->GetJit() == nullptr) {
+        runtime->CreateJit();
+      } else {
+        LOG(INFO) << "Not late-enabling JIT (already on)";
+      }
+    }
+    debug_flags &= ~DEBUG_ENABLE_JIT;
+  }
+
   // This is for backwards compatibility with Dalvik.
   debug_flags &= ~DEBUG_ENABLE_ASSERT;