Don't store copied methods in BSS.
Otherwise, we can end up in a state where the method on the stack is
unrelated to the receiver.
Also fix a comment related to GetCanonicalMethod and
StackVisitor::ValidateFrame.
Test: 810-checker-invoke-super-default
Change-Id: I3030e4af6059f7a4a7a1f046f2aabae8ce9057da
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index dc990ab..45c50b0 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -1320,6 +1320,10 @@
// If successful, update .bss entry in oat file if any.
if (called != nullptr) {
+ // We only put non copied methods in the BSS. Putting a copy can lead to an
+ // odd situation where the ArtMethod being executed is unrelated to the
+ // receiver of the method.
+ called = called->GetCanonicalMethod();
if (invoke_type == kSuper) {
if (called->GetDexFile() == called_method.dex_file) {
called_method.index = called->GetDexMethodIndex();
diff --git a/runtime/stack.cc b/runtime/stack.cc
index a20f40c..094c25b 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -711,8 +711,8 @@
LinearAlloc* const linear_alloc = runtime->GetLinearAlloc();
if (!linear_alloc->Contains(method)) {
// Check class linker linear allocs.
- // We get the canonical method as copied methods may have their declaring
- // class from another class loader.
+ // We get the canonical method as copied methods may have been allocated
+ // by a different class loader.
const PointerSize ptrSize = runtime->GetClassLinker()->GetImagePointerSize();
ArtMethod* canonical = method->GetCanonicalMethod(ptrSize);
ObjPtr<mirror::Class> klass = canonical->GetDeclaringClass();