Fix relation between debuggable / JIT zygote.

- Move the logic to clear precompiled in ClassLinker.
- Add a null check on entries in ZygoteMap
- Avoid doing JIT zygote actions (precompile, remapping boot images)
when debuggable.

Test: android.jdwptunnel.cts.JdwpTunnelTest#testAttachDebuggerToProfileableApp
Change-Id: I9b5e391bb35aa04bbeba01b9b563b33f96395d2e
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 3b8c2a7..0c3b18b 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -879,37 +879,28 @@
 }
 
 void JitCodeCache::TransitionToDebuggable() {
-  // We want to discard JIT compiled methods that are non-debuggable. These are:
-  // - Methods compiled by the zygote (where the compiled code is in the zygote exec
-  //   space)
-  // - Methods that are precompiled in the method_code_map_.
-  //
-  // Also, we want to clear the precompiled flag to clear the effects of
-  // GetSavedEntryPointOfPreCompiledMethod.
+  // Check that none of our methods have an entrypoint in the zygote exec
+  // space (this should be taken care of by
+  // ClassLinker::UpdateEntryPointsClassVisitor.
   {
     MutexLock mu(Thread::Current(), *Locks::jit_lock_);
-    for (const auto& it : method_code_map_) {
-      ArtMethod* method = it.second;
-      if (IsInZygoteExecSpace(method->GetEntryPointFromQuickCompiledCode()) ||
-          method->IsPreCompiled()) {
-        method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
-      }
-      if (method->IsPreCompiled()) {
-        method->ClearPreCompiled();
+    if (kIsDebugBuild) {
+      for (const auto& it : method_code_map_) {
+        ArtMethod* method = it.second;
+        DCHECK(!method->IsPreCompiled());
+        DCHECK(!IsInZygoteExecSpace(method->GetEntryPointFromQuickCompiledCode()));
       }
     }
     // Not strictly necessary, but this map is useless now.
     saved_compiled_methods_map_.clear();
   }
-  for (const auto& entry : zygote_map_) {
-    ArtMethod* method = entry.method;
-    if (IsInZygoteExecSpace(method->GetEntryPointFromQuickCompiledCode())) {
-      method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
-    }
-    // We check if it's precompiled instead of DCHECKing it to support
-    // TransitionToDebuggable being called multiple times.
-    if (method->IsPreCompiled()) {
-      method->ClearPreCompiled();
+  if (kIsDebugBuild) {
+    for (const auto& entry : zygote_map_) {
+      ArtMethod* method = entry.method;
+      if (method != nullptr) {
+        DCHECK(!method->IsPreCompiled());
+        DCHECK(!IsInZygoteExecSpace(method->GetEntryPointFromQuickCompiledCode()));
+      }
     }
   }
 }