Pass the right dex_file/method_index for String.<init>.

Passing the dex file of the caller in instruction_builder.cc
was problematic as this information get lost at the point of RTP.

test: test.py
Change-Id: I3f620b931544a538386d23c2456b182b3ed41091
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index 64a1ecc..a38e271 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -960,14 +960,18 @@
         HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
         dchecked_integral_cast<uint64_t>(string_init_entry_point)
     };
-    MethodReference target_method(dex_file_, method_idx);
+    ScopedObjectAccess soa(Thread::Current());
+    MethodReference target_method(resolved_method->GetDexFile(),
+                                  resolved_method->GetDexMethodIndex());
+    // We pass null for the resolved_method to ensure optimizations
+    // don't rely on it.
     HInvoke* invoke = new (allocator_) HInvokeStaticOrDirect(
         allocator_,
         number_of_arguments - 1,
         DataType::Type::kReference /*return_type */,
         dex_pc,
         method_idx,
-        nullptr,
+        nullptr /* resolved_method */,
         dispatch_info,
         invoke_type,
         target_method,
diff --git a/compiler/optimizing/reference_type_propagation.cc b/compiler/optimizing/reference_type_propagation.cc
index 8bb124e..67a61fc 100644
--- a/compiler/optimizing/reference_type_propagation.cc
+++ b/compiler/optimizing/reference_type_propagation.cc
@@ -537,14 +537,13 @@
       Thread* self = Thread::Current();
       StackHandleScope<2> hs(self);
       const DexFile& dex_file = *invoke->GetTargetMethod().dex_file;
+      uint32_t dex_method_index = invoke->GetTargetMethod().index;
       Handle<mirror::DexCache> dex_cache(
           hs.NewHandle(FindDexCacheWithHint(self, dex_file, hint_dex_cache_)));
-      // Use a null loader. We should probably use the compiling method's class loader,
-      // but then we would need to pass it to RTPVisitor just for this debug check. Since
-      // the method is from the String class, the null loader is good enough.
+      // Use a null loader, the target method is in a boot classpath dex file.
       Handle<mirror::ClassLoader> loader(hs.NewHandle<mirror::ClassLoader>(nullptr));
       ArtMethod* method = cl->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>(
-          invoke->GetDexMethodIndex(), dex_cache, loader, /* referrer */ nullptr, kDirect);
+          dex_method_index, dex_cache, loader, /* referrer */ nullptr, kDirect);
       DCHECK(method != nullptr);
       mirror::Class* declaring_class = method->GetDeclaringClass();
       DCHECK(declaring_class != nullptr);