Revert "Don't use AOT code for native methods for java debuggable runtime"

This reverts commit 7d30cee9872527ecedb07dc32099e24cf4a657ce.

Reason for revert: https://android-build.googleplex.com/builds/submitted/8501823/art-tracing/latest/view/logs/build_error.log

Change-Id: Ibdd3abcd468573193d293db20c84941d3517948d
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index 40b7a7b..867f75c 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -617,15 +617,6 @@
   }
 
   OatQuickMethodHeader* method_header = OatQuickMethodHeader::FromEntryPoint(oat_entry_point);
-  // We could have existing Oat code for native methods but we may not use it if the runtime is java
-  // debuggable or when profiling boot class path. There is no easy way to check if the pc
-  // corresponds to QuickGenericJniStub. Since we have eliminated all the other cases, if the pc
-  // doesn't correspond to the AOT code then we must be running QuickGenericJniStub.
-  if (IsNative() && !method_header->Contains(pc)) {
-    DCHECK_NE(pc, 0u) << "PC 0 for " << PrettyMethod();
-    return nullptr;
-  }
-
   DCHECK(method_header->Contains(pc))
       << PrettyMethod()
       << " " << std::hex << pc << " " << oat_entry_point
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index afa7c39..1e328a3 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -300,11 +300,16 @@
          Runtime::Current()->GetRuntimeCallbacks()->IsMethodBeingInspected(method);
 }
 
-static bool CanUseAotCode(const void* quick_code)
+static bool CanUseAotCode(ArtMethod* method, const void* quick_code)
     REQUIRES_SHARED(Locks::mutator_lock_) {
   if (quick_code == nullptr) {
     return false;
   }
+  if (method->IsNative()) {
+    // AOT code for native methods can always be used.
+    return true;
+  }
+
   Runtime* runtime = Runtime::Current();
   // For simplicity, we never use AOT code for debuggable.
   if (runtime->IsJavaDebuggable()) {
@@ -340,7 +345,7 @@
   // In debuggable mode, we can only use AOT code for native methods.
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
   const void* aot_code = method->GetOatMethodQuickCode(class_linker->GetImagePointerSize());
-  if (CanUseAotCode(aot_code)) {
+  if (CanUseAotCode(method, aot_code)) {
     return aot_code;
   }
 
@@ -399,7 +404,7 @@
   }
 
   // Use the provided AOT code if possible.
-  if (CanUseAotCode(aot_code)) {
+  if (CanUseAotCode(method, aot_code)) {
     UpdateEntryPoints(method, aot_code);
     return;
   }
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 45ca8fe..e20f883 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -3145,12 +3145,14 @@
     for (auto& m : klass->GetMethods(pointer_size)) {
       const void* code = m.GetEntryPointFromQuickCompiledCode();
       if (Runtime::Current()->GetHeap()->IsInBootImageOatFile(code) &&
+          !m.IsNative() &&
           !m.IsProxyMethod()) {
         instrumentation_->InitializeMethodsCode(&m, /*aot_code=*/ nullptr);
       }
 
       if (Runtime::Current()->GetJit() != nullptr &&
-          Runtime::Current()->GetJit()->GetCodeCache()->IsInZygoteExecSpace(code)) {
+          Runtime::Current()->GetJit()->GetCodeCache()->IsInZygoteExecSpace(code) &&
+          !m.IsNative()) {
         DCHECK(!m.IsProxyMethod());
         instrumentation_->InitializeMethodsCode(&m, /*aot_code=*/ nullptr);
       }