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/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "oops/objArrayKlass.hpp"
33 #include "opto/callGenerator.hpp"
34 #include "opto/parse.hpp"
35 #include "runtime/handles.inline.hpp"
36
37 //=============================================================================
38 //------------------------------InlineTree-------------------------------------
39 InlineTree::InlineTree(Compile* c,
40 const InlineTree *caller_tree, ciMethod* callee,
41 JVMState* caller_jvms, int caller_bci,
42 float site_invoke_ratio, int max_inline_level) :
43 C(c),
44 _caller_jvms(caller_jvms),
45 _caller_tree((InlineTree*) caller_tree),
46 _method(callee),
47 _site_invoke_ratio(site_invoke_ratio),
48 _max_inline_level(max_inline_level),
49 _count_inline_bcs(method()->code_size_for_inlining()),
50 _subtrees(c->comp_arena(), 2, 0, NULL),
51 _msg(NULL)
462 }
463 // We will attempt to see if a class/field/etc got properly loaded. If it
464 // did not, it may attempt to throw an exception during our probing. Catch
465 // and ignore such exceptions and do not attempt to compile the method.
466 if( callee_method->should_exclude() ) return false;
467
468 return true;
469 }
470
471 //------------------------------check_can_parse--------------------------------
472 const char* InlineTree::check_can_parse(ciMethod* callee) {
473 // Certain methods cannot be parsed at all:
474 if ( callee->is_native()) return "native method";
475 if ( callee->is_abstract()) return "abstract method";
476 if (!callee->can_be_compiled()) return "not compilable (disabled)";
477 if (!callee->has_balanced_monitors()) return "not compilable (unbalanced monitors)";
478 if ( callee->get_flow_analysis()->failing()) return "not compilable (flow analysis failed)";
479 return NULL;
480 }
481
482 //------------------------------print_inlining---------------------------------
483 void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci,
484 bool success) const {
485 const char* inline_msg = msg();
486 assert(inline_msg != NULL, "just checking");
487 if (C->log() != NULL) {
488 if (success) {
489 C->log()->inline_success(inline_msg);
490 } else {
491 C->log()->inline_fail(inline_msg);
492 }
493 }
494 if (C->print_inlining()) {
495 C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
496 if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
497 if (Verbose && callee_method) {
498 const InlineTree *top = this;
499 while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
500 //tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
501 }
502 }
503 }
504
505 //------------------------------ok_to_inline-----------------------------------
506 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci, bool& should_delay) {
507 assert(callee_method != NULL, "caller checks for optimized virtual!");
508 assert(!should_delay, "should be initialized to false");
509 #ifdef ASSERT
510 // Make sure the incoming jvms has the same information content as me.
511 // This means that we can eventually make this whole class AllStatic.
512 if (jvms->caller() == NULL) {
513 assert(_caller_jvms == NULL, "redundant instance state");
514 } else {
515 assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
516 }
517 assert(_method == jvms->method(), "redundant instance state");
518 #endif
519 int caller_bci = jvms->bci();
520 ciMethod* caller_method = jvms->method();
521
522 // Do some initial checks.
523 if (!pass_initial_checks(caller_method, caller_bci, callee_method)) {
524 set_msg("failed initial checks");
525 print_inlining(callee_method, caller_bci, false /* !success */);
526 return NULL;
527 }
528
529 // Do some parse checks.
530 set_msg(check_can_parse(callee_method));
531 if (msg() != NULL) {
532 print_inlining(callee_method, caller_bci, false /* !success */);
533 return NULL;
534 }
535
536 // Check if inlining policy says no.
537 WarmCallInfo wci = *(initial_wci);
538 bool success = try_to_inline(callee_method, caller_method, caller_bci,
539 jvms, profile, &wci, should_delay);
540
541 #ifndef PRODUCT
542 if (InlineWarmCalls && (PrintOpto || C->print_inlining())) {
543 bool cold = wci.is_cold();
544 bool hot = !cold && wci.is_hot();
545 bool old_cold = !success;
546 if (old_cold != cold || (Verbose || WizardMode)) {
547 if (msg() == NULL) {
548 set_msg("OK");
549 }
550 tty->print(" OldInlining= %4s : %s\n WCI=",
551 old_cold ? "cold" : "hot", msg());
552 wci.print();
554 }
555 #endif
556 if (success) {
557 wci = *(WarmCallInfo::always_hot());
558 } else {
559 wci = *(WarmCallInfo::always_cold());
560 }
561
562 if (!InlineWarmCalls) {
563 if (!wci.is_cold() && !wci.is_hot()) {
564 // Do not inline the warm calls.
565 wci = *(WarmCallInfo::always_cold());
566 }
567 }
568
569 if (!wci.is_cold()) {
570 // Inline!
571 if (msg() == NULL) {
572 set_msg("inline (hot)");
573 }
574 print_inlining(callee_method, caller_bci, true /* success */);
575 build_inline_tree_for_callee(callee_method, jvms, caller_bci);
576 if (InlineWarmCalls && !wci.is_hot())
577 return new (C) WarmCallInfo(wci); // copy to heap
578 return WarmCallInfo::always_hot();
579 }
580
581 // Do not inline
582 if (msg() == NULL) {
583 set_msg("too cold to inline");
584 }
585 print_inlining(callee_method, caller_bci, false /* !success */ );
586 return NULL;
587 }
588
589 //------------------------------compute_callee_frequency-----------------------
590 float InlineTree::compute_callee_frequency( int caller_bci ) const {
591 int count = method()->interpreter_call_site_count(caller_bci);
592 int invcnt = method()->interpreter_invocation_count();
593 float freq = (float)count/(float)invcnt;
594 // Call-site count / interpreter invocation count, scaled recursively.
595 // Always between 0.0 and 1.0. Represents the percentage of the method's
596 // total execution time used at this call site.
597
598 return freq;
599 }
600
601 //------------------------------build_inline_tree_for_callee-------------------
602 InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) {
603 float recur_frequency = _site_invoke_ratio * compute_callee_frequency(caller_bci);
604 // Attempt inlining.
605 InlineTree* old_ilt = callee_at(caller_bci, callee_method);
|
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/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "jfr/jfrEvents.hpp"
33 #include "oops/objArrayKlass.hpp"
34 #include "opto/callGenerator.hpp"
35 #include "opto/parse.hpp"
36 #include "runtime/handles.inline.hpp"
37
38 //=============================================================================
39 //------------------------------InlineTree-------------------------------------
40 InlineTree::InlineTree(Compile* c,
41 const InlineTree *caller_tree, ciMethod* callee,
42 JVMState* caller_jvms, int caller_bci,
43 float site_invoke_ratio, int max_inline_level) :
44 C(c),
45 _caller_jvms(caller_jvms),
46 _caller_tree((InlineTree*) caller_tree),
47 _method(callee),
48 _site_invoke_ratio(site_invoke_ratio),
49 _max_inline_level(max_inline_level),
50 _count_inline_bcs(method()->code_size_for_inlining()),
51 _subtrees(c->comp_arena(), 2, 0, NULL),
52 _msg(NULL)
463 }
464 // We will attempt to see if a class/field/etc got properly loaded. If it
465 // did not, it may attempt to throw an exception during our probing. Catch
466 // and ignore such exceptions and do not attempt to compile the method.
467 if( callee_method->should_exclude() ) return false;
468
469 return true;
470 }
471
472 //------------------------------check_can_parse--------------------------------
473 const char* InlineTree::check_can_parse(ciMethod* callee) {
474 // Certain methods cannot be parsed at all:
475 if ( callee->is_native()) return "native method";
476 if ( callee->is_abstract()) return "abstract method";
477 if (!callee->can_be_compiled()) return "not compilable (disabled)";
478 if (!callee->has_balanced_monitors()) return "not compilable (unbalanced monitors)";
479 if ( callee->get_flow_analysis()->failing()) return "not compilable (flow analysis failed)";
480 return NULL;
481 }
482
483 static void post_inlining_event(int compile_id,const char* msg, bool success, int bci, ciMethod* caller, ciMethod* callee) {
484 assert(caller != NULL, "invariant");
485 assert(callee != NULL, "invariant");
486 EventCompilerInlining event;
487 if (event.should_commit()) {
488 JfrStructCalleeMethod callee_struct;
489 callee_struct.set_type(callee->holder()->name()->as_utf8());
490 callee_struct.set_name(callee->name()->as_utf8());
491 callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8());
492 event.set_compileId(compile_id);
493 event.set_message(msg);
494 event.set_succeeded(success);
495 event.set_bci(bci);
496 event.set_caller(caller->get_Method());
497 event.set_callee(callee_struct);
498 event.commit();
499 }
500 }
501
502 //------------------------------print_inlining---------------------------------
503 void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci,
504 ciMethod* caller_method, bool success) const {
505 const char* inline_msg = msg();
506 assert(inline_msg != NULL, "just checking");
507 if (C->log() != NULL) {
508 if (success) {
509 C->log()->inline_success(inline_msg);
510 } else {
511 C->log()->inline_fail(inline_msg);
512 }
513 }
514 if (C->print_inlining()) {
515 C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
516 if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
517 if (Verbose && callee_method) {
518 const InlineTree *top = this;
519 while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
520 //tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
521 }
522 }
523 post_inlining_event(C->compile_id(), inline_msg, success, caller_bci, caller_method, callee_method);
524 }
525
526 //------------------------------ok_to_inline-----------------------------------
527 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci, bool& should_delay) {
528 assert(callee_method != NULL, "caller checks for optimized virtual!");
529 assert(!should_delay, "should be initialized to false");
530 #ifdef ASSERT
531 // Make sure the incoming jvms has the same information content as me.
532 // This means that we can eventually make this whole class AllStatic.
533 if (jvms->caller() == NULL) {
534 assert(_caller_jvms == NULL, "redundant instance state");
535 } else {
536 assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
537 }
538 assert(_method == jvms->method(), "redundant instance state");
539 #endif
540 int caller_bci = jvms->bci();
541 ciMethod* caller_method = jvms->method();
542
543 // Do some initial checks.
544 if (!pass_initial_checks(caller_method, caller_bci, callee_method)) {
545 set_msg("failed initial checks");
546 print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
547 return NULL;
548 }
549
550 // Do some parse checks.
551 set_msg(check_can_parse(callee_method));
552 if (msg() != NULL) {
553 print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
554 return NULL;
555 }
556
557 // Check if inlining policy says no.
558 WarmCallInfo wci = *(initial_wci);
559 bool success = try_to_inline(callee_method, caller_method, caller_bci,
560 jvms, profile, &wci, should_delay);
561
562 #ifndef PRODUCT
563 if (InlineWarmCalls && (PrintOpto || C->print_inlining())) {
564 bool cold = wci.is_cold();
565 bool hot = !cold && wci.is_hot();
566 bool old_cold = !success;
567 if (old_cold != cold || (Verbose || WizardMode)) {
568 if (msg() == NULL) {
569 set_msg("OK");
570 }
571 tty->print(" OldInlining= %4s : %s\n WCI=",
572 old_cold ? "cold" : "hot", msg());
573 wci.print();
575 }
576 #endif
577 if (success) {
578 wci = *(WarmCallInfo::always_hot());
579 } else {
580 wci = *(WarmCallInfo::always_cold());
581 }
582
583 if (!InlineWarmCalls) {
584 if (!wci.is_cold() && !wci.is_hot()) {
585 // Do not inline the warm calls.
586 wci = *(WarmCallInfo::always_cold());
587 }
588 }
589
590 if (!wci.is_cold()) {
591 // Inline!
592 if (msg() == NULL) {
593 set_msg("inline (hot)");
594 }
595 print_inlining(callee_method, caller_bci, caller_method, true /* success */);
596 build_inline_tree_for_callee(callee_method, jvms, caller_bci);
597 if (InlineWarmCalls && !wci.is_hot())
598 return new (C) WarmCallInfo(wci); // copy to heap
599 return WarmCallInfo::always_hot();
600 }
601
602 // Do not inline
603 if (msg() == NULL) {
604 set_msg("too cold to inline");
605 }
606 print_inlining(callee_method, caller_bci, caller_method, false /* !success */ );
607 return NULL;
608 }
609
610 //------------------------------compute_callee_frequency-----------------------
611 float InlineTree::compute_callee_frequency( int caller_bci ) const {
612 int count = method()->interpreter_call_site_count(caller_bci);
613 int invcnt = method()->interpreter_invocation_count();
614 float freq = (float)count/(float)invcnt;
615 // Call-site count / interpreter invocation count, scaled recursively.
616 // Always between 0.0 and 1.0. Represents the percentage of the method's
617 // total execution time used at this call site.
618
619 return freq;
620 }
621
622 //------------------------------build_inline_tree_for_callee-------------------
623 InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) {
624 float recur_frequency = _site_invoke_ratio * compute_callee_frequency(caller_bci);
625 // Attempt inlining.
626 InlineTree* old_ilt = callee_at(caller_bci, callee_method);
|