diff options
| author | 2019-05-14 14:42:02 +0100 | |
|---|---|---|
| committer | 2019-05-15 10:46:22 +0100 | |
| commit | ad7dbacc3a0f41e4bd6fd9dc33e806489cbedcbe (patch) | |
| tree | f54d26bc9c1369d86cbbd47a8fcf80e244a53bf1 | |
| parent | 3ac5ea4aa6f12a45e64bb2665e9abff2206d664f (diff) | |
oatdump: Fix oat code retrieval.
Test: m dump-oat-boot
Bug: 132685275
(cherry picked from commit e00e20103fe798669b69de79e161650908659d05)
Change-Id: I9d11fc494f704a57603ca3e017dcb778e9d8eeaf
Merged-In: I151969ad6ac6bd7a8dce6c7427478cdde369bfd0
| -rw-r--r-- | oatdump/oatdump.cc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index b14d407e15..6fa4e9d432 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -716,8 +716,27 @@ class OatDumper { if (class_def != nullptr) { uint16_t class_def_index = dex_file->GetIndexForClassDef(*class_def); const OatFile::OatClass oat_class = oat_dex_file->GetOatClass(class_def_index); - size_t method_index = m->GetMethodIndex(); - return oat_class.GetOatMethod(method_index).GetQuickCode(); + uint32_t oat_method_index; + if (m->IsStatic() || m->IsDirect()) { + // Simple case where the oat method index was stashed at load time. + oat_method_index = m->GetMethodIndex(); + } else { + // Compute the oat_method_index by search for its position in the class def. + ClassAccessor accessor(*dex_file, *class_def); + oat_method_index = accessor.NumDirectMethods(); + bool found_virtual = false; + for (ClassAccessor::Method dex_method : accessor.GetVirtualMethods()) { + // Check method index instead of identity in case of duplicate method definitions. + if (dex_method.GetIndex() == m->GetDexMethodIndex()) { + found_virtual = true; + break; + } + ++oat_method_index; + } + CHECK(found_virtual) << "Didn't find oat method index for virtual method: " + << dex_file->PrettyMethod(m->GetDexMethodIndex()); + } + return oat_class.GetOatMethod(oat_method_index).GetQuickCode(); } } } |