Reland "Improve invokeinterface for nterp."
This reverts commit f1d06474baa2f7c00761db39099b89ddab71bbe4.
Bug: 177554973
Bug: 112676029
Test: test.py
Test: 815-invokeinterface-default
Test: enable text-to-speech on device, no crash
Reason for revert: Fixed issue with recursive default methods
Change-Id: I2fb9336adb6c4fc920f39aa19bfe7f0a92ce059a
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index 3ffb24b..1fd76f7 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -58,7 +58,10 @@
}
HInvokeStaticOrDirect::DispatchInfo HSharpening::SharpenLoadMethod(
- ArtMethod* callee, bool has_method_id, CodeGenerator* codegen) {
+ ArtMethod* callee,
+ bool has_method_id,
+ bool for_interface_call,
+ CodeGenerator* codegen) {
if (kIsDebugBuild) {
ScopedObjectAccess soa(Thread::Current()); // Required for GetDeclaringClass below.
DCHECK(callee != nullptr);
@@ -83,8 +86,14 @@
// We don't optimize for debuggable as it would prevent us from obsoleting the method in some
// situations.
const CompilerOptions& compiler_options = codegen->GetCompilerOptions();
- if (callee == codegen->GetGraph()->GetArtMethod() && !codegen->GetGraph()->IsDebuggable()) {
- // Recursive call.
+ if (callee == codegen->GetGraph()->GetArtMethod() &&
+ !codegen->GetGraph()->IsDebuggable() &&
+ // The runtime expects the canonical interface method being passed as
+ // hidden argument when doing an invokeinterface. Because default methods
+ // can be called through invokevirtual, we may get a copied method if we
+ // load 'recursively'.
+ (!for_interface_call || !callee->IsDefault())) {
+ // Recursive load.
method_load_kind = MethodLoadKind::kRecursive;
code_ptr_location = CodePtrLocation::kCallSelf;
} else if (compiler_options.IsBootImage() || compiler_options.IsBootImageExtension()) {