Force set resolved method for static invokes
For static invokes, we may dispatch to the static method in the
superclass but resolve using the subclass. To prevent getting slow
paths on each invoke, we force set the resolved method for the
super class dex method index if we are in the same dex file.
Added test.
Bug: 19175856
(cherry picked from commit e4a91bbeaa118bc01a5c338c6a6d9ee094a6a2c6)
Change-Id: I26f8644a7f725f5c2dc2a94a8e9578f573792507
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 403313a..0651899 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -827,6 +827,15 @@
caller->SetDexCacheResolvedMethod(method_index, called);
}
}
+ } else if (invoke_type == kStatic) {
+ const auto called_dex_method_idx = called->GetDexMethodIndex();
+ // For static invokes, we may dispatch to the static method in the superclass but resolve
+ // using the subclass. To prevent getting slow paths on each invoke, we force set the
+ // resolved method for the super class dex method index if we are in the same dex file.
+ // b/19175856
+ if (called->GetDexFile() == dex_file && dex_method_idx != called_dex_method_idx) {
+ called->GetDexCache()->SetResolvedMethod(called_dex_method_idx, called);
+ }
}
// Ensure that the called method's class is initialized.
StackHandleScope<1> hs(soa.Self());