Reland "Use InitializeMethodsCode when we need to reinitialize a method entrypoint."

This reverts commit b0f63c93e44bf53a34dda90c74b8725a932922da.

Reason for revert: Fix For proxy init.
Test: test.py

Change-Id: I6b4796115d73a093f86309cec1f03cafd981c2e9
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 5ae6513..5eab75d 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -201,22 +201,6 @@
   self->AssertPendingException();
 }
 
-static void ChangeInterpreterBridgeToNterp(ArtMethod* method, ClassLinker* class_linker)
-    REQUIRES_SHARED(Locks::mutator_lock_) {
-  Runtime* runtime = Runtime::Current();
-  if (class_linker->IsQuickToInterpreterBridge(method->GetEntryPointFromQuickCompiledCode()) &&
-      CanMethodUseNterp(method)) {
-    if (method->GetDeclaringClass()->IsVisiblyInitialized() ||
-        !NeedsClinitCheckBeforeCall(method)) {
-      runtime->GetInstrumentation()->UpdateMethodsCode(method, interpreter::GetNterpEntryPoint());
-    } else {
-      // Put the resolution stub, which will initialize the class and then
-      // call the method with nterp.
-      runtime->GetInstrumentation()->UpdateMethodsCode(method, GetQuickResolutionStub());
-    }
-  }
-}
-
 static void UpdateClassAfterVerification(Handle<mirror::Class> klass,
                                          PointerSize pointer_size,
                                          verifier::FailureKind failure_kind)
@@ -231,7 +215,9 @@
   // to methods that currently use the switch interpreter.
   if (interpreter::CanRuntimeUseNterp()) {
     for (ArtMethod& m : klass->GetMethods(pointer_size)) {
-      ChangeInterpreterBridgeToNterp(&m, class_linker);
+      if (class_linker->IsQuickToInterpreterBridge(m.GetEntryPointFromQuickCompiledCode())) {
+        runtime->GetInstrumentation()->InitializeMethodsCode(&m, /*aot_code=*/nullptr);
+      }
     }
   }
 }
@@ -2008,10 +1994,11 @@
         // reset it with the runtime value.
         method.ResetCounter(hotness_threshold);
       }
-      // Set image methods' entry point that point to the interpreter bridge to the
-      // nterp entry point.
       if (method.GetEntryPointFromQuickCompiledCode() == nterp_trampoline_) {
         if (can_use_nterp) {
+          // Set image methods' entry point that point to the nterp trampoline to the
+          // nterp entry point. This allows taking the fast path when doing a
+          // nterp->nterp call.
           DCHECK(!NeedsClinitCheckBeforeCall(&method) ||
                  method.GetDeclaringClass()->IsVisiblyInitialized());
           method.SetEntryPointFromQuickCompiledCode(interpreter::GetNterpEntryPoint());
@@ -3388,6 +3375,7 @@
     return;
   }
 
+  instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation();
   // Link the code of methods skipped by LinkCode.
   for (size_t method_index = 0; method_index < num_direct_methods; ++method_index) {
     ArtMethod* method = klass->GetDirectMethod(method_index, pointer_size);
@@ -3395,7 +3383,6 @@
       // Only update static methods.
       continue;
     }
-    instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation();
     instrumentation->UpdateMethodsCode(method, instrumentation->GetCodeForInvoke(method));
   }
   // Ignore virtual methods on the iterator.
@@ -9779,14 +9766,6 @@
   return GetQuickGenericJniStub();
 }
 
-void ClassLinker::SetEntryPointsToInterpreter(ArtMethod* method) const {
-  if (!method->IsNative()) {
-    method->SetEntryPointFromQuickCompiledCode(GetQuickToInterpreterBridge());
-  } else {
-    method->SetEntryPointFromQuickCompiledCode(GetQuickGenericJniStub());
-  }
-}
-
 void ClassLinker::SetEntryPointsForObsoleteMethod(ArtMethod* method) const {
   DCHECK(method->IsObsolete());
   // We cannot mess with the entrypoints of native methods because they are used to determine how