Avoid SetResolvedDirectMethod on failure to ResolveMethod

Change-Id: I03b579a43ba4004b6441d5123f1ce402feb77624
diff --git a/src/runtime_support.cc b/src/runtime_support.cc
index 9653d28..7ae5da5 100644
--- a/src/runtime_support.cc
+++ b/src/runtime_support.cc
@@ -401,25 +401,26 @@
   }
   // Resolve method filling in dex cache
   Method* called = linker->ResolveMethod(method_idx, *caller_sp, true);
-  // Update CodeAndDirectMethod table
-  Method* caller = *caller_sp;
-  DexCache* dex_cache = caller->GetDeclaringClass()->GetDexCache();
-  dex_cache->GetCodeAndDirectMethods()->SetResolvedDirectMethod(method_idx, called);
   if (LIKELY(!thread->IsExceptionPending())) {
+    // Update CodeAndDirectMethod table
+    Method* caller = *caller_sp;
+    DexCache* dex_cache = caller->GetDeclaringClass()->GetDexCache();
+    dex_cache->GetCodeAndDirectMethods()->SetResolvedDirectMethod(method_idx, called);
     // We got this far, ensure that the declaring class is initialized
     linker->EnsureInitialized(called->GetDeclaringClass(), true);
   }
   void* code;
   if (UNLIKELY(thread->IsExceptionPending())) {
-    // Something went wrong, go into deliver exception with the pending exception in r0
+    // Something went wrong in ResolveMethod or EnsureInitialized,
+    // go into deliver exception with the pending exception in r0
     code = reinterpret_cast<void*>(art_deliver_exception_from_code);
-    regs[0] =  reinterpret_cast<uintptr_t>(thread->GetException());
+    regs[0] = reinterpret_cast<uintptr_t>(thread->GetException());
     thread->ClearException();
   } else {
     // Expect class to at least be initializing
     CHECK(called->GetDeclaringClass()->IsInitializing());
     // Set up entry into main method
-    regs[0] =  reinterpret_cast<uintptr_t>(called);
+    regs[0] = reinterpret_cast<uintptr_t>(called);
     code = const_cast<void*>(called->GetCode());
   }
   return code;