Jit-zygote compiled code isn't debuggable

We check the debuggablity of compiled code by checking to see if it
was compiled by the JIT. This works since we throw all precompiled
code out when transitioning to debuggable. Unfortunately with
jit-zygote the non-debuggable zygote methods can be incorrectly seen
as debuggable when encountered on the stack. This can lead to
incorrect deoptimization and other issues. To fix this we explicitly
exclude jit-zygote code from the check.

Bug: 144947842
Test: ./test.py --host
Change-Id: I4e953f64f8261b7a16d7c3199cec89998af0c1cf
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 2415a9f..c43fe11 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -273,8 +273,12 @@
 
 JitCodeCache::~JitCodeCache() {}
 
+bool JitCodeCache::PrivateRegionContainsPc(const void* ptr) const {
+  return private_region_.IsInExecSpace(ptr);
+}
+
 bool JitCodeCache::ContainsPc(const void* ptr) const {
-  return private_region_.IsInExecSpace(ptr) || shared_region_.IsInExecSpace(ptr);
+  return PrivateRegionContainsPc(ptr) || shared_region_.IsInExecSpace(ptr);
 }
 
 bool JitCodeCache::WillExecuteJitCode(ArtMethod* method) {
diff --git a/runtime/jit/jit_code_cache.h b/runtime/jit/jit_code_cache.h
index 22b43cc..d8216d2 100644
--- a/runtime/jit/jit_code_cache.h
+++ b/runtime/jit/jit_code_cache.h
@@ -225,6 +225,9 @@
   // Return true if the code cache contains this pc.
   bool ContainsPc(const void* pc) const;
 
+  // Return true if the code cache contains this pc in the private region (i.e. not from zygote).
+  bool PrivateRegionContainsPc(const void* pc) const;
+
   // Returns true if either the method's entrypoint is JIT compiled code or it is the
   // instrumentation entrypoint and we can jump to jit code for this method. For testing use only.
   bool WillExecuteJitCode(ArtMethod* method) REQUIRES(!Locks::jit_lock_);
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 8607991..b739450 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -2735,9 +2735,10 @@
   // We could look at the oat file where `code` is being defined,
   // and check whether it's been compiled debuggable, but we decided to
   // only rely on the JIT for debuggable apps.
-  return IsJavaDebuggable() &&
-      GetJit() != nullptr &&
-      GetJit()->GetCodeCache()->ContainsPc(reinterpret_cast<const void*>(code));
+  // The JIT-zygote is not debuggable so we need to be sure to exclude code from the non-private
+  // region as well.
+  return IsJavaDebuggable() && GetJit() != nullptr &&
+         GetJit()->GetCodeCache()->PrivateRegionContainsPc(reinterpret_cast<const void*>(code));
 }
 
 LinearAlloc* Runtime::CreateLinearAlloc() {