Revert^4 "JIT JNI stubs."

The original CL,
    https://android-review.googlesource.com/513417 ,
has a bug fixed in the Revert^2,
    https://android-review.googlesource.com/550579 ,
and this Revert^4 adds two more fixes:
    - fix obsolete native method getting interpreter
      entrypoint in 980-redefine-object,
    - fix random JIT GC flakiness in 667-jit-jni-stub.

Test: testrunner.py --host --prebuild --no-relocate \
      --no-image --jit -t 980-redefine-object
Bug: 65574695
Bug: 69843562

This reverts commit 056d7756152bb3ced81dd57781be5028428ce2bd.

Change-Id: Ic778686168b90e29816fd526e23141dcbe5ea880
diff --git a/runtime/art_method.cc b/runtime/art_method.cc
index fa0c501..43a5139 100644
--- a/runtime/art_method.cc
+++ b/runtime/art_method.cc
@@ -587,11 +587,6 @@
   CHECK(existing_entry_point != nullptr) << PrettyMethod() << "@" << this;
   ClassLinker* class_linker = runtime->GetClassLinker();
 
-  if (class_linker->IsQuickGenericJniStub(existing_entry_point)) {
-    // The generic JNI does not have any method header.
-    return nullptr;
-  }
-
   if (existing_entry_point == GetQuickProxyInvokeHandler()) {
     DCHECK(IsProxyMethod() && !IsConstructor());
     // The proxy entry point does not have any method header.
@@ -599,7 +594,8 @@
   }
 
   // Check whether the current entry point contains this pc.
-  if (!class_linker->IsQuickResolutionStub(existing_entry_point) &&
+  if (!class_linker->IsQuickGenericJniStub(existing_entry_point) &&
+      !class_linker->IsQuickResolutionStub(existing_entry_point) &&
       !class_linker->IsQuickToInterpreterBridge(existing_entry_point)) {
     OatQuickMethodHeader* method_header =
         OatQuickMethodHeader::FromEntryPoint(existing_entry_point);
@@ -632,19 +628,13 @@
   OatFile::OatMethod oat_method =
       FindOatMethodFor(this, class_linker->GetImagePointerSize(), &found);
   if (!found) {
-    if (class_linker->IsQuickResolutionStub(existing_entry_point)) {
-      // We are running the generic jni stub, but the entry point of the method has not
-      // been updated yet.
-      DCHECK_EQ(pc, 0u) << "Should be a downcall";
-      DCHECK(IsNative());
-      return nullptr;
-    }
-    if (existing_entry_point == GetQuickInstrumentationEntryPoint()) {
-      // We are running the generic jni stub, but the method is being instrumented.
-      // NB We would normally expect the pc to be zero but we can have non-zero pc's if
-      // instrumentation is installed or removed during the call which is using the generic jni
-      // trampoline.
-      DCHECK(IsNative());
+    if (IsNative()) {
+      // We are running the GenericJNI stub. The entrypoint may point
+      // to different entrypoints or to a JIT-compiled JNI stub.
+      DCHECK(class_linker->IsQuickGenericJniStub(existing_entry_point) ||
+             class_linker->IsQuickResolutionStub(existing_entry_point) ||
+             existing_entry_point == GetQuickInstrumentationEntryPoint() ||
+             (jit != nullptr && jit->GetCodeCache()->ContainsPc(existing_entry_point)));
       return nullptr;
     }
     // Only for unit tests.
@@ -702,13 +692,15 @@
   declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass());
 
   // If the entry point of the method we are copying from is from JIT code, we just
-  // put the entry point of the new method to interpreter. We could set the entry point
-  // to the JIT code, but this would require taking the JIT code cache lock to notify
-  // it, which we do not want at this level.
+  // put the entry point of the new method to interpreter or GenericJNI. We could set
+  // the entry point to the JIT code, but this would require taking the JIT code cache
+  // lock to notify it, which we do not want at this level.
   Runtime* runtime = Runtime::Current();
   if (runtime->UseJitCompilation()) {
     if (runtime->GetJit()->GetCodeCache()->ContainsPc(GetEntryPointFromQuickCompiledCode())) {
-      SetEntryPointFromQuickCompiledCodePtrSize(GetQuickToInterpreterBridge(), image_pointer_size);
+      SetEntryPointFromQuickCompiledCodePtrSize(
+          src->IsNative() ? GetQuickGenericJniStub() : GetQuickToInterpreterBridge(),
+          image_pointer_size);
     }
   }
   // Clear the profiling info for the same reasons as the JIT code.