diff options
author | 2021-11-01 09:02:09 +0000 | |
---|---|---|
committer | 2021-11-01 10:45:06 +0000 | |
commit | e43aa3f55fd01ce0887059b309a41b6441521e7c (patch) | |
tree | 7ba4ef9adfbb77e6baa1891c3fabd783fb03d580 /compiler/optimizing/inliner.cc | |
parent | 808d8cc8114e0c5ee3116639fe9d31be5a70403a (diff) |
Revert^2 "Inline across dex files for bootclaspath's methods"
This reverts commit 8cb989f1019c4fa30845bf2deb5bc996ed4e8966, so we
are re-enabling commit d690f8ae8f8e2675bc52089a83ac18c749f8e6d2.
Reason for revert: Failing test was fixed here
https://android-review.googlesource.com/c/platform/art/+/1873567
Bug: 154012332
Test: ART tests
Change-Id: If159b29583e35abcfe753f30483f83990208b1b9
Diffstat (limited to 'compiler/optimizing/inliner.cc')
-rw-r--r-- | compiler/optimizing/inliner.cc | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index c7426828cb..17957d8b0f 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -1701,18 +1701,26 @@ static inline Handle<T> NewHandleIfDifferent(ObjPtr<T> object, Handle<T> hint, H return (object != hint.Get()) ? graph->GetHandleCache()->NewHandle(object) : hint; } -static bool CanEncodeInlinedMethodInStackMap(const DexFile& caller_dex_file, ArtMethod* callee) +static bool CanEncodeInlinedMethodInStackMap(const DexFile& outer_dex_file, + ArtMethod* callee, + bool* out_needs_bss_check) REQUIRES_SHARED(Locks::mutator_lock_) { if (!Runtime::Current()->IsAotCompiler()) { // JIT can always encode methods in stack maps. return true; } - if (IsSameDexFile(caller_dex_file, *callee->GetDexFile())) { + if (IsSameDexFile(outer_dex_file, *callee->GetDexFile())) { return true; } + + // Inline across dexfiles if the callee's DexFile is in the bootclasspath. + if (callee->GetDeclaringClass()->GetClassLoader() == nullptr) { + *out_needs_bss_check = true; + return true; + } + // TODO(ngeoffray): Support more AOT cases for inlining: // - methods in multidex - // - methods in boot image for on-device non-PIC compilation. return false; } @@ -1822,6 +1830,11 @@ bool HInliner::CanInlineBody(const HGraph* callee_graph, return false; } + const bool too_many_registers = + total_number_of_dex_registers_ > kMaximumNumberOfCumulatedDexRegisters; + bool needs_bss_check = false; + const bool can_encode_in_stack_map = CanEncodeInlinedMethodInStackMap( + *outer_compilation_unit_.GetDexFile(), resolved_method, &needs_bss_check); size_t number_of_instructions = 0; // Skip the entry block, it does not contain instructions that prevent inlining. for (HBasicBlock* block : callee_graph->GetReversePostOrderSkipEntryBlock()) { @@ -1856,24 +1869,22 @@ bool HInliner::CanInlineBody(const HGraph* callee_graph, return false; } HInstruction* current = instr_it.Current(); - if (current->NeedsEnvironment() && - (total_number_of_dex_registers_ > kMaximumNumberOfCumulatedDexRegisters)) { - LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedEnvironmentBudget) - << "Method " << resolved_method->PrettyMethod() - << " is not inlined because its caller has reached" - << " its environment budget limit."; - return false; - } + if (current->NeedsEnvironment()) { + if (too_many_registers) { + LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedEnvironmentBudget) + << "Method " << resolved_method->PrettyMethod() + << " is not inlined because its caller has reached" + << " its environment budget limit."; + return false; + } - if (current->NeedsEnvironment() && - !CanEncodeInlinedMethodInStackMap(*caller_compilation_unit_.GetDexFile(), - resolved_method)) { - LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedStackMaps) - << "Method " << resolved_method->PrettyMethod() - << " could not be inlined because " << current->DebugName() - << " needs an environment, is in a different dex file" - << ", and cannot be encoded in the stack maps."; - return false; + if (!can_encode_in_stack_map) { + LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedStackMaps) + << "Method " << resolved_method->PrettyMethod() << " could not be inlined because " + << current->DebugName() << " needs an environment, is in a different dex file" + << ", and cannot be encoded in the stack maps."; + return false; + } } if (current->IsUnresolvedStaticFieldGet() || @@ -1887,6 +1898,21 @@ bool HInliner::CanInlineBody(const HGraph* callee_graph, << " entrypoint"; return false; } + + // We currently don't have support for inlining across dex files if the inlined method needs a + // .bss entry. This only happens when we are: + // 1) In AoT, + // 2) cross-dex inlining, and + // 3) have an instruction that needs a bss entry, which will always be + // 3)b) an instruction that needs an environment. + // TODO(solanes, 154012332): Add this support. + if (needs_bss_check && current->NeedsBss()) { + DCHECK(current->NeedsEnvironment()); + LOG_FAIL(stats_, MethodCompilationStat::kNotInlinedBss) + << "Method " << resolved_method->PrettyMethod() + << " could not be inlined because it needs a BSS check"; + return false; + } } } |