summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2024-04-29 09:58:23 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2024-04-30 14:18:27 +0000
commitf65b1c4e254b3fcd262ed6f26420d4d13b127709 (patch)
tree8b9b5a889fe7f5179cd8be5bd4f77b6e4af7aaa9 /runtime/class_linker.cc
parent256d751dd830fc6bf28f8b1aa99346e3b951e4c1 (diff)
Do not return an abstract class as IMT owner.
Abstract classes don't have an IMT and therefore cannot own one. Test: 141-class-unload Bug: 322253629 Change-Id: Ic6bb498d83ec66252710af384c24963be2287055
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 050896041b..5b00a87217 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -6627,8 +6627,15 @@ static ObjPtr<mirror::Class> GetImtOwner(ObjPtr<mirror::Class> klass)
DCHECK(imt != nullptr);
while (klass->HasSuperClass()) {
ObjPtr<mirror::Class> super_class = klass->GetSuperClass();
- if (super_class->ShouldHaveImt() && imt != super_class->GetImt(kRuntimePointerSize)) {
+ // Abstract classes cannot have IMTs, so we skip them.
+ while (super_class->IsAbstract()) {
+ DCHECK(super_class->HasSuperClass());
+ super_class = super_class->GetSuperClass();
+ }
+ DCHECK(super_class->ShouldHaveImt());
+ if (imt != super_class->GetImt(kRuntimePointerSize)) {
// IMT not shared with the super class, return the current class.
+ DCHECK_EQ(klass->GetImt(kRuntimePointerSize), imt) << klass->PrettyClass();
return klass;
}
klass = super_class;
@@ -6651,6 +6658,10 @@ ArtMethod* ClassLinker::AddMethodToConflictTable(ObjPtr<mirror::Class> klass,
DCHECK(imt_owner != nullptr);
LinearAlloc* linear_alloc = GetAllocatorForClassLoader(imt_owner->GetClassLoader());
+ // If the imt owner is in an image, the imt is also there and not in the
+ // linear alloc.
+ DCHECK_IMPLIES(runtime->GetHeap()->FindSpaceFromObject(imt_owner, /*fail_ok=*/true) == nullptr,
+ linear_alloc->Contains(klass->GetImt(kRuntimePointerSize)));
// Create a new entry if the existing one is the shared conflict method.
ArtMethod* new_conflict_method = (conflict_method == runtime->GetImtConflictMethod())