Fix exception delivery for exceptions caught by a static method called on behalf of <clinit>.

We'd already fixed ToDexPC, but needed to fix ToNativePC in the same way.

Change-Id: If8594beec710a39529b15499faeeedd41c9a42f2
diff --git a/src/object.cc b/src/object.cc
index c9e0929..85a2d0a 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -473,6 +473,21 @@
   return result;
 }
 
+static const void* GetOatCode(const Method* m) {
+  Runtime* runtime = Runtime::Current();
+  const void* code = m->GetCode();
+  // Peel off any method tracing trampoline.
+  if (runtime->IsMethodTracingActive() && runtime->GetTracer()->GetSavedCodeFromMap(m) != NULL) {
+    code = runtime->GetTracer()->GetSavedCodeFromMap(m);
+  }
+  // Peel off any resolution stub.
+  if (code == runtime->GetResolutionStubArray(Runtime::kStaticMethod)->GetData() ||
+      code == runtime->GetResolutionStubArray(Runtime::kInstanceMethod)->GetData()) {
+    code = runtime->GetClassLinker()->GetOatCodeFor(m);
+  }
+  return code;
+}
+
 uint32_t Method::ToDexPC(const uintptr_t pc) const {
   const uint32_t* mapping_table = GetMappingTable();
   if (mapping_table == NULL) {
@@ -480,19 +495,7 @@
     return DexFile::kDexNoIndex;   // Special no mapping case
   }
   size_t mapping_table_length = GetMappingTableLength();
-  const void* code_offset;
-  Runtime* runtime = Runtime::Current();
-  if (runtime->IsMethodTracingActive() &&
-      runtime->GetTracer()->GetSavedCodeFromMap(this) != NULL) {
-    code_offset = runtime->GetTracer()->GetSavedCodeFromMap(this);
-  } else {
-    code_offset = GetCode();
-  }
-  if (code_offset == runtime->GetResolutionStubArray(Runtime::kStaticMethod)->GetData() ||
-      code_offset == runtime->GetResolutionStubArray(Runtime::kInstanceMethod)->GetData()) {
-    code_offset = runtime->GetClassLinker()->GetOatCodeFor(this);
-  }
-  uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(code_offset);
+  uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(GetOatCode(this));
   uint32_t best_offset = 0;
   uint32_t best_dex_offset = 0;
   for (size_t i = 0; i < mapping_table_length; i += 2) {
@@ -522,12 +525,7 @@
     uint32_t map_offset = mapping_table[i];
     uint32_t map_dex_offset = mapping_table[i + 1];
     if (map_dex_offset == dex_pc) {
-      if (Runtime::Current()->IsMethodTracingActive()) {
-        Trace* tracer = Runtime::Current()->GetTracer();
-        return reinterpret_cast<uintptr_t>(tracer->GetSavedCodeFromMap(this)) + map_offset;
-      } else {
-        return reinterpret_cast<uintptr_t>(GetCode()) + map_offset;
-      }
+      return reinterpret_cast<uintptr_t>(GetOatCode(this)) + map_offset;
     }
   }
   LOG(FATAL) << "Looking up Dex PC not contained in method";