Make adbconnection try to start the JIT if it is not running.

The new adbconnection jdwp-provider forces processes to throw out
compiled code when a debugger attaches. This is normally not a problem
since the JIT will pick up the slack in short order. If one is
debugging system_server (or a few other similar system services)
performance will be permanently degraded since these processes run
with the JIT disabled.

In order to improve the experience of debugging these processes we
make adbconnection attempt to start the JIT if it is not currently
running. In order for this to work the user will need to run
'adb shell setenforce 0' to disable selinux prior to attaching the
debugger.

Bug: 78119634

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>

Change-Id: Iffb382460a1dbcd055d533a44367c4ccb3830f10
diff --git a/adbconnection/adbconnection.cc b/adbconnection/adbconnection.cc
index 06ded26..ee89717 100644
--- a/adbconnection/adbconnection.cc
+++ b/adbconnection/adbconnection.cc
@@ -824,11 +824,21 @@
 }
 
 void AdbConnectionState::AttachJdwpAgent(art::Thread* self) {
+  art::Runtime* runtime = art::Runtime::Current();
+  if (runtime->GetJit() == nullptr && !runtime->GetInstrumentation()->IsForcedInterpretOnly()) {
+    // If we don't have a JIT we should try to start the jit for performance reasons.
+    runtime->CreateJit();
+    if (runtime->GetJit() == nullptr) {
+      LOG(WARNING) << "Could not start jit for debugging. This process might be quite slow as it "
+                   << "is running entirely in the interpreter. Try running 'setenforce 0' and "
+                   << "starting the debugging session over.";
+    }
+  }
   self->AssertNoPendingException();
-  art::Runtime::Current()->AttachAgent(/* JNIEnv */ nullptr,
-                                       MakeAgentArg(),
-                                       /* classloader */ nullptr,
-                                       /*allow_non_debuggable_tooling*/ true);
+  runtime->AttachAgent(/* JNIEnv */ nullptr,
+                       MakeAgentArg(),
+                       /* classloader */ nullptr,
+                       /*allow_non_debuggable_tooling*/ true);
   if (self->IsExceptionPending()) {
     LOG(ERROR) << "Failed to load agent " << agent_name_;
     art::ScopedObjectAccess soa(self);