blob: b26afd1ca39680377c84ad2c4d8b88477ac734fb [file] [log] [blame]
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "inliner.h"
18
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000020#include "builder.h"
21#include "class_linker.h"
22#include "constant_folding.h"
23#include "dead_code_elimination.h"
24#include "driver/compiler_driver-inl.h"
25#include "driver/dex_compilation_unit.h"
26#include "instruction_simplifier.h"
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000027#include "mirror/class_loader.h"
28#include "mirror/dex_cache.h"
29#include "nodes.h"
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +010030#include "reference_type_propagation.h"
Nicolas Geoffray259136f2014-12-17 23:21:58 +000031#include "register_allocator.h"
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000032#include "ssa_phi_elimination.h"
33#include "scoped_thread_state_change.h"
34#include "thread.h"
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010035#include "dex/verified_method.h"
36#include "dex/verification_results.h"
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000037
38namespace art {
39
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +010040static constexpr int kMaxInlineCodeUnits = 18;
41static constexpr int kDepthLimit = 3;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000042
43void HInliner::Run() {
Nicolas Geoffraye50b8d22015-03-13 08:57:42 +000044 if (graph_->IsDebuggable()) {
45 // For simplicity, we currently never inline when the graph is debuggable. This avoids
46 // doing some logic in the runtime to discover if a method could have been inlined.
47 return;
48 }
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000049 const GrowableArray<HBasicBlock*>& blocks = graph_->GetReversePostOrder();
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +010050 HBasicBlock* next_block = blocks.Get(0);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000051 for (size_t i = 0; i < blocks.Size(); ++i) {
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +010052 // Because we are changing the graph when inlining, we need to remember the next block.
53 // This avoids doing the inlining work again on the inlined blocks.
54 if (blocks.Get(i) != next_block) {
55 continue;
56 }
57 HBasicBlock* block = next_block;
58 next_block = (i == blocks.Size() - 1) ? nullptr : blocks.Get(i + 1);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000059 for (HInstruction* instruction = block->GetFirstInstruction(); instruction != nullptr;) {
60 HInstruction* next = instruction->GetNext();
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +010061 HInvoke* call = instruction->AsInvoke();
Razvan A Lupusoru3e90a962015-03-27 13:44:44 -070062 // As long as the call is not intrinsified, it is worth trying to inline.
63 if (call != nullptr && call->GetIntrinsic() == Intrinsics::kNone) {
Nicolas Geoffray79041292015-03-26 10:05:54 +000064 // We use the original invoke type to ensure the resolution of the called method
65 // works properly.
66 if (!TryInline(call, call->GetDexMethodIndex(), call->GetOriginalInvokeType())) {
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000067 if (kIsDebugBuild) {
68 std::string callee_name =
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000069 PrettyMethod(call->GetDexMethodIndex(), *outer_compilation_unit_.GetDexFile());
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000070 bool should_inline = callee_name.find("$inline$") != std::string::npos;
71 CHECK(!should_inline) << "Could not inline " << callee_name;
72 }
73 }
74 }
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +000075 instruction = next;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000076 }
77 }
78}
79
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +010080static bool IsMethodOrDeclaringClassFinal(ArtMethod* method)
81 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
82 return method->IsFinal() || method->GetDeclaringClass()->IsFinal();
83}
84
85/**
86 * Given the `resolved_method` looked up in the dex cache, try to find
87 * the actual runtime target of an interface or virtual call.
88 * Return nullptr if the runtime target cannot be proven.
89 */
90static ArtMethod* FindVirtualOrInterfaceTarget(HInvoke* invoke, ArtMethod* resolved_method)
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
92 if (IsMethodOrDeclaringClassFinal(resolved_method)) {
93 // No need to lookup further, the resolved method will be the target.
94 return resolved_method;
95 }
96
97 HInstruction* receiver = invoke->InputAt(0);
98 if (receiver->IsNullCheck()) {
99 // Due to multiple levels of inlining within the same pass, it might be that
100 // null check does not have the reference type of the actual receiver.
101 receiver = receiver->InputAt(0);
102 }
103 ReferenceTypeInfo info = receiver->GetReferenceTypeInfo();
104 if (info.IsTop()) {
105 // We have no information on the receiver.
106 return nullptr;
107 } else if (!info.IsExact()) {
108 // We currently only support inlining with known receivers.
109 // TODO: Remove this check, we should be able to inline final methods
110 // on unknown receivers.
111 return nullptr;
112 } else if (info.GetTypeHandle()->IsInterface()) {
113 // Statically knowing that the receiver has an interface type cannot
114 // help us find what is the target method.
115 return nullptr;
116 }
117
118 ClassLinker* cl = Runtime::Current()->GetClassLinker();
119 size_t pointer_size = cl->GetImagePointerSize();
120 if (invoke->IsInvokeInterface()) {
121 resolved_method = info.GetTypeHandle()->FindVirtualMethodForInterface(
122 resolved_method, pointer_size);
123 } else {
124 DCHECK(invoke->IsInvokeVirtual());
125 resolved_method = info.GetTypeHandle()->FindVirtualMethodForVirtual(
126 resolved_method, pointer_size);
127 }
128
129 if (resolved_method == nullptr) {
130 // The information we had on the receiver was not enough to find
131 // the target method. Since we check above the exact type of the receiver,
132 // the only reason this can happen is an IncompatibleClassChangeError.
133 return nullptr;
134 } else if (resolved_method->IsAbstract()) {
135 // The information we had on the receiver was not enough to find
136 // the target method. Since we check above the exact type of the receiver,
137 // the only reason this can happen is an IncompatibleClassChangeError.
138 return nullptr;
139 } else if (IsMethodOrDeclaringClassFinal(resolved_method)) {
140 // A final method has to be the target method.
141 return resolved_method;
142 } else if (info.IsExact()) {
143 // If we found a method and the receiver's concrete type is statically
144 // known, we know for sure the target.
145 return resolved_method;
146 } else {
147 // Even if we did find a method, the receiver type was not enough to
148 // statically find the runtime target.
149 return nullptr;
150 }
151}
152
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000153bool HInliner::TryInline(HInvoke* invoke_instruction,
154 uint32_t method_index,
155 InvokeType invoke_type) const {
156 ScopedObjectAccess soa(Thread::Current());
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000157 const DexFile& caller_dex_file = *caller_compilation_unit_.GetDexFile();
158 VLOG(compiler) << "Try inlining " << PrettyMethod(method_index, caller_dex_file);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000159
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +0100160 ArtMethod* resolved_method = nullptr;
161 {
162 // Don't keep this handle scope on stack, otherwise we cannot do a reference type
163 // propagation while inlining.
164 StackHandleScope<2> hs(soa.Self());
165 Handle<mirror::DexCache> dex_cache(
166 hs.NewHandle(caller_compilation_unit_.GetClassLinker()->FindDexCache(caller_dex_file)));
167 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(
168 soa.Decode<mirror::ClassLoader*>(caller_compilation_unit_.GetClassLoader())));
169 resolved_method = compiler_driver_->ResolveMethod(
170 soa, dex_cache, class_loader, &caller_compilation_unit_, method_index, invoke_type);
171 }
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000172
Mathieu Chartiere401d142015-04-22 13:56:20 -0700173 if (resolved_method == nullptr) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000174 VLOG(compiler) << "Method cannot be resolved " << PrettyMethod(method_index, caller_dex_file);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000175 return false;
176 }
177
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +0100178 if (!invoke_instruction->IsInvokeStaticOrDirect()) {
179 resolved_method = FindVirtualOrInterfaceTarget(invoke_instruction, resolved_method);
180 if (resolved_method == nullptr) {
181 VLOG(compiler) << "Interface or virtual call to "
182 << PrettyMethod(method_index, caller_dex_file)
183 << "could not be statically determined";
184 return false;
185 }
186 }
187
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100188 bool same_dex_file = true;
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000189 const DexFile& outer_dex_file = *outer_compilation_unit_.GetDexFile();
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000190 if (resolved_method->GetDexFile()->GetLocation().compare(outer_dex_file.GetLocation()) != 0) {
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100191 same_dex_file = false;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000192 }
193
194 const DexFile::CodeItem* code_item = resolved_method->GetCodeItem();
195
196 if (code_item == nullptr) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000197 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000198 << " is not inlined because it is native";
199 return false;
200 }
201
202 if (code_item->insns_size_in_code_units_ > kMaxInlineCodeUnits) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000203 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000204 << " is too big to inline";
205 return false;
206 }
207
208 if (code_item->tries_size_ != 0) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000209 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000210 << " is not inlined because of try block";
211 return false;
212 }
213
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100214 uint16_t class_def_idx = resolved_method->GetDeclaringClass()->GetDexClassDefIndex();
215 if (!compiler_driver_->IsMethodVerifiedWithoutFailures(
216 resolved_method->GetDexMethodIndex(), class_def_idx, *resolved_method->GetDexFile())) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000217 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100218 << " couldn't be verified, so it cannot be inlined";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000219 return false;
220 }
221
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000222 if (resolved_method->ShouldNotInline()) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000223 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000224 << " was already flagged as non inlineable";
225 return false;
226 }
227
Roland Levillain4c0eb422015-04-24 16:43:49 +0100228 if (invoke_instruction->IsInvokeStaticOrDirect() &&
229 invoke_instruction->AsInvokeStaticOrDirect()->IsStaticWithImplicitClinitCheck()) {
230 // Case of a static method that cannot be inlined because it implicitly
231 // requires an initialization check of its declaring class.
232 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
233 << " is not inlined because it is static and requires a clinit"
234 << " check that cannot be emitted due to Dex cache limitations";
235 return false;
236 }
237
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100238 if (!TryBuildAndInline(resolved_method, invoke_instruction, method_index, same_dex_file)) {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000239 return false;
240 }
241
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000242 VLOG(compiler) << "Successfully inlined " << PrettyMethod(method_index, caller_dex_file);
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000243 MaybeRecordStat(kInlinedInvoke);
244 return true;
245}
246
Mathieu Chartiere401d142015-04-22 13:56:20 -0700247bool HInliner::TryBuildAndInline(ArtMethod* resolved_method,
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000248 HInvoke* invoke_instruction,
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000249 uint32_t method_index,
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100250 bool same_dex_file) const {
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000251 ScopedObjectAccess soa(Thread::Current());
252 const DexFile::CodeItem* code_item = resolved_method->GetCodeItem();
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000253 const DexFile& caller_dex_file = *caller_compilation_unit_.GetDexFile();
Nicolas Geoffrayc0365b12015-03-18 18:31:52 +0000254
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000255 DexCompilationUnit dex_compilation_unit(
256 nullptr,
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000257 caller_compilation_unit_.GetClassLoader(),
258 caller_compilation_unit_.GetClassLinker(),
259 *resolved_method->GetDexFile(),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000260 code_item,
261 resolved_method->GetDeclaringClass()->GetDexClassDefIndex(),
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000262 resolved_method->GetDexMethodIndex(),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000263 resolved_method->GetAccessFlags(),
264 nullptr);
265
Calin Juravle3cd4fc82015-05-14 15:15:42 +0100266 bool requires_ctor_barrier = false;
267
268 if (dex_compilation_unit.IsConstructor()) {
269 // If it's a super invocation and we already generate a barrier there's no need
270 // to generate another one.
271 // We identify super calls by looking at the "this" pointer. If its value is the
272 // same as the local "this" pointer then we must have a super invocation.
273 bool is_super_invocation = invoke_instruction->InputAt(0)->IsParameterValue()
274 && invoke_instruction->InputAt(0)->AsParameterValue()->IsThis();
275 if (is_super_invocation && graph_->ShouldGenerateConstructorBarrier()) {
276 requires_ctor_barrier = false;
277 } else {
278 Thread* self = Thread::Current();
279 requires_ctor_barrier = compiler_driver_->RequiresConstructorBarrier(self,
280 dex_compilation_unit.GetDexFile(),
281 dex_compilation_unit.GetClassDefIndex());
282 }
283 }
284
Nicolas Geoffraye0fe7ae2015-03-09 10:02:49 +0000285 HGraph* callee_graph = new (graph_->GetArena()) HGraph(
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100286 graph_->GetArena(),
287 caller_dex_file,
288 method_index,
Calin Juravle3cd4fc82015-05-14 15:15:42 +0100289 requires_ctor_barrier,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700290 compiler_driver_->GetInstructionSet(),
Nicolas Geoffrayb176d7c2015-05-20 18:48:31 +0100291 invoke_instruction->GetOriginalInvokeType(),
Nicolas Geoffray0a23d742015-05-07 11:57:35 +0100292 graph_->IsDebuggable(),
293 graph_->GetCurrentInstructionId());
David Brazdil5e8b1372015-01-23 14:39:08 +0000294
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000295 OptimizingCompilerStats inline_stats;
David Brazdil5e8b1372015-01-23 14:39:08 +0000296 HGraphBuilder builder(callee_graph,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000297 &dex_compilation_unit,
298 &outer_compilation_unit_,
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000299 resolved_method->GetDexFile(),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000300 compiler_driver_,
301 &inline_stats);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000302
David Brazdil5e8b1372015-01-23 14:39:08 +0000303 if (!builder.BuildGraph(*code_item)) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000304 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000305 << " could not be built, so cannot be inlined";
Nicolas Geoffray5ae13252015-05-27 12:53:36 +0100306 // There could be multiple reasons why the graph could not be built, including
307 // unaccessible methods/fields due to using a different dex cache. We do not mark
308 // the method as non-inlineable so that other callers can still try to inline it.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000309 return false;
310 }
311
Nicolas Geoffray259136f2014-12-17 23:21:58 +0000312 if (!RegisterAllocator::CanAllocateRegistersFor(*callee_graph,
313 compiler_driver_->GetInstructionSet())) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000314 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffray259136f2014-12-17 23:21:58 +0000315 << " cannot be inlined because of the register allocator";
Nicolas Geoffrayd0261432015-05-26 14:35:06 +0100316 resolved_method->SetShouldNotInline();
Nicolas Geoffray259136f2014-12-17 23:21:58 +0000317 return false;
318 }
319
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000320 if (!callee_graph->TryBuildingSsa()) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000321 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000322 << " could not be transformed to SSA";
Nicolas Geoffrayd0261432015-05-26 14:35:06 +0100323 resolved_method->SetShouldNotInline();
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000324 return false;
325 }
326
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000327 // Run simple optimizations on the graph.
Calin Juravle7a9c8852015-04-21 14:07:50 +0100328 HDeadCodeElimination dce(callee_graph, stats_);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000329 HConstantFolding fold(callee_graph);
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +0100330 ReferenceTypePropagation type_propagation(callee_graph, handles_);
Calin Juravleacf735c2015-02-12 15:25:22 +0000331 InstructionSimplifier simplify(callee_graph, stats_);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000332
333 HOptimization* optimizations[] = {
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000334 &dce,
335 &fold,
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +0100336 &type_propagation,
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000337 &simplify,
338 };
339
340 for (size_t i = 0; i < arraysize(optimizations); ++i) {
341 HOptimization* optimization = optimizations[i];
342 optimization->Run();
343 }
344
345 if (depth_ + 1 < kDepthLimit) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000346 HInliner inliner(callee_graph,
347 outer_compilation_unit_,
348 dex_compilation_unit,
349 compiler_driver_,
Nicolas Geoffray1d5006c2015-06-03 15:04:32 +0100350 handles_,
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000351 stats_,
352 depth_ + 1);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000353 inliner.Run();
354 }
355
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100356 // TODO: We should abort only if all predecessors throw. However,
357 // HGraph::InlineInto currently does not handle an exit block with
358 // a throw predecessor.
359 HBasicBlock* exit_block = callee_graph->GetExitBlock();
360 if (exit_block == nullptr) {
361 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
362 << " could not be inlined because it has an infinite loop";
363 resolved_method->SetShouldNotInline();
364 return false;
365 }
366
367 bool has_throw_predecessor = false;
368 for (size_t i = 0, e = exit_block->GetPredecessors().Size(); i < e; ++i) {
369 if (exit_block->GetPredecessors().Get(i)->GetLastInstruction()->IsThrow()) {
370 has_throw_predecessor = true;
371 break;
372 }
373 }
374 if (has_throw_predecessor) {
375 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
376 << " could not be inlined because one branch always throws";
377 resolved_method->SetShouldNotInline();
378 return false;
379 }
380
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000381 HReversePostOrderIterator it(*callee_graph);
Nicolas Geoffrayef87c5d2015-01-30 12:41:14 +0000382 it.Advance(); // Past the entry block, it does not contain instructions that prevent inlining.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000383 for (; !it.Done(); it.Advance()) {
384 HBasicBlock* block = it.Current();
385 if (block->IsLoopHeader()) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000386 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000387 << " could not be inlined because it contains a loop";
Nicolas Geoffrayd0261432015-05-26 14:35:06 +0100388 resolved_method->SetShouldNotInline();
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000389 return false;
390 }
391
392 for (HInstructionIterator instr_it(block->GetInstructions());
393 !instr_it.Done();
394 instr_it.Advance()) {
395 HInstruction* current = instr_it.Current();
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000396
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100397 if (current->IsInvokeInterface()) {
398 // Disable inlining of interface calls. The cost in case of entering the
399 // resolution conflict is currently too high.
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000400 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100401 << " could not be inlined because it has an interface call.";
Nicolas Geoffrayd0261432015-05-26 14:35:06 +0100402 resolved_method->SetShouldNotInline();
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000403 return false;
404 }
405
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100406 if (!same_dex_file && current->NeedsEnvironment()) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000407 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000408 << " could not be inlined because " << current->DebugName()
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100409 << " needs an environment and is in a different dex file";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000410 return false;
411 }
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000412
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100413 if (!same_dex_file && current->NeedsDexCache()) {
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000414 VLOG(compiler) << "Method " << PrettyMethod(method_index, caller_dex_file)
415 << " could not be inlined because " << current->DebugName()
416 << " it is in a different dex file and requires access to the dex cache";
Nicolas Geoffrayd0261432015-05-26 14:35:06 +0100417 // Do not flag the method as not-inlineable. A caller within the same
418 // dex file could still successfully inline it.
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000419 return false;
420 }
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000421 }
422 }
423
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000424 callee_graph->InlineInto(graph_, invoke_instruction);
Nicolas Geoffray7c5367b2014-12-17 10:13:46 +0000425
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000426 return true;
427}
428
429} // namespace art