diff options
author | 2023-12-04 12:05:00 +0000 | |
---|---|---|
committer | 2024-01-03 14:48:12 +0000 | |
commit | 41c5dde40d1c75d36a7f984c8d72ec65fbff3111 (patch) | |
tree | 7fda2cbd5c320582b3f7b65a394d33bf9d7fed58 /compiler/optimizing/profiling_info_builder.cc | |
parent | c4aff3d48d3040b9b5a42b9f807e7d2671e138c0 (diff) |
Run optimizations with baseline compilation.
And introduce inlined inline caches, which customize an inline cache for
the top-level method being compiled.
Reduces jank on compose view scrolling for 20 seconds:
- For Go Mokey:
- Before: ~525 frames drawn / ~14.64% janky frames
- After: ~891 frames drawn / ~4.74% janky frames
- For Pixel 8 pro:
- Before: ~2443 frames drawn / ~0.91% janky frames
- After: ~2447 frames drawn / ~0.65% janky frames
Bug: 313040662
Test: test.py
Change-Id: Ibaa746c6bd3c665b18ec9cd29cb477cf21023467
Diffstat (limited to 'compiler/optimizing/profiling_info_builder.cc')
-rw-r--r-- | compiler/optimizing/profiling_info_builder.cc | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/compiler/optimizing/profiling_info_builder.cc b/compiler/optimizing/profiling_info_builder.cc index 7888753830..19795f5466 100644 --- a/compiler/optimizing/profiling_info_builder.cc +++ b/compiler/optimizing/profiling_info_builder.cc @@ -20,6 +20,7 @@ #include "code_generator.h" #include "driver/compiler_options.h" #include "dex/code_item_accessors-inl.h" +#include "inliner.h" #include "jit/profiling_info.h" #include "optimizing_compiler_stats.h" #include "scoped_thread_state_change-inl.h" @@ -42,10 +43,53 @@ void ProfilingInfoBuilder::Run() { ProfilingInfo::Create(soa.Self(), GetGraph()->GetArtMethod(), inline_caches_)); } + +uint32_t ProfilingInfoBuilder::EncodeInlinedDexPc(const HInliner* inliner, + const CompilerOptions& compiler_options, + HInvoke* invoke) { + DCHECK(inliner->GetCallerEnvironment() != nullptr); + DCHECK(inliner->GetParent() != nullptr); + std::vector<uint32_t> temp_vector; + temp_vector.push_back(invoke->GetDexPc()); + while (inliner->GetCallerEnvironment() != nullptr) { + temp_vector.push_back(inliner->GetCallerEnvironment()->GetDexPc()); + inliner = inliner->GetParent(); + } + + DCHECK_EQ(inliner->GetOutermostGraph(), inliner->GetGraph()); + return InlineCache::EncodeDexPc( + inliner->GetOutermostGraph()->GetArtMethod(), + temp_vector, + compiler_options.GetInlineMaxCodeUnits()); +} + +static uint32_t EncodeDexPc(HInvoke* invoke, const CompilerOptions& compiler_options) { + std::vector<uint32_t> dex_pcs; + ArtMethod* outer_method = nullptr; + for (HEnvironment* environment = invoke->GetEnvironment(); + environment != nullptr; + environment = environment->GetParent()) { + outer_method = environment->GetMethod(); + dex_pcs.push_back(environment->GetDexPc()); + } + + ScopedObjectAccess soa(Thread::Current()); + return InlineCache::EncodeDexPc( + outer_method, + dex_pcs, + compiler_options.GetInlineMaxCodeUnits()); +} + void ProfilingInfoBuilder::HandleInvoke(HInvoke* invoke) { - DCHECK(!invoke->GetEnvironment()->IsFromInlinedInvoke()); if (IsInlineCacheUseful(invoke, codegen_)) { - inline_caches_.push_back(invoke->GetDexPc()); + uint32_t dex_pc = EncodeDexPc(invoke, compiler_options_); + if (dex_pc != kNoDexPc) { + inline_caches_.push_back(dex_pc); + } else { + ScopedObjectAccess soa(Thread::Current()); + LOG(WARNING) << "Could not encode dex pc for " + << invoke->GetResolvedMethod()->PrettyMethod(); + } } } @@ -81,10 +125,15 @@ bool ProfilingInfoBuilder::IsInlineCacheUseful(HInvoke* invoke, CodeGenerator* c return true; } -InlineCache* ProfilingInfoBuilder::GetInlineCache(ProfilingInfo* info, HInvoke* instruction) { - DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); +InlineCache* ProfilingInfoBuilder::GetInlineCache(ProfilingInfo* info, + const CompilerOptions& compiler_options, + HInvoke* instruction) { ScopedObjectAccess soa(Thread::Current()); - return info->GetInlineCache(instruction->GetDexPc()); + uint32_t dex_pc = EncodeDexPc(instruction, compiler_options); + if (dex_pc == kNoDexPc) { + return nullptr; + } + return info->GetInlineCache(dex_pc); } } // namespace art |