From d690f8ae8f8e2675bc52089a83ac18c749f8e6d2 Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Fri, 1 Oct 2021 09:26:56 +0100 Subject: Inline across dex files for bootclaspath's methods We can relax a bit the restriction for not inlining across dexfiles when we are AoT compiling and we need an environment. There's an added new restriction related to BSS entries. We could potentially inline across dex files for those cases too but are left to be solved in follow-up CLs. Bug: 154012332 Test: ART tests Change-Id: I5122b26c79b3e30d2643c0ccc05d595a0047953e --- compiler/optimizing/stack_map_stream.cc | 37 +++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'compiler/optimizing/stack_map_stream.cc') diff --git a/compiler/optimizing/stack_map_stream.cc b/compiler/optimizing/stack_map_stream.cc index e52a3ce272..964b48c6ac 100644 --- a/compiler/optimizing/stack_map_stream.cc +++ b/compiler/optimizing/stack_map_stream.cc @@ -17,10 +17,14 @@ #include "stack_map_stream.h" #include +#include #include "art_method-inl.h" #include "base/stl_util.h" +#include "class_linker.h" +#include "dex/dex_file.h" #include "dex/dex_file_types.h" +#include "optimizing/nodes.h" #include "optimizing/optimizing_compiler.h" #include "runtime.h" #include "scoped_thread_state_change-inl.h" @@ -211,12 +215,26 @@ void StackMapStream::BeginInlineInfoEntry(ArtMethod* method, entry[InlineInfo::kArtMethodHi] = High32Bits(reinterpret_cast(method)); entry[InlineInfo::kArtMethodLo] = Low32Bits(reinterpret_cast(method)); } else { - if (dex_pc != static_cast(-1) && kIsDebugBuild) { + uint32_t bootclasspath_index = MethodInfo::kSameDexFile; + if (dex_pc != static_cast(-1)) { ScopedObjectAccess soa(Thread::Current()); - DCHECK(IsSameDexFile(*outer_dex_file, *method->GetDexFile())); + const DexFile* dex_file = method->GetDexFile(); + if (method->GetDeclaringClass()->GetClassLoader() == nullptr) { + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + const std::vector& boot_class_path = class_linker->GetBootClassPath(); + auto it = std::find_if( + boot_class_path.begin(), boot_class_path.end(), [dex_file](const DexFile* df) { + return IsSameDexFile(*df, *dex_file); + }); + DCHECK(it != boot_class_path.end()); + bootclasspath_index = std::distance(boot_class_path.begin(), it); + } else { + DCHECK(IsSameDexFile(*outer_dex_file, *dex_file)); + } } uint32_t dex_method_index = method->GetDexMethodIndex(); - entry[InlineInfo::kMethodInfoIndex] = method_infos_.Dedup({dex_method_index}); + entry[InlineInfo::kMethodInfoIndex] = + method_infos_.Dedup({dex_method_index, bootclasspath_index}); } current_inline_infos_.push_back(entry); @@ -232,7 +250,18 @@ void StackMapStream::BeginInlineInfoEntry(ArtMethod* method, if (encode_art_method) { CHECK_EQ(inline_info.GetArtMethod(), method); } else { - CHECK_EQ(code_info.GetMethodIndexOf(inline_info), method->GetDexMethodIndex()); + MethodInfo method_info = code_info.GetMethodInfoOf(inline_info); + CHECK_EQ(method_info.GetMethodIndex(), method->GetDexMethodIndex()); + if (inline_info.GetDexPc() != static_cast(-1)) { + ScopedObjectAccess soa(Thread::Current()); + if (method->GetDeclaringClass()->GetClassLoader() == nullptr) { + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + const std::vector& boot_class_path = class_linker->GetBootClassPath(); + DCHECK_LT(method_info.GetDexFileIndex(), boot_class_path.size()); + CHECK(IsSameDexFile(*boot_class_path[method_info.GetDexFileIndex()], + *method->GetDexFile())); + } + } } }); } -- cgit v1.2.3-59-g8ed1b