Move jit startup attempt to openjdkjvmti from adbconnection

We were attempting to start the jit in adbconnection if it was not
already running in order to improve the performance of debugging
system_server and other similar processes. Since we have opened up the
kArtTiVersion (0x70010200) environment to any agent (on userdebug/eng
builds) it would be useful for these other agents also have the
performance boost when running on these processes.

Test: Build
Test: adb root &&
      adb shell setenforce 0 &&
      adb forward tcp:12345 jdwp:`adb shell pidof system_server` &&
      jdb -attach localhost:12345;
      <Do things with debugger and device>

Bug: 78119634
Bug: 78195998
Change-Id: Ibfe10b43dcd23d615c03c12af2625e2b0c54f6a4
diff --git a/openjdkjvmti/deopt_manager.cc b/openjdkjvmti/deopt_manager.cc
index a6f1207..d4e5df1 100644
--- a/openjdkjvmti/deopt_manager.cc
+++ b/openjdkjvmti/deopt_manager.cc
@@ -40,6 +40,7 @@
 #include "dex/dex_file_annotations.h"
 #include "dex/modifiers.h"
 #include "events-inl.h"
+#include "jit/jit.h"
 #include "jni_internal.h"
 #include "mirror/class-inl.h"
 #include "mirror/object_array-inl.h"
@@ -127,6 +128,22 @@
                    << "loaded too late to change runtime state to DEBUGGABLE. Only kArtTiVersion "
                    << "(0x" << std::hex << kArtTiVersion << ") environments are available. Some "
                    << "functionality might not work properly.";
+      if (runtime->GetJit() == nullptr &&
+          runtime->GetJITOptions()->UseJitCompilation() &&
+          !runtime->GetInstrumentation()->IsForcedInterpretOnly()) {
+        // If we don't have a jit we should try to start the jit for performance reasons. We only
+        // need to do this for late attach on non-debuggable processes because for debuggable
+        // processes we already rely on jit and we cannot force this jit to start if we are still in
+        // OnLoad since the runtime hasn't started up sufficiently. This is only expected to happen
+        // on userdebug/eng builds.
+        LOG(INFO) << "Attempting to start jit for openjdkjvmti plugin.";
+        runtime->CreateJit();
+        if (runtime->GetJit() == nullptr) {
+          LOG(WARNING) << "Could not start jit for openjdkjvmti plugin. This process might be "
+                       << "quite slow as it is running entirely in the interpreter. Try running "
+                       << "'setenforce 0' and restarting this process.";
+        }
+      }
     }
     runtime->DeoptimizeBootImage();
   }