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