From b740438513307629491c575dbf895bbbf215f77c Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Wed, 2 Feb 2022 16:00:52 +0000 Subject: Revert^2 "Add bss support for inlining BCP DexFiles for single image" This reverts commit 239c449f10853374a9a7a2bd1d8413354054573e. Reason for revert: Fix in android-review.googlesource.com/c/1968661/1..3 Additionally, we are adding the runtime support for updating the .bss slots on android-review.googlesource.com/c/1968661/3..4. Since BCP the DexFiles will not have a corresponding OatDexFile, we can do a best-effort try to fetch the outer method's OatFile to update the bss slots at runtime. Bug: 154012332 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Test: Compile and open top 10 APKs with csuite locally Change-Id: Ifb2b152cee363c4674fc9273690c73f0406282ba --- runtime/entrypoints/entrypoint_utils.cc | 51 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'runtime/entrypoints/entrypoint_utils.cc') diff --git a/runtime/entrypoints/entrypoint_utils.cc b/runtime/entrypoints/entrypoint_utils.cc index 1c0127a519..63d2aa4351 100644 --- a/runtime/entrypoints/entrypoint_utils.cc +++ b/runtime/entrypoints/entrypoint_utils.cc @@ -36,6 +36,7 @@ #include "mirror/object_array-inl.h" #include "nth_caller_visitor.h" #include "oat_file.h" +#include "oat_file-inl.h" #include "oat_quick_method_header.h" #include "reflection.h" #include "scoped_thread_state_change-inl.h" @@ -284,22 +285,46 @@ ObjPtr ResolveMethodTypeFromCode(ArtMethod* referrer, return method_type; } -void MaybeUpdateBssMethodEntry(ArtMethod* callee, MethodReference callee_reference) { - DCHECK(callee != nullptr); - if (callee_reference.dex_file->GetOatDexFile() != nullptr) { - size_t bss_offset = IndexBssMappingLookup::GetBssOffset( - callee_reference.dex_file->GetOatDexFile()->GetMethodBssMapping(), - callee_reference.index, - callee_reference.dex_file->NumMethodIds(), - static_cast(kRuntimePointerSize)); +void MaybeUpdateBssMethodEntry(ArtMethod* callee, + MethodReference callee_reference, + ArtMethod* outer_method) { + DCHECK_NE(callee, nullptr); + if (outer_method->GetDexFile()->GetOatDexFile() == nullptr || + outer_method->GetDexFile()->GetOatDexFile()->GetOatFile() == nullptr) { + // No OatFile to update. + return; + } + const OatFile* outer_oat_file = outer_method->GetDexFile()->GetOatDexFile()->GetOatFile(); + + const DexFile* dex_file = callee_reference.dex_file; + const OatDexFile* oat_dex_file = dex_file->GetOatDexFile(); + const IndexBssMapping* mapping = nullptr; + if (oat_dex_file != nullptr && oat_dex_file->GetOatFile() == outer_oat_file) { + // DexFiles compiled together to an oat file case. + mapping = oat_dex_file->GetMethodBssMapping(); + } else { + // Try to find the DexFile in the BCP of the outer_method. + const OatFile::BssMappingInfo* mapping_info = outer_oat_file->FindBcpMappingInfo(dex_file); + if (mapping_info != nullptr) { + mapping = mapping_info->method_bss_mapping; + } + } + + // Perform the update if we found a mapping. + if (mapping != nullptr) { + size_t bss_offset = + IndexBssMappingLookup::GetBssOffset(mapping, + callee_reference.index, + dex_file->NumMethodIds(), + static_cast(kRuntimePointerSize)); if (bss_offset != IndexBssMappingLookup::npos) { DCHECK_ALIGNED(bss_offset, static_cast(kRuntimePointerSize)); - const OatFile* oat_file = callee_reference.dex_file->GetOatDexFile()->GetOatFile(); - ArtMethod** method_entry = reinterpret_cast(const_cast( - oat_file->BssBegin() + bss_offset)); - DCHECK_GE(method_entry, oat_file->GetBssMethods().data()); + DCHECK_NE(outer_oat_file, nullptr); + ArtMethod** method_entry = reinterpret_cast( + const_cast(outer_oat_file->BssBegin() + bss_offset)); + DCHECK_GE(method_entry, outer_oat_file->GetBssMethods().data()); DCHECK_LT(method_entry, - oat_file->GetBssMethods().data() + oat_file->GetBssMethods().size()); + outer_oat_file->GetBssMethods().data() + outer_oat_file->GetBssMethods().size()); std::atomic* atomic_entry = reinterpret_cast*>(method_entry); if (kIsDebugBuild) { -- cgit v1.2.3-59-g8ed1b