File: | jdk/src/hotspot/share/opto/bytecodeInfo.cpp |
Warning: | line 66, column 3 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. | |||
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
4 | * | |||
5 | * This code is free software; you can redistribute it and/or modify it | |||
6 | * under the terms of the GNU General Public License version 2 only, as | |||
7 | * published by the Free Software Foundation. | |||
8 | * | |||
9 | * This code is distributed in the hope that it will be useful, but WITHOUT | |||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
12 | * version 2 for more details (a copy is included in the LICENSE file that | |||
13 | * accompanied this code). | |||
14 | * | |||
15 | * You should have received a copy of the GNU General Public License version | |||
16 | * 2 along with this work; if not, write to the Free Software Foundation, | |||
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |||
18 | * | |||
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |||
20 | * or visit www.oracle.com if you need additional information or have any | |||
21 | * questions. | |||
22 | * | |||
23 | */ | |||
24 | ||||
25 | #include "precompiled.hpp" | |||
26 | #include "ci/ciReplay.hpp" | |||
27 | #include "classfile/vmSymbols.hpp" | |||
28 | #include "compiler/compilationPolicy.hpp" | |||
29 | #include "compiler/compileBroker.hpp" | |||
30 | #include "compiler/compilerEvent.hpp" | |||
31 | #include "compiler/compileLog.hpp" | |||
32 | #include "interpreter/linkResolver.hpp" | |||
33 | #include "jfr/jfrEvents.hpp" | |||
34 | #include "oops/objArrayKlass.hpp" | |||
35 | #include "opto/callGenerator.hpp" | |||
36 | #include "opto/parse.hpp" | |||
37 | #include "runtime/handles.inline.hpp" | |||
38 | #include "utilities/events.hpp" | |||
39 | ||||
40 | //============================================================================= | |||
41 | //------------------------------InlineTree------------------------------------- | |||
42 | InlineTree::InlineTree(Compile* c, | |||
43 | const InlineTree *caller_tree, ciMethod* callee, | |||
44 | JVMState* caller_jvms, int caller_bci, | |||
45 | int max_inline_level) : | |||
46 | C(c), | |||
47 | _caller_jvms(caller_jvms), | |||
48 | _method(callee), | |||
49 | _late_inline(false), | |||
50 | _caller_tree((InlineTree*) caller_tree), | |||
51 | _count_inline_bcs(method()->code_size_for_inlining()), | |||
52 | _max_inline_level(max_inline_level), | |||
53 | _subtrees(c->comp_arena(), 2, 0, NULL__null), | |||
54 | _msg(NULL__null) | |||
55 | { | |||
56 | #ifndef PRODUCT | |||
57 | _count_inlines = 0; | |||
58 | _forced_inline = false; | |||
59 | #endif | |||
60 | if (_caller_jvms != NULL__null) { | |||
61 | // Keep a private copy of the caller_jvms: | |||
62 | _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms()); | |||
63 | _caller_jvms->set_bci(caller_jvms->bci()); | |||
64 | assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining")do { if (!(!caller_jvms->should_reexecute())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 64, "assert(" "!caller_jvms->should_reexecute()" ") failed" , "there should be no reexecute bytecode with inlining"); ::breakpoint (); } } while (0); | |||
65 | } | |||
66 | assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS")do { if (!(_caller_jvms->same_calls_as(caller_jvms))) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 66, "assert(" "_caller_jvms->same_calls_as(caller_jvms)" ") failed", "consistent JVMS"); ::breakpoint(); } } while (0 ); | |||
| ||||
67 | assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter")do { if (!((caller_tree == __null ? 0 : caller_tree->stack_depth () + 1) == stack_depth())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 67, "assert(" "(caller_tree == __null ? 0 : caller_tree->stack_depth() + 1) == stack_depth()" ") failed", "correct (redundant) depth parameter"); ::breakpoint (); } } while (0); | |||
68 | assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter")do { if (!(caller_bci == this->caller_bci())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 68, "assert(" "caller_bci == this->caller_bci()" ") failed" , "correct (redundant) bci parameter"); ::breakpoint(); } } while (0); | |||
69 | // Update hierarchical counts, count_inline_bcs() and count_inlines() | |||
70 | InlineTree *caller = (InlineTree *)caller_tree; | |||
71 | for( ; caller != NULL__null; caller = ((InlineTree *)(caller->caller_tree())) ) { | |||
72 | caller->_count_inline_bcs += count_inline_bcs(); | |||
73 | NOT_PRODUCT(caller->_count_inlines++;)caller->_count_inlines++; | |||
74 | } | |||
75 | } | |||
76 | ||||
77 | /** | |||
78 | * Return true when EA is ON and a java constructor is called or | |||
79 | * a super constructor is called from an inlined java constructor. | |||
80 | * Also return true for boxing methods. | |||
81 | * Also return true for methods returning Iterator (including Iterable::iterator()) | |||
82 | * that is essential for forall-loops performance. | |||
83 | */ | |||
84 | static bool is_init_with_ea(ciMethod* callee_method, | |||
85 | ciMethod* caller_method, Compile* C) { | |||
86 | if (!C->do_escape_analysis() || !EliminateAllocations) { | |||
87 | return false; // EA is off | |||
88 | } | |||
89 | if (callee_method->is_initializer()) { | |||
90 | return true; // constuctor | |||
91 | } | |||
92 | if (caller_method->is_initializer() && | |||
93 | caller_method != C->method() && | |||
94 | caller_method->holder()->is_subclass_of(callee_method->holder())) { | |||
95 | return true; // super constructor is called from inlined constructor | |||
96 | } | |||
97 | if (C->eliminate_boxing() && callee_method->is_boxing_method()) { | |||
98 | return true; | |||
99 | } | |||
100 | ciType *retType = callee_method->signature()->return_type(); | |||
101 | ciKlass *iter = C->env()->Iterator_klass(); | |||
102 | if(retType->is_loaded() && iter->is_loaded() && retType->is_subtype_of(iter)) { | |||
103 | return true; | |||
104 | } | |||
105 | return false; | |||
106 | } | |||
107 | ||||
108 | /** | |||
109 | * Force inlining unboxing accessor. | |||
110 | */ | |||
111 | static bool is_unboxing_method(ciMethod* callee_method, Compile* C) { | |||
112 | return C->eliminate_boxing() && callee_method->is_unboxing_method(); | |||
113 | } | |||
114 | ||||
115 | // positive filter: should callee be inlined? | |||
116 | bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method, | |||
117 | int caller_bci, NOT_PRODUCT_ARG(bool& should_delay)bool& should_delay, ciCallProfile& profile) { | |||
118 | // Allows targeted inlining | |||
119 | if (C->directive()->should_inline(callee_method)) { | |||
120 | set_msg("force inline by CompileCommand"); | |||
121 | _forced_inline = true; | |||
122 | return true; | |||
123 | } | |||
124 | ||||
125 | if (callee_method->force_inline()) { | |||
126 | set_msg("force inline by annotation"); | |||
127 | _forced_inline = true; | |||
128 | return true; | |||
129 | } | |||
130 | ||||
131 | #ifndef PRODUCT | |||
132 | int inline_depth = inline_level() + 1; | |||
133 | if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth, should_delay)) { | |||
134 | if (should_delay) { | |||
135 | set_msg("force (incremental) inline by ciReplay"); | |||
136 | } else { | |||
137 | set_msg("force inline by ciReplay"); | |||
138 | } | |||
139 | _forced_inline = true; | |||
140 | return true; | |||
141 | } | |||
142 | #endif | |||
143 | ||||
144 | int size = callee_method->code_size_for_inlining(); | |||
145 | ||||
146 | // Check for too many throws (and not too huge) | |||
147 | if(callee_method->interpreter_throwout_count() > InlineThrowCount && | |||
148 | size < InlineThrowMaxSize ) { | |||
149 | if (C->print_inlining() && Verbose) { | |||
150 | CompileTask::print_inline_indent(inline_level()); | |||
151 | tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count()); | |||
152 | } | |||
153 | set_msg("many throws"); | |||
154 | return true; | |||
155 | } | |||
156 | ||||
157 | int default_max_inline_size = C->max_inline_size(); | |||
158 | int inline_small_code_size = InlineSmallCode / 4; | |||
159 | int max_inline_size = default_max_inline_size; | |||
160 | ||||
161 | int call_site_count = caller_method->scale_count(profile.count()); | |||
162 | int invoke_count = caller_method->interpreter_invocation_count(); | |||
163 | ||||
164 | assert(invoke_count != 0, "require invocation count greater than zero")do { if (!(invoke_count != 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 164, "assert(" "invoke_count != 0" ") failed", "require invocation count greater than zero" ); ::breakpoint(); } } while (0); | |||
165 | double freq = (double)call_site_count / (double)invoke_count; | |||
166 | ||||
167 | // bump the max size if the call is frequent | |||
168 | if ((freq >= InlineFrequencyRatio) || | |||
169 | is_unboxing_method(callee_method, C) || | |||
170 | is_init_with_ea(callee_method, caller_method, C)) { | |||
171 | ||||
172 | max_inline_size = C->freq_inline_size(); | |||
173 | if (size <= max_inline_size && TraceFrequencyInlining) { | |||
174 | CompileTask::print_inline_indent(inline_level()); | |||
175 | tty->print_cr("Inlined frequent method (freq=%lf):", freq); | |||
176 | CompileTask::print_inline_indent(inline_level()); | |||
177 | callee_method->print(); | |||
178 | tty->cr(); | |||
179 | } | |||
180 | } else { | |||
181 | // Not hot. Check for medium-sized pre-existing nmethod at cold sites. | |||
182 | if (callee_method->has_compiled_code() && | |||
183 | callee_method->instructions_size() > inline_small_code_size) { | |||
184 | set_msg("already compiled into a medium method"); | |||
185 | return false; | |||
186 | } | |||
187 | } | |||
188 | if (size > max_inline_size) { | |||
189 | if (max_inline_size > default_max_inline_size) { | |||
190 | set_msg("hot method too big"); | |||
191 | } else { | |||
192 | set_msg("too big"); | |||
193 | } | |||
194 | return false; | |||
195 | } | |||
196 | return true; | |||
197 | } | |||
198 | ||||
199 | ||||
200 | // negative filter: should callee NOT be inlined? | |||
201 | bool InlineTree::should_not_inline(ciMethod* callee_method, ciMethod* caller_method, | |||
202 | int caller_bci, NOT_PRODUCT_ARG(bool& should_delay)bool& should_delay, ciCallProfile& profile) { | |||
203 | const char* fail_msg = NULL__null; | |||
204 | ||||
205 | // First check all inlining restrictions which are required for correctness | |||
206 | if (callee_method->is_abstract()) { | |||
207 | fail_msg = "abstract method"; // // note: we allow ik->is_abstract() | |||
208 | } else if (!callee_method->holder()->is_initialized() && | |||
209 | // access allowed in the context of static initializer | |||
210 | C->needs_clinit_barrier(callee_method->holder(), caller_method)) { | |||
211 | fail_msg = "method holder not initialized"; | |||
212 | } else if (callee_method->is_native()) { | |||
213 | fail_msg = "native method"; | |||
214 | } else if (callee_method->dont_inline()) { | |||
215 | fail_msg = "don't inline by annotation"; | |||
216 | } | |||
217 | ||||
218 | // one more inlining restriction | |||
219 | if (fail_msg == NULL__null && callee_method->has_unloaded_classes_in_signature()) { | |||
220 | fail_msg = "unloaded signature classes"; | |||
221 | } | |||
222 | ||||
223 | if (fail_msg != NULL__null) { | |||
224 | set_msg(fail_msg); | |||
225 | return true; | |||
226 | } | |||
227 | ||||
228 | // ignore heuristic controls on inlining | |||
229 | if (C->directive()->should_inline(callee_method)) { | |||
230 | set_msg("force inline by CompileCommand"); | |||
231 | return false; | |||
232 | } | |||
233 | ||||
234 | if (C->directive()->should_not_inline(callee_method)) { | |||
235 | set_msg("disallowed by CompileCommand"); | |||
236 | return true; | |||
237 | } | |||
238 | ||||
239 | #ifndef PRODUCT | |||
240 | int inline_depth = inline_level() + 1; | |||
241 | if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth, should_delay)) { | |||
242 | if (should_delay) { | |||
243 | set_msg("force (incremental) inline by ciReplay"); | |||
244 | } else { | |||
245 | set_msg("force inline by ciReplay"); | |||
246 | } | |||
247 | return false; | |||
248 | } | |||
249 | ||||
250 | if (ciReplay::should_not_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) { | |||
251 | set_msg("disallowed by ciReplay"); | |||
252 | return true; | |||
253 | } | |||
254 | ||||
255 | if (ciReplay::should_not_inline(callee_method)) { | |||
256 | set_msg("disallowed by ciReplay"); | |||
257 | return true; | |||
258 | } | |||
259 | #endif | |||
260 | ||||
261 | if (callee_method->force_inline()) { | |||
262 | set_msg("force inline by annotation"); | |||
263 | return false; | |||
264 | } | |||
265 | ||||
266 | // Now perform checks which are heuristic | |||
267 | ||||
268 | if (is_unboxing_method(callee_method, C)) { | |||
269 | // Inline unboxing methods. | |||
270 | return false; | |||
271 | } | |||
272 | ||||
273 | if (callee_method->has_compiled_code() && | |||
274 | callee_method->instructions_size() > InlineSmallCode) { | |||
275 | set_msg("already compiled into a big method"); | |||
276 | return true; | |||
277 | } | |||
278 | ||||
279 | // don't inline exception code unless the top method belongs to an | |||
280 | // exception class | |||
281 | if (caller_tree() != NULL__null && | |||
282 | callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { | |||
283 | const InlineTree *top = this; | |||
284 | while (top->caller_tree() != NULL__null) top = top->caller_tree(); | |||
285 | ciInstanceKlass* k = top->method()->holder(); | |||
286 | if (!k->is_subclass_of(C->env()->Throwable_klass())) { | |||
287 | set_msg("exception method"); | |||
288 | return true; | |||
289 | } | |||
290 | } | |||
291 | ||||
292 | // use frequency-based objections only for non-trivial methods | |||
293 | if (callee_method->code_size() <= MaxTrivialSize) { | |||
294 | return false; | |||
295 | } | |||
296 | ||||
297 | // don't use counts with -Xcomp | |||
298 | if (UseInterpreter) { | |||
299 | if (!callee_method->has_compiled_code() && | |||
300 | !callee_method->was_executed_more_than(0)) { | |||
301 | set_msg("never executed"); | |||
302 | return true; | |||
303 | } | |||
304 | ||||
305 | if (is_init_with_ea(callee_method, caller_method, C)) { | |||
306 | // Escape Analysis: inline all executed constructors | |||
307 | return false; | |||
308 | } | |||
309 | ||||
310 | if (MinInlineFrequencyRatio > 0) { | |||
311 | int call_site_count = caller_method->scale_count(profile.count()); | |||
312 | int invoke_count = caller_method->interpreter_invocation_count(); | |||
313 | assert(invoke_count != 0, "require invocation count greater than zero")do { if (!(invoke_count != 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 313, "assert(" "invoke_count != 0" ") failed", "require invocation count greater than zero" ); ::breakpoint(); } } while (0); | |||
314 | double freq = (double)call_site_count / (double)invoke_count; | |||
315 | double min_freq = MAX2(MinInlineFrequencyRatio, 1.0 / CompilationPolicy::min_invocations()); | |||
316 | ||||
317 | if (freq < min_freq) { | |||
318 | set_msg("low call site frequency"); | |||
319 | return true; | |||
320 | } | |||
321 | } | |||
322 | ||||
323 | if (MinInliningThreshold > 0) { // Deprecated heuristic | |||
324 | intx counter_high_value = TieredCompilation ? InvocationCounter::count_limit / 2 : CompileThreshold / 2; | |||
325 | if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold, counter_high_value))) { | |||
326 | set_msg("executed < MinInliningThreshold times"); | |||
327 | return true; | |||
328 | } | |||
329 | } | |||
330 | } | |||
331 | ||||
332 | return false; | |||
333 | } | |||
334 | ||||
335 | bool InlineTree::is_not_reached(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile) { | |||
336 | if (!UseInterpreter) { | |||
337 | return false; // -Xcomp | |||
338 | } | |||
339 | if (profile.count() > 0) { | |||
340 | return false; // reachable according to profile | |||
341 | } | |||
342 | if (!callee_method->was_executed_more_than(0)) { | |||
343 | return true; // callee was never executed | |||
344 | } | |||
345 | if (caller_method->is_not_reached(caller_bci)) { | |||
346 | return true; // call site not resolved | |||
347 | } | |||
348 | if (profile.count() == -1) { | |||
349 | return false; // immature profile; optimistically treat as reached | |||
350 | } | |||
351 | assert(profile.count() == 0, "sanity")do { if (!(profile.count() == 0)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 351, "assert(" "profile.count() == 0" ") failed", "sanity") ; ::breakpoint(); } } while (0); | |||
352 | ||||
353 | // Profile info is scarce. | |||
354 | // Try to guess: check if the call site belongs to a start block. | |||
355 | // Call sites in a start block should be reachable if no exception is thrown earlier. | |||
356 | ciMethodBlocks* caller_blocks = caller_method->get_method_blocks(); | |||
357 | bool is_start_block = caller_blocks->block_containing(caller_bci)->start_bci() == 0; | |||
358 | if (is_start_block) { | |||
359 | return false; // treat the call reached as part of start block | |||
360 | } | |||
361 | return true; // give up and treat the call site as not reached | |||
362 | } | |||
363 | ||||
364 | //-----------------------------try_to_inline----------------------------------- | |||
365 | // return true if ok | |||
366 | // Relocated from "InliningClosure::try_to_inline" | |||
367 | bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, | |||
368 | int caller_bci, JVMState* jvms, ciCallProfile& profile, | |||
369 | bool& should_delay) { | |||
370 | ||||
371 | if (ClipInlining && (int)count_inline_bcs() >= DesiredMethodLimit) { | |||
372 | if (!callee_method->force_inline() || !IncrementalInline) { | |||
373 | set_msg("size > DesiredMethodLimit"); | |||
374 | return false; | |||
375 | } else if (!C->inlining_incrementally()) { | |||
376 | should_delay = true; | |||
377 | } | |||
378 | } | |||
379 | ||||
380 | _forced_inline = false; // Reset | |||
381 | ||||
382 | // 'should_delay' can be overridden during replay compilation | |||
383 | if (!should_inline(callee_method, caller_method, caller_bci, NOT_PRODUCT_ARG(should_delay)should_delay, profile)) { | |||
384 | return false; | |||
385 | } | |||
386 | // 'should_delay' can be overridden during replay compilation | |||
387 | if (should_not_inline(callee_method, caller_method, caller_bci, NOT_PRODUCT_ARG(should_delay)should_delay, profile)) { | |||
388 | return false; | |||
389 | } | |||
390 | ||||
391 | if (InlineAccessors && callee_method->is_accessor()) { | |||
392 | // accessor methods are not subject to any of the following limits. | |||
393 | set_msg("accessor"); | |||
394 | return true; | |||
395 | } | |||
396 | ||||
397 | // suppress a few checks for accessors and trivial methods | |||
398 | if (callee_method->code_size() > MaxTrivialSize) { | |||
399 | ||||
400 | // don't inline into giant methods | |||
401 | if (C->over_inlining_cutoff()) { | |||
402 | if ((!callee_method->force_inline() && !caller_method->is_compiled_lambda_form()) | |||
403 | || !IncrementalInline) { | |||
404 | set_msg("NodeCountInliningCutoff"); | |||
405 | return false; | |||
406 | } else { | |||
407 | should_delay = true; | |||
408 | } | |||
409 | } | |||
410 | ||||
411 | if (!UseInterpreter && | |||
412 | is_init_with_ea(callee_method, caller_method, C)) { | |||
413 | // Escape Analysis stress testing when running Xcomp: | |||
414 | // inline constructors even if they are not reached. | |||
415 | } else if (forced_inline()) { | |||
416 | // Inlining was forced by CompilerOracle, ciReplay or annotation | |||
417 | } else if (is_not_reached(callee_method, caller_method, caller_bci, profile)) { | |||
418 | // don't inline unreached call sites | |||
419 | set_msg("call site not reached"); | |||
420 | return false; | |||
421 | } | |||
422 | } | |||
423 | ||||
424 | if (!C->do_inlining() && InlineAccessors) { | |||
425 | set_msg("not an accessor"); | |||
426 | return false; | |||
427 | } | |||
428 | ||||
429 | // Limit inlining depth in case inlining is forced or | |||
430 | // _max_inline_level was increased to compensate for lambda forms. | |||
431 | if (inline_level() > MaxForceInlineLevel) { | |||
432 | set_msg("MaxForceInlineLevel"); | |||
433 | return false; | |||
434 | } | |||
435 | if (inline_level() > _max_inline_level) { | |||
436 | if (!callee_method->force_inline() || !IncrementalInline) { | |||
437 | set_msg("inlining too deep"); | |||
438 | return false; | |||
439 | } else if (!C->inlining_incrementally()) { | |||
440 | should_delay = true; | |||
441 | } | |||
442 | } | |||
443 | ||||
444 | // detect direct and indirect recursive inlining | |||
445 | { | |||
446 | // count the current method and the callee | |||
447 | const bool is_compiled_lambda_form = callee_method->is_compiled_lambda_form(); | |||
448 | int inline_level = 0; | |||
449 | if (!is_compiled_lambda_form) { | |||
450 | if (method() == callee_method) { | |||
451 | inline_level++; | |||
452 | } | |||
453 | } | |||
454 | // count callers of current method and callee | |||
455 | Node* callee_argument0 = is_compiled_lambda_form ? jvms->map()->argument(jvms, 0)->uncast() : NULL__null; | |||
456 | for (JVMState* j = jvms->caller(); j != NULL__null && j->has_method(); j = j->caller()) { | |||
457 | if (j->method() == callee_method) { | |||
458 | if (is_compiled_lambda_form) { | |||
459 | // Since compiled lambda forms are heavily reused we allow recursive inlining. If it is truly | |||
460 | // a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the | |||
461 | // compiler stack. | |||
462 | Node* caller_argument0 = j->map()->argument(j, 0)->uncast(); | |||
463 | if (caller_argument0 == callee_argument0) { | |||
464 | inline_level++; | |||
465 | } | |||
466 | } else { | |||
467 | inline_level++; | |||
468 | } | |||
469 | } | |||
470 | } | |||
471 | if (inline_level > MaxRecursiveInlineLevel) { | |||
472 | set_msg("recursive inlining is too deep"); | |||
473 | return false; | |||
474 | } | |||
475 | } | |||
476 | ||||
477 | int size = callee_method->code_size_for_inlining(); | |||
478 | ||||
479 | if (ClipInlining && (int)count_inline_bcs() + size >= DesiredMethodLimit) { | |||
480 | if (!callee_method->force_inline() || !IncrementalInline) { | |||
481 | set_msg("size > DesiredMethodLimit"); | |||
482 | return false; | |||
483 | } else if (!C->inlining_incrementally()) { | |||
484 | should_delay = true; | |||
485 | } | |||
486 | } | |||
487 | ||||
488 | // ok, inline this method | |||
489 | return true; | |||
490 | } | |||
491 | ||||
492 | //------------------------------pass_initial_checks---------------------------- | |||
493 | bool InlineTree::pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) { | |||
494 | // Check if a callee_method was suggested | |||
495 | if (callee_method == NULL__null) { | |||
496 | return false; | |||
497 | } | |||
498 | ciInstanceKlass *callee_holder = callee_method->holder(); | |||
499 | // Check if klass of callee_method is loaded | |||
500 | if (!callee_holder->is_loaded()) { | |||
501 | return false; | |||
502 | } | |||
503 | if (!callee_holder->is_initialized() && | |||
504 | // access allowed in the context of static initializer | |||
505 | C->needs_clinit_barrier(callee_holder, caller_method)) { | |||
506 | return false; | |||
507 | } | |||
508 | if( !UseInterpreter ) /* running Xcomp */ { | |||
509 | // Checks that constant pool's call site has been visited | |||
510 | // stricter than callee_holder->is_initialized() | |||
511 | ciBytecodeStream iter(caller_method); | |||
512 | iter.force_bci(caller_bci); | |||
513 | Bytecodes::Code call_bc = iter.cur_bc(); | |||
514 | // An invokedynamic instruction does not have a klass. | |||
515 | if (call_bc != Bytecodes::_invokedynamic) { | |||
516 | int index = iter.get_index_u2_cpcache(); | |||
517 | if (!caller_method->is_klass_loaded(index, true)) { | |||
518 | return false; | |||
519 | } | |||
520 | // Try to do constant pool resolution if running Xcomp | |||
521 | if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) { | |||
522 | return false; | |||
523 | } | |||
524 | } | |||
525 | } | |||
526 | return true; | |||
527 | } | |||
528 | ||||
529 | //------------------------------check_can_parse-------------------------------- | |||
530 | const char* InlineTree::check_can_parse(ciMethod* callee) { | |||
531 | // Certain methods cannot be parsed at all: | |||
532 | if ( callee->is_native()) return "native method"; | |||
533 | if ( callee->is_abstract()) return "abstract method"; | |||
534 | if (!callee->has_balanced_monitors()) return "not compilable (unbalanced monitors)"; | |||
535 | if ( callee->get_flow_analysis()->failing()) return "not compilable (flow analysis failed)"; | |||
536 | if (!callee->can_be_parsed()) return "cannot be parsed"; | |||
537 | return NULL__null; | |||
538 | } | |||
539 | ||||
540 | //------------------------------print_inlining--------------------------------- | |||
541 | void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci, | |||
542 | ciMethod* caller_method, bool success) const { | |||
543 | const char* inline_msg = msg(); | |||
544 | assert(inline_msg != NULL, "just checking")do { if (!(inline_msg != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 544, "assert(" "inline_msg != __null" ") failed", "just checking" ); ::breakpoint(); } } while (0); | |||
545 | if (C->log() != NULL__null) { | |||
546 | if (success) { | |||
547 | C->log()->inline_success(inline_msg); | |||
548 | } else { | |||
549 | C->log()->inline_fail(inline_msg); | |||
550 | } | |||
551 | } | |||
552 | CompileTask::print_inlining_ul(callee_method, inline_level(), | |||
553 | caller_bci, inline_msg); | |||
554 | if (C->print_inlining()) { | |||
555 | C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg); | |||
556 | guarantee(callee_method != NULL, "would crash in CompilerEvent::InlineEvent::post")do { if (!(callee_method != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 556, "guarantee(" "callee_method != NULL" ") failed", "would crash in CompilerEvent::InlineEvent::post" ); ::breakpoint(); } } while (0); | |||
557 | if (Verbose) { | |||
558 | const InlineTree *top = this; | |||
559 | while (top->caller_tree() != NULL__null) { top = top->caller_tree(); } | |||
560 | //tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count()); | |||
561 | } | |||
562 | } | |||
563 | EventCompilerInlining event; | |||
564 | if (event.should_commit()) { | |||
565 | CompilerEvent::InlineEvent::post(event, C->compile_id(), caller_method->get_Method(), callee_method, success, inline_msg, caller_bci); | |||
566 | } | |||
567 | } | |||
568 | ||||
569 | //------------------------------ok_to_inline----------------------------------- | |||
570 | bool InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, | |||
571 | bool& should_delay) { | |||
572 | #ifdef ASSERT1 | |||
573 | assert(callee_method != NULL, "caller checks for optimized virtual!")do { if (!(callee_method != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 573, "assert(" "callee_method != __null" ") failed", "caller checks for optimized virtual!" ); ::breakpoint(); } } while (0); | |||
574 | // Make sure the incoming jvms has the same information content as me. | |||
575 | // This means that we can eventually make this whole class AllStatic. | |||
576 | if (jvms->caller() == NULL__null) { | |||
577 | assert(_caller_jvms == NULL, "redundant instance state")do { if (!(_caller_jvms == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 577, "assert(" "_caller_jvms == __null" ") failed", "redundant instance state" ); ::breakpoint(); } } while (0); | |||
578 | } else { | |||
579 | assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state")do { if (!(_caller_jvms->same_calls_as(jvms->caller())) ) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 579, "assert(" "_caller_jvms->same_calls_as(jvms->caller())" ") failed", "redundant instance state"); ::breakpoint(); } } while (0); | |||
580 | } | |||
581 | assert(_method == jvms->method(), "redundant instance state")do { if (!(_method == jvms->method())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 581, "assert(" "_method == jvms->method()" ") failed", "redundant instance state" ); ::breakpoint(); } } while (0); | |||
582 | #endif | |||
583 | int caller_bci = jvms->bci(); | |||
584 | ciMethod* caller_method = jvms->method(); | |||
585 | ||||
586 | // Do some initial checks. | |||
587 | if (!pass_initial_checks(caller_method, caller_bci, callee_method)) { | |||
588 | set_msg("failed initial checks"); | |||
589 | print_inlining(callee_method, caller_bci, caller_method, false /* !success */); | |||
590 | return false; | |||
591 | } | |||
592 | ||||
593 | // Do some parse checks. | |||
594 | set_msg(check_can_parse(callee_method)); | |||
595 | if (msg() != NULL__null) { | |||
596 | print_inlining(callee_method, caller_bci, caller_method, false /* !success */); | |||
597 | return false; | |||
598 | } | |||
599 | ||||
600 | // Check if inlining policy says no. | |||
601 | bool success = try_to_inline(callee_method, caller_method, caller_bci, jvms, profile, | |||
602 | should_delay); // out | |||
603 | if (success) { | |||
604 | // Inline! | |||
605 | if (msg() == NULL__null) { | |||
606 | set_msg("inline (hot)"); | |||
607 | } | |||
608 | print_inlining(callee_method, caller_bci, caller_method, true /* success */); | |||
609 | InlineTree* callee_tree = build_inline_tree_for_callee(callee_method, jvms, caller_bci); | |||
610 | if (should_delay) { | |||
611 | // Record late inlining decision in order to dump it for compiler replay | |||
612 | callee_tree->set_late_inline(); | |||
613 | } | |||
614 | return true; | |||
615 | } else { | |||
616 | // Do not inline | |||
617 | if (msg() == NULL__null) { | |||
618 | set_msg("too cold to inline"); | |||
619 | } | |||
620 | print_inlining(callee_method, caller_bci, caller_method, false /* !success */ ); | |||
621 | return false; | |||
622 | } | |||
623 | } | |||
624 | ||||
625 | //------------------------------build_inline_tree_for_callee------------------- | |||
626 | InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) { | |||
627 | // Attempt inlining. | |||
628 | InlineTree* old_ilt = callee_at(caller_bci, callee_method); | |||
629 | if (old_ilt
| |||
630 | return old_ilt; | |||
631 | } | |||
632 | int max_inline_level_adjust = 0; | |||
633 | if (caller_jvms->method() != NULL__null) { | |||
634 | if (caller_jvms->method()->is_compiled_lambda_form()) { | |||
635 | max_inline_level_adjust += 1; // don't count actions in MH or indy adapter frames | |||
636 | } else if (callee_method->is_method_handle_intrinsic() || | |||
637 | callee_method->is_compiled_lambda_form()) { | |||
638 | max_inline_level_adjust += 1; // don't count method handle calls from java.lang.invoke implementation | |||
639 | } | |||
640 | if (max_inline_level_adjust
| |||
641 | CompileTask::print_inline_indent(inline_level()); | |||
642 | tty->print_cr(" \\-> discounting inline depth"); | |||
643 | } | |||
644 | if (max_inline_level_adjust
| |||
645 | int id1 = C->log()->identify(caller_jvms->method()); | |||
646 | int id2 = C->log()->identify(callee_method); | |||
647 | C->log()->elem("inline_level_discount caller='%d' callee='%d'", id1, id2); | |||
648 | } | |||
649 | } | |||
650 | // Allocate in the comp_arena to make sure the InlineTree is live when dumping a replay compilation file | |||
651 | InlineTree* ilt = new (C->comp_arena()) InlineTree(C, this, callee_method, caller_jvms, caller_bci, _max_inline_level + max_inline_level_adjust); | |||
652 | _subtrees.append(ilt); | |||
653 | ||||
654 | NOT_PRODUCT( _count_inlines += 1; )_count_inlines += 1; | |||
655 | ||||
656 | return ilt; | |||
657 | } | |||
658 | ||||
659 | ||||
660 | //---------------------------------------callee_at----------------------------- | |||
661 | InlineTree *InlineTree::callee_at(int bci, ciMethod* callee) const { | |||
662 | for (int i = 0; i < _subtrees.length(); i++) { | |||
663 | InlineTree* sub = _subtrees.at(i); | |||
664 | if (sub->caller_bci() == bci && callee == sub->method()) { | |||
665 | return sub; | |||
666 | } | |||
667 | } | |||
668 | return NULL__null; | |||
669 | } | |||
670 | ||||
671 | ||||
672 | //------------------------------build_inline_tree_root------------------------- | |||
673 | InlineTree *InlineTree::build_inline_tree_root() { | |||
674 | Compile* C = Compile::current(); | |||
675 | ||||
676 | // Root of inline tree | |||
677 | InlineTree* ilt = new InlineTree(C, NULL__null, C->method(), NULL__null, -1, MaxInlineLevel); | |||
678 | ||||
679 | return ilt; | |||
680 | } | |||
681 | ||||
682 | ||||
683 | //-------------------------find_subtree_from_root----------------------------- | |||
684 | // Given a jvms, which determines a call chain from the root method, | |||
685 | // find the corresponding inline tree. | |||
686 | // Note: This method will be removed or replaced as InlineTree goes away. | |||
687 | InlineTree* InlineTree::find_subtree_from_root(InlineTree* root, JVMState* jvms, ciMethod* callee) { | |||
688 | InlineTree* iltp = root; | |||
689 | uint depth = jvms && jvms->has_method() ? jvms->depth() : 0; | |||
| ||||
690 | for (uint d = 1; d <= depth; d++) { | |||
691 | JVMState* jvmsp = jvms->of_depth(d); | |||
692 | // Select the corresponding subtree for this bci. | |||
693 | assert(jvmsp->method() == iltp->method(), "tree still in sync")do { if (!(jvmsp->method() == iltp->method())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 693, "assert(" "jvmsp->method() == iltp->method()" ") failed" , "tree still in sync"); ::breakpoint(); } } while (0); | |||
694 | ciMethod* d_callee = (d == depth) ? callee : jvms->of_depth(d+1)->method(); | |||
695 | InlineTree* sub = iltp->callee_at(jvmsp->bci(), d_callee); | |||
696 | if (sub
| |||
697 | if (d
| |||
698 | sub = iltp->build_inline_tree_for_callee(d_callee, jvmsp, jvmsp->bci()); | |||
699 | } | |||
700 | guarantee(sub != NULL, "should be a sub-ilt here")do { if (!(sub != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/bytecodeInfo.cpp" , 700, "guarantee(" "sub != NULL" ") failed", "should be a sub-ilt here" ); ::breakpoint(); } } while (0); | |||
701 | return sub; | |||
702 | } | |||
703 | iltp = sub; | |||
704 | } | |||
705 | return iltp; | |||
706 | } | |||
707 | ||||
708 | // Count number of nodes in this subtree | |||
709 | int InlineTree::count() const { | |||
710 | int result = 1; | |||
711 | for (int i = 0 ; i < _subtrees.length(); i++) { | |||
712 | result += _subtrees.at(i)->count(); | |||
713 | } | |||
714 | return result; | |||
715 | } | |||
716 | ||||
717 | void InlineTree::dump_replay_data(outputStream* out) { | |||
718 | out->print(" %d %d %d ", inline_level(), caller_bci(), _late_inline); | |||
719 | method()->dump_name_as_ascii(out); | |||
720 | for (int i = 0 ; i < _subtrees.length(); i++) { | |||
721 | _subtrees.at(i)->dump_replay_data(out); | |||
722 | } | |||
723 | } | |||
724 | ||||
725 | ||||
726 | #ifndef PRODUCT | |||
727 | void InlineTree::print_impl(outputStream* st, int indent) const { | |||
728 | for (int i = 0; i < indent; i++) st->print(" "); | |||
729 | st->print(" @ %d", caller_bci()); | |||
730 | method()->print_short_name(st); | |||
731 | st->cr(); | |||
732 | ||||
733 | for (int i = 0 ; i < _subtrees.length(); i++) { | |||
734 | _subtrees.at(i)->print_impl(st, indent + 2); | |||
735 | } | |||
736 | } | |||
737 | ||||
738 | void InlineTree::print_value_on(outputStream* st) const { | |||
739 | print_impl(st, 2); | |||
740 | } | |||
741 | #endif |