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 "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "compiler/compileLog.hpp"
29 #include "interpreter/linkResolver.hpp"
30 #include "oops/objArrayKlass.hpp"
31 #include "opto/callGenerator.hpp"
32 #include "opto/parse.hpp"
33 #include "runtime/handles.inline.hpp"
34
35 //=============================================================================
36 //------------------------------InlineTree-------------------------------------
37 InlineTree::InlineTree( Compile* c,
38 const InlineTree *caller_tree, ciMethod* callee,
39 JVMState* caller_jvms, int caller_bci,
40 float site_invoke_ratio, int site_depth_adjust)
41 : C(c), _caller_jvms(caller_jvms),
42 _caller_tree((InlineTree*)caller_tree),
43 _method(callee), _site_invoke_ratio(site_invoke_ratio),
44 _site_depth_adjust(site_depth_adjust),
45 _count_inline_bcs(method()->code_size())
46 {
47 NOT_PRODUCT(_count_inlines = 0;)
58 // Update hierarchical counts, count_inline_bcs() and count_inlines()
59 InlineTree *caller = (InlineTree *)caller_tree;
60 for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) {
61 caller->_count_inline_bcs += count_inline_bcs();
62 NOT_PRODUCT(caller->_count_inlines++;)
63 }
64 }
65 }
66
67 InlineTree::InlineTree(Compile* c, ciMethod* callee_method, JVMState* caller_jvms,
68 float site_invoke_ratio, int site_depth_adjust)
69 : C(c), _caller_jvms(caller_jvms), _caller_tree(NULL),
70 _method(callee_method), _site_invoke_ratio(site_invoke_ratio),
71 _site_depth_adjust(site_depth_adjust),
72 _count_inline_bcs(method()->code_size())
73 {
74 NOT_PRODUCT(_count_inlines = 0;)
75 assert(!UseOldInlining, "do not use for old stuff");
76 }
77
78
79
80 static void print_indent(int depth) {
81 tty->print(" ");
82 for (int i = depth; i != 0; --i) tty->print(" ");
83 }
84
85 static bool is_init_with_ea(ciMethod* callee_method,
86 ciMethod* caller_method, Compile* C) {
87 // True when EA is ON and a java constructor is called or
88 // a super constructor is called from an inlined java constructor.
89 return C->do_escape_analysis() && EliminateAllocations &&
90 ( callee_method->is_initializer() ||
91 (caller_method->is_initializer() &&
92 caller_method != C->method() &&
93 caller_method->holder()->is_subclass_of(callee_method->holder()))
94 );
95 }
96
97 // positive filter: should send be inlined? returns NULL, if yes, or rejection msg
98 const char* InlineTree::shouldInline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result) const {
99 // Allows targeted inlining
100 if(callee_method->should_inline()) {
101 *wci_result = *(WarmCallInfo::always_hot());
102 if (PrintInlining && Verbose) {
103 print_indent(inline_depth());
104 tty->print_cr("Inlined method is hot: ");
105 }
106 return NULL;
107 }
108
109 // positive filter: should send be inlined? returns NULL (--> yes)
110 // or rejection msg
111 int max_size = C->max_inline_size();
112 int size = callee_method->code_size();
113
114 // Check for too many throws (and not too huge)
115 if(callee_method->interpreter_throwout_count() > InlineThrowCount &&
116 size < InlineThrowMaxSize ) {
117 wci_result->set_profit(wci_result->profit() * 100);
118 if (PrintInlining && Verbose) {
119 print_indent(inline_depth());
120 tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
121 }
122 return NULL;
123 }
124
125 if (!UseOldInlining) {
126 return NULL; // size and frequency are represented in a new way
127 }
128
129 int call_site_count = method()->scale_count(profile.count());
130 int invoke_count = method()->interpreter_invocation_count();
131 assert( invoke_count != 0, "Require invokation count greater than zero");
132 int freq = call_site_count/invoke_count;
133
134 // bump the max size if the call is frequent
135 if ((freq >= InlineFrequencyRatio) ||
136 (call_site_count >= InlineFrequencyCount) ||
137 is_init_with_ea(callee_method, caller_method, C)) {
138
139 max_size = C->freq_inline_size();
140 if (size <= max_size && TraceFrequencyInlining) {
141 print_indent(inline_depth());
142 tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count);
143 print_indent(inline_depth());
144 callee_method->print();
145 tty->cr();
146 }
147 } else {
148 // Not hot. Check for medium-sized pre-existing nmethod at cold sites.
149 if (callee_method->has_compiled_code() &&
150 callee_method->instructions_size(CompLevel_full_optimization) > InlineSmallCode/4)
151 return "already compiled into a medium method";
152 }
153 if (size > max_size) {
154 if (max_size > C->max_inline_size())
155 return "hot method too big";
156 return "too big";
157 }
158 return NULL;
159 }
160
161
162 // negative filter: should send NOT be inlined? returns NULL, ok to inline, or rejection msg
163 const char* InlineTree::shouldNotInline(ciMethod *callee_method, ciMethod* caller_method, WarmCallInfo* wci_result) const {
298 }
299
300 if ((!UseInterpreter || CompileTheWorld) &&
301 is_init_with_ea(callee_method, caller_method, C)) {
302
303 // Escape Analysis stress testing when running Xcomp or CTW:
304 // inline constructors even if they are not reached.
305
306 } else if (profile.count() == 0) {
307 // don't inline unreached call sites
308 return "call site not reached";
309 }
310 }
311
312 if (!C->do_inlining() && InlineAccessors) {
313 return "not an accessor";
314 }
315 if( inline_depth() > MaxInlineLevel ) {
316 return "inlining too deep";
317 }
318 if( method() == callee_method &&
319 inline_depth() > MaxRecursiveInlineLevel ) {
320 return "recursively inlining too deep";
321 }
322
323 int size = callee_method->code_size();
324
325 if (UseOldInlining && ClipInlining
326 && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
327 return "size > DesiredMethodLimit";
328 }
329
330 // ok, inline this method
331 return NULL;
332 }
333
334 //------------------------------pass_initial_checks----------------------------
335 bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) {
336 ciInstanceKlass *callee_holder = callee_method ? callee_method->holder() : NULL;
337 // Check if a callee_method was suggested
338 if( callee_method == NULL ) return false;
339 // Check if klass of callee_method is loaded
351 if (!caller_method->is_klass_loaded(index, true)) {
352 return false;
353 }
354 // Try to do constant pool resolution if running Xcomp
355 if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) {
356 return false;
357 }
358 }
359 }
360 // We will attempt to see if a class/field/etc got properly loaded. If it
361 // did not, it may attempt to throw an exception during our probing. Catch
362 // and ignore such exceptions and do not attempt to compile the method.
363 if( callee_method->should_exclude() ) return false;
364
365 return true;
366 }
367
368 #ifndef PRODUCT
369 //------------------------------print_inlining---------------------------------
370 // Really, the failure_msg can be a success message also.
371 void InlineTree::print_inlining(ciMethod *callee_method, int caller_bci, const char *failure_msg) const {
372 print_indent(inline_depth());
373 tty->print("@ %d ", caller_bci);
374 if( callee_method ) callee_method->print_short_name();
375 else tty->print(" callee not monotonic or profiled");
376 tty->print(" %s", (failure_msg ? failure_msg : "inline"));
377 if( Verbose && callee_method ) {
378 const InlineTree *top = this;
379 while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
380 tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
381 }
382 tty->cr();
383 }
384 #endif
385
386 //------------------------------ok_to_inline-----------------------------------
387 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci) {
388 assert(callee_method != NULL, "caller checks for optimized virtual!");
389 #ifdef ASSERT
390 // Make sure the incoming jvms has the same information content as me.
391 // This means that we can eventually make this whole class AllStatic.
392 if (jvms->caller() == NULL) {
393 assert(_caller_jvms == NULL, "redundant instance state");
394 } else {
395 assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
396 }
397 assert(_method == jvms->method(), "redundant instance state");
398 #endif
399 const char *failure_msg = NULL;
400 int caller_bci = jvms->bci();
401 ciMethod *caller_method = jvms->method();
402
|
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 "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "compiler/compileBroker.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "interpreter/linkResolver.hpp"
31 #include "oops/objArrayKlass.hpp"
32 #include "opto/callGenerator.hpp"
33 #include "opto/parse.hpp"
34 #include "runtime/handles.inline.hpp"
35
36 //=============================================================================
37 //------------------------------InlineTree-------------------------------------
38 InlineTree::InlineTree( Compile* c,
39 const InlineTree *caller_tree, ciMethod* callee,
40 JVMState* caller_jvms, int caller_bci,
41 float site_invoke_ratio, int site_depth_adjust)
42 : C(c), _caller_jvms(caller_jvms),
43 _caller_tree((InlineTree*)caller_tree),
44 _method(callee), _site_invoke_ratio(site_invoke_ratio),
45 _site_depth_adjust(site_depth_adjust),
46 _count_inline_bcs(method()->code_size())
47 {
48 NOT_PRODUCT(_count_inlines = 0;)
59 // Update hierarchical counts, count_inline_bcs() and count_inlines()
60 InlineTree *caller = (InlineTree *)caller_tree;
61 for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) {
62 caller->_count_inline_bcs += count_inline_bcs();
63 NOT_PRODUCT(caller->_count_inlines++;)
64 }
65 }
66 }
67
68 InlineTree::InlineTree(Compile* c, ciMethod* callee_method, JVMState* caller_jvms,
69 float site_invoke_ratio, int site_depth_adjust)
70 : C(c), _caller_jvms(caller_jvms), _caller_tree(NULL),
71 _method(callee_method), _site_invoke_ratio(site_invoke_ratio),
72 _site_depth_adjust(site_depth_adjust),
73 _count_inline_bcs(method()->code_size())
74 {
75 NOT_PRODUCT(_count_inlines = 0;)
76 assert(!UseOldInlining, "do not use for old stuff");
77 }
78
79 static bool is_init_with_ea(ciMethod* callee_method,
80 ciMethod* caller_method, Compile* C) {
81 // True when EA is ON and a java constructor is called or
82 // a super constructor is called from an inlined java constructor.
83 return C->do_escape_analysis() && EliminateAllocations &&
84 ( callee_method->is_initializer() ||
85 (caller_method->is_initializer() &&
86 caller_method != C->method() &&
87 caller_method->holder()->is_subclass_of(callee_method->holder()))
88 );
89 }
90
91 // positive filter: should send be inlined? returns NULL, if yes, or rejection msg
92 const char* InlineTree::shouldInline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result) const {
93 // Allows targeted inlining
94 if(callee_method->should_inline()) {
95 *wci_result = *(WarmCallInfo::always_hot());
96 if (PrintInlining && Verbose) {
97 CompileTask::print_inline_indent(inline_depth());
98 tty->print_cr("Inlined method is hot: ");
99 }
100 return NULL;
101 }
102
103 // positive filter: should send be inlined? returns NULL (--> yes)
104 // or rejection msg
105 int max_size = C->max_inline_size();
106 int size = callee_method->code_size();
107
108 // Check for too many throws (and not too huge)
109 if(callee_method->interpreter_throwout_count() > InlineThrowCount &&
110 size < InlineThrowMaxSize ) {
111 wci_result->set_profit(wci_result->profit() * 100);
112 if (PrintInlining && Verbose) {
113 CompileTask::print_inline_indent(inline_depth());
114 tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count());
115 }
116 return NULL;
117 }
118
119 if (!UseOldInlining) {
120 return NULL; // size and frequency are represented in a new way
121 }
122
123 int call_site_count = method()->scale_count(profile.count());
124 int invoke_count = method()->interpreter_invocation_count();
125 assert( invoke_count != 0, "Require invokation count greater than zero");
126 int freq = call_site_count/invoke_count;
127
128 // bump the max size if the call is frequent
129 if ((freq >= InlineFrequencyRatio) ||
130 (call_site_count >= InlineFrequencyCount) ||
131 is_init_with_ea(callee_method, caller_method, C)) {
132
133 max_size = C->freq_inline_size();
134 if (size <= max_size && TraceFrequencyInlining) {
135 CompileTask::print_inline_indent(inline_depth());
136 tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count);
137 CompileTask::print_inline_indent(inline_depth());
138 callee_method->print();
139 tty->cr();
140 }
141 } else {
142 // Not hot. Check for medium-sized pre-existing nmethod at cold sites.
143 if (callee_method->has_compiled_code() &&
144 callee_method->instructions_size(CompLevel_full_optimization) > InlineSmallCode/4)
145 return "already compiled into a medium method";
146 }
147 if (size > max_size) {
148 if (max_size > C->max_inline_size())
149 return "hot method too big";
150 return "too big";
151 }
152 return NULL;
153 }
154
155
156 // negative filter: should send NOT be inlined? returns NULL, ok to inline, or rejection msg
157 const char* InlineTree::shouldNotInline(ciMethod *callee_method, ciMethod* caller_method, WarmCallInfo* wci_result) const {
292 }
293
294 if ((!UseInterpreter || CompileTheWorld) &&
295 is_init_with_ea(callee_method, caller_method, C)) {
296
297 // Escape Analysis stress testing when running Xcomp or CTW:
298 // inline constructors even if they are not reached.
299
300 } else if (profile.count() == 0) {
301 // don't inline unreached call sites
302 return "call site not reached";
303 }
304 }
305
306 if (!C->do_inlining() && InlineAccessors) {
307 return "not an accessor";
308 }
309 if( inline_depth() > MaxInlineLevel ) {
310 return "inlining too deep";
311 }
312
313 // We need to detect recursive inlining of method handle targets: if
314 // the current method is a method handle adapter and one of the
315 // callers is the same method as the callee, we bail out if
316 // MaxRecursiveInlineLevel is hit.
317 if (method()->is_method_handle_adapter()) {
318 JVMState* jvms = caller_jvms();
319 int inline_level = 0;
320 while (jvms != NULL && jvms->has_method()) {
321 if (jvms->method() == callee_method) {
322 inline_level++;
323 if (inline_level > MaxRecursiveInlineLevel)
324 return "recursively inlining too deep";
325 }
326 jvms = jvms->caller();
327 }
328 }
329
330 if (method() == callee_method && inline_depth() > MaxRecursiveInlineLevel) {
331 return "recursively inlining too deep";
332 }
333
334 int size = callee_method->code_size();
335
336 if (UseOldInlining && ClipInlining
337 && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
338 return "size > DesiredMethodLimit";
339 }
340
341 // ok, inline this method
342 return NULL;
343 }
344
345 //------------------------------pass_initial_checks----------------------------
346 bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) {
347 ciInstanceKlass *callee_holder = callee_method ? callee_method->holder() : NULL;
348 // Check if a callee_method was suggested
349 if( callee_method == NULL ) return false;
350 // Check if klass of callee_method is loaded
362 if (!caller_method->is_klass_loaded(index, true)) {
363 return false;
364 }
365 // Try to do constant pool resolution if running Xcomp
366 if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) {
367 return false;
368 }
369 }
370 }
371 // We will attempt to see if a class/field/etc got properly loaded. If it
372 // did not, it may attempt to throw an exception during our probing. Catch
373 // and ignore such exceptions and do not attempt to compile the method.
374 if( callee_method->should_exclude() ) return false;
375
376 return true;
377 }
378
379 #ifndef PRODUCT
380 //------------------------------print_inlining---------------------------------
381 // Really, the failure_msg can be a success message also.
382 void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci, const char* failure_msg) const {
383 CompileTask::print_inlining(callee_method, inline_depth(), caller_bci, failure_msg ? failure_msg : "inline");
384 if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
385 if (Verbose && callee_method) {
386 const InlineTree *top = this;
387 while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
388 tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
389 }
390 }
391 #endif
392
393 //------------------------------ok_to_inline-----------------------------------
394 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci) {
395 assert(callee_method != NULL, "caller checks for optimized virtual!");
396 #ifdef ASSERT
397 // Make sure the incoming jvms has the same information content as me.
398 // This means that we can eventually make this whole class AllStatic.
399 if (jvms->caller() == NULL) {
400 assert(_caller_jvms == NULL, "redundant instance state");
401 } else {
402 assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
403 }
404 assert(_method == jvms->method(), "redundant instance state");
405 #endif
406 const char *failure_msg = NULL;
407 int caller_bci = jvms->bci();
408 ciMethod *caller_method = jvms->method();
409
|