image: Allow methods with code in another oat file to work correctly

This fixes an issue when classes with default methods are in the boot
image and are used by an app image.

Bug: 27315287
Change-Id: Iaa66848fc07a0c779bc6e047bd154e2a4b87e1c8
diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc
index d50528e..a4feff6 100644
--- a/compiler/image_writer.cc
+++ b/compiler/image_writer.cc
@@ -2044,9 +2044,19 @@
   // trampoline.
 
   // Quick entrypoint:
-  uint32_t quick_oat_code_offset = PointerToLowMemUInt32(
-      method->GetEntryPointFromQuickCompiledCodePtrSize(target_ptr_size_));
-  const uint8_t* quick_code = GetOatAddressForOffset(quick_oat_code_offset, image_info);
+  const void* quick_oat_entry_point =
+      method->GetEntryPointFromQuickCompiledCodePtrSize(target_ptr_size_);
+  const uint8_t* quick_code;
+
+  if (UNLIKELY(IsInBootImage(method->GetDeclaringClass()))) {
+    DCHECK(method->MightBeCopied());
+    // If the code is not in the oat file corresponding to this image (e.g. default methods)
+    quick_code = reinterpret_cast<const uint8_t*>(quick_oat_entry_point);
+  } else {
+    uint32_t quick_oat_code_offset = PointerToLowMemUInt32(quick_oat_entry_point);
+    quick_code = GetOatAddressForOffset(quick_oat_code_offset, image_info);
+  }
+
   *quick_is_interpreted = false;
   if (quick_code != nullptr && (!method->IsStatic() || method->IsConstructor() ||
       method->GetDeclaringClass()->IsInitialized())) {