Merge "Make adbconnection try to start the JIT if it is not running." into pi-dev
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);