1 /*
   2  * Copyright (c) 1998, 2013, 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/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;
  57 #endif
  58   if (_caller_jvms != NULL) {
  59     // Keep a private copy of the caller_jvms:
  60     _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms());
  61     _caller_jvms->set_bci(caller_jvms->bci());
  62     assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining");
  63   }
  64   assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS");
  65   assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter");
  66   assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter");
  67   // Update hierarchical counts, count_inline_bcs() and count_inlines()
  68   InlineTree *caller = (InlineTree *)caller_tree;
  69   for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) {
  70     caller->_count_inline_bcs += count_inline_bcs();
  71     NOT_PRODUCT(caller->_count_inlines++;)
  72   }
  73 }
  74 
  75 /**
  76  *  Return true when EA is ON and a java constructor is called or
  77  *  a super constructor is called from an inlined java constructor.
  78  *  Also return true for boxing methods.
  79  */
  80 static bool is_init_with_ea(ciMethod* callee_method,
  81                             ciMethod* caller_method, Compile* C) {
  82   if (!C->do_escape_analysis() || !EliminateAllocations) {
  83     return false; // EA is off
  84   }
  85   if (callee_method->is_initializer()) {
  86     return true; // constuctor
  87   }
  88   if (caller_method->is_initializer() &&
  89       caller_method != C->method() &&
  90       caller_method->holder()->is_subclass_of(callee_method->holder())) {
  91     return true; // super constructor is called from inlined constructor
  92   }
  93   if (C->eliminate_boxing() && callee_method->is_boxing_method()) {
  94     return true;
  95   }
  96   return false;
  97 }
  98 
  99 /**
 100  *  Force inlining unboxing accessor.
 101  */
 102 static bool is_unboxing_method(ciMethod* callee_method, Compile* C) {
 103   return C->eliminate_boxing() && callee_method->is_unboxing_method();
 104 }
 105 
 106 // positive filter: should callee be inlined?
 107 bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
 108                                int caller_bci, ciCallProfile& profile,
 109                                WarmCallInfo* wci_result) {
 110   // Allows targeted inlining
 111   if (C->directive()->should_inline(callee_method)) {
 112     *wci_result = *(WarmCallInfo::always_hot());
 113     if (C->print_inlining() && Verbose) {
 114       CompileTask::print_inline_indent(inline_level());
 115       tty->print_cr("Inlined method is hot: ");
 116     }
 117     set_msg("force inline by CompileCommand");
 118     _forced_inline = true;
 119     return true;
 120   }
 121 
 122   if (callee_method->force_inline()) {
 123       set_msg("force inline by annotation");
 124       _forced_inline = true;
 125       return true;
 126   }
 127 
 128   if (callee_method->caller_sensitive()) {
 129       set_msg("force inline @CallerSensitive");
 130       _forced_inline = true;
 131       return true;
 132   }
 133 
 134 #ifndef PRODUCT
 135   int inline_depth = inline_level()+1;
 136   if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
 137     set_msg("force inline by ciReplay");
 138     _forced_inline = true;
 139     return true;
 140   }
 141 #endif
 142 
 143   int size = callee_method->code_size_for_inlining();
 144 
 145   // Check for too many throws (and not too huge)
 146   if(callee_method->interpreter_throwout_count() > InlineThrowCount &&
 147      size < InlineThrowMaxSize ) {
 148     wci_result->set_profit(wci_result->profit() * 100);
 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  = method()->scale_count(profile.count());
 162   int invoke_count     = method()->interpreter_invocation_count();
 163 
 164   assert(invoke_count != 0, "require invocation count greater than zero");
 165   int freq = call_site_count / invoke_count;
 166 
 167   // bump the max size if the call is frequent
 168   if ((freq >= InlineFrequencyRatio) ||
 169       (call_site_count >= InlineFrequencyCount) ||
 170       is_unboxing_method(callee_method, C) ||
 171       is_init_with_ea(callee_method, caller_method, C)) {
 172 
 173     max_inline_size = C->freq_inline_size();
 174     if (size <= max_inline_size && TraceFrequencyInlining) {
 175       CompileTask::print_inline_indent(inline_level());
 176       tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count);
 177       CompileTask::print_inline_indent(inline_level());
 178       callee_method->print();
 179       tty->cr();
 180     }
 181   } else {
 182     // Not hot.  Check for medium-sized pre-existing nmethod at cold sites.
 183     if (callee_method->has_compiled_code() &&
 184         callee_method->instructions_size() > inline_small_code_size) {
 185       set_msg("already compiled into a medium method");
 186       return false;
 187     }
 188   }
 189   if (size > max_inline_size) {
 190     if (max_inline_size > default_max_inline_size) {
 191       set_msg("hot method too big");
 192     } else {
 193       set_msg("too big");
 194     }
 195     return false;
 196   }
 197   return true;
 198 }
 199 
 200 
 201 // negative filter: should callee NOT be inlined?
 202 bool InlineTree::should_not_inline(ciMethod *callee_method,
 203                                    ciMethod* caller_method,
 204                                    JVMState* jvms,
 205                                    WarmCallInfo* wci_result) {
 206 
 207   const char* fail_msg = NULL;
 208 
 209   // First check all inlining restrictions which are required for correctness
 210   if ( callee_method->is_abstract()) {
 211     fail_msg = "abstract method"; // // note: we allow ik->is_abstract()
 212   } else if (!callee_method->holder()->is_initialized()) {
 213     fail_msg = "method holder not initialized";
 214   } else if ( callee_method->is_native()) {
 215     fail_msg = "native method";
 216   } else if ( callee_method->dont_inline()) {
 217     fail_msg = "don't inline by annotation";
 218   }
 219 
 220   // one more inlining restriction
 221   if (fail_msg == NULL && callee_method->has_unloaded_classes_in_signature()) {
 222     fail_msg = "unloaded signature classes";
 223   }
 224 
 225   if (fail_msg != NULL) {
 226     set_msg(fail_msg);
 227     return true;
 228   }
 229 
 230   // ignore heuristic controls on inlining
 231   if (C->directive()->should_inline(callee_method)) {
 232     set_msg("force inline by CompileCommand");
 233     return false;
 234   }
 235 
 236   if (C->directive()->should_not_inline(callee_method)) {
 237     set_msg("disallowed by CompileCommand");
 238     return true;
 239   }
 240 
 241 #ifndef PRODUCT
 242   int caller_bci = jvms->bci();
 243   int inline_depth = inline_level()+1;
 244   if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
 245     set_msg("force inline by ciReplay");
 246     return false;
 247   }
 248 
 249   if (ciReplay::should_not_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
 250     set_msg("disallowed by ciReplay");
 251     return true;
 252   }
 253 
 254   if (ciReplay::should_not_inline(callee_method)) {
 255     set_msg("disallowed by ciReplay");
 256     return true;
 257   }
 258 #endif
 259 
 260   if (callee_method->force_inline()) {
 261     set_msg("force inline by annotation");
 262     return false;
 263   }
 264 
 265   if (callee_method->caller_sensitive()) {
 266     set_msg("force inline @CallerSensitive");
 267     return false;
 268   }
 269 
 270   // Now perform checks which are heuristic
 271 
 272   if (is_unboxing_method(callee_method, C)) {
 273     // Inline unboxing methods.
 274     return false;
 275   }
 276 
 277   if (callee_method->has_compiled_code() &&
 278       callee_method->instructions_size() > InlineSmallCode) {
 279     set_msg("already compiled into a big method");
 280     return true;
 281   }
 282 
 283   // don't inline exception code unless the top method belongs to an
 284   // exception class
 285   if (caller_tree() != NULL &&
 286       callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) {
 287     const InlineTree *top = this;
 288     while (top->caller_tree() != NULL) top = top->caller_tree();
 289     ciInstanceKlass* k = top->method()->holder();
 290     if (!k->is_subclass_of(C->env()->Throwable_klass())) {
 291       set_msg("exception method");
 292       return true;
 293     }
 294   }
 295 
 296   // use frequency-based objections only for non-trivial methods
 297   if (callee_method->code_size() <= MaxTrivialSize) {
 298     return false;
 299   }
 300 
 301   // don't use counts with -Xcomp or CTW
 302   if (UseInterpreter && !CompileTheWorld) {
 303 
 304     if (!callee_method->has_compiled_code() &&
 305         !callee_method->was_executed_more_than(0)) {
 306       set_msg("never executed");
 307       return true;
 308     }
 309 
 310     if (is_init_with_ea(callee_method, caller_method, C)) {
 311       // Escape Analysis: inline all executed constructors
 312       return false;
 313     } else {
 314       intx counter_high_value;
 315       // Tiered compilation uses a different "high value" than non-tiered compilation.
 316       // Determine the right value to use.
 317       if (TieredCompilation) {
 318         counter_high_value = InvocationCounter::count_limit / 2;
 319       } else {
 320         counter_high_value = CompileThreshold / 2;
 321       }
 322       if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold, counter_high_value))) {
 323         set_msg("executed < MinInliningThreshold times");
 324         return true;
 325       }
 326     }
 327   }
 328 
 329   return false;
 330 }
 331 
 332 //-----------------------------try_to_inline-----------------------------------
 333 // return true if ok
 334 // Relocated from "InliningClosure::try_to_inline"
 335 bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
 336                                int caller_bci, JVMState* jvms, ciCallProfile& profile,
 337                                WarmCallInfo* wci_result, bool& should_delay) {
 338 
 339   if (ClipInlining && (int)count_inline_bcs() >= DesiredMethodLimit) {
 340     if ((!callee_method->force_inline() && !callee_method->caller_sensitive()) || !IncrementalInline) {
 341       set_msg("size > DesiredMethodLimit");
 342       return false;
 343     } else if (!C->inlining_incrementally()) {
 344       should_delay = true;
 345     }
 346   }
 347 
 348   _forced_inline = false; // Reset
 349   if (!should_inline(callee_method, caller_method, caller_bci, profile,
 350                      wci_result)) {
 351     return false;
 352   }
 353   if (should_not_inline(callee_method, caller_method, jvms, wci_result)) {
 354     return false;
 355   }
 356 
 357   if (InlineAccessors && callee_method->is_accessor()) {
 358     // accessor methods are not subject to any of the following limits.
 359     set_msg("accessor");
 360     return true;
 361   }
 362 
 363   // suppress a few checks for accessors and trivial methods
 364   if (callee_method->code_size() > MaxTrivialSize) {
 365 
 366     // don't inline into giant methods
 367     if (C->over_inlining_cutoff()) {
 368       if ((!callee_method->force_inline() && !caller_method->caller_sensitive() && !caller_method->is_compiled_lambda_form())
 369           || !IncrementalInline) {
 370         set_msg("NodeCountInliningCutoff");
 371         return false;
 372       } else {
 373         should_delay = true;
 374       }
 375     }
 376 
 377     if ((!UseInterpreter || CompileTheWorld) &&
 378         is_init_with_ea(callee_method, caller_method, C)) {
 379       // Escape Analysis stress testing when running Xcomp or CTW:
 380       // inline constructors even if they are not reached.
 381     } else if (forced_inline()) {
 382       // Inlining was forced by CompilerOracle, ciReplay or annotation
 383     } else if (profile.count() == 0) {
 384       // don't inline unreached call sites
 385        set_msg("call site not reached");
 386        return false;
 387     }
 388   }
 389 
 390   if (!C->do_inlining() && InlineAccessors) {
 391     set_msg("not an accessor");
 392     return false;
 393   }
 394 
 395   // Limit inlining depth in case inlining is forced or
 396   // _max_inline_level was increased to compensate for lambda forms.
 397   if (inline_level() > MaxForceInlineLevel) {
 398     set_msg("MaxForceInlineLevel");
 399     return false;
 400   }
 401   if (inline_level() > _max_inline_level) {
 402     if ((!callee_method->force_inline() && !callee_method->caller_sensitive()) || !IncrementalInline) {
 403       set_msg("inlining too deep");
 404       return false;
 405     } else if (!C->inlining_incrementally()) {
 406       should_delay = true;
 407     }
 408   }
 409 
 410   // detect direct and indirect recursive inlining
 411   {
 412     // count the current method and the callee
 413     const bool is_compiled_lambda_form = callee_method->is_compiled_lambda_form();
 414     int inline_level = 0;
 415     if (!is_compiled_lambda_form) {
 416       if (method() == callee_method) {
 417         inline_level++;
 418       }
 419     }
 420     // count callers of current method and callee
 421     Node* callee_argument0 = is_compiled_lambda_form ? jvms->map()->argument(jvms, 0)->uncast() : NULL;
 422     for (JVMState* j = jvms->caller(); j != NULL && j->has_method(); j = j->caller()) {
 423       if (j->method() == callee_method) {
 424         if (is_compiled_lambda_form) {
 425           // Since compiled lambda forms are heavily reused we allow recursive inlining.  If it is truly
 426           // a recursion (using the same "receiver") we limit inlining otherwise we can easily blow the
 427           // compiler stack.
 428           Node* caller_argument0 = j->map()->argument(j, 0)->uncast();
 429           if (caller_argument0 == callee_argument0) {
 430             inline_level++;
 431           }
 432         } else {
 433           inline_level++;
 434         }
 435       }
 436     }
 437     if (inline_level > MaxRecursiveInlineLevel) {
 438       set_msg("recursive inlining is too deep");
 439       return false;
 440     }
 441   }
 442 
 443   int size = callee_method->code_size_for_inlining();
 444 
 445   if (ClipInlining && (int)count_inline_bcs() + size >= DesiredMethodLimit) {
 446     if ((!callee_method->force_inline() && !callee_method->caller_sensitive()) || !IncrementalInline) {
 447       set_msg("size > DesiredMethodLimit");
 448       return false;
 449     } else if (!C->inlining_incrementally()) {
 450       should_delay = true;
 451     }
 452   }
 453 
 454   // ok, inline this method
 455   return true;
 456 }
 457 
 458 //------------------------------pass_initial_checks----------------------------
 459 bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) {
 460   ciInstanceKlass *callee_holder = callee_method ? callee_method->holder() : NULL;
 461   // Check if a callee_method was suggested
 462   if( callee_method == NULL )            return false;
 463   // Check if klass of callee_method is loaded
 464   if( !callee_holder->is_loaded() )      return false;
 465   if( !callee_holder->is_initialized() ) return false;
 466   if( !UseInterpreter || CompileTheWorld /* running Xcomp or CTW */ ) {
 467     // Checks that constant pool's call site has been visited
 468     // stricter than callee_holder->is_initialized()
 469     ciBytecodeStream iter(caller_method);
 470     iter.force_bci(caller_bci);
 471     Bytecodes::Code call_bc = iter.cur_bc();
 472     // An invokedynamic instruction does not have a klass.
 473     if (call_bc != Bytecodes::_invokedynamic) {
 474       int index = iter.get_index_u2_cpcache();
 475       if (!caller_method->is_klass_loaded(index, true)) {
 476         return false;
 477       }
 478       // Try to do constant pool resolution if running Xcomp
 479       if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) {
 480         return false;
 481       }
 482     }
 483   }
 484   return true;
 485 }
 486 
 487 //------------------------------check_can_parse--------------------------------
 488 const char* InlineTree::check_can_parse(ciMethod* callee) {
 489   // Certain methods cannot be parsed at all:
 490   if ( callee->is_native())                     return "native method";
 491   if ( callee->is_abstract())                   return "abstract method";
 492   if (!callee->can_be_compiled())               return "not compilable (disabled)";
 493   if (!callee->has_balanced_monitors())         return "not compilable (unbalanced monitors)";
 494   if ( callee->get_flow_analysis()->failing())  return "not compilable (flow analysis failed)";
 495   return NULL;
 496 }
 497 
 498 //------------------------------print_inlining---------------------------------
 499 void InlineTree::print_inlining(ciMethod* callee_method, int caller_bci,
 500                                 ciMethod* caller_method, bool success) const {
 501   const char* inline_msg = msg();
 502   assert(inline_msg != NULL, "just checking");
 503   if (C->log() != NULL) {
 504     if (success) {
 505       C->log()->inline_success(inline_msg);
 506     } else {
 507       C->log()->inline_fail(inline_msg);
 508     }
 509   }
 510   if (C->print_inlining()) {
 511     C->print_inlining(callee_method, inline_level(), caller_bci, inline_msg);
 512     if (callee_method == NULL) tty->print(" callee not monotonic or profiled");
 513     if (Verbose && callee_method) {
 514       const InlineTree *top = this;
 515       while( top->caller_tree() != NULL ) { top = top->caller_tree(); }
 516       //tty->print("  bcs: %d+%d  invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count());
 517     }
 518   }
 519 #if INCLUDE_TRACE
 520   EventCompilerInlining event;
 521   if (event.should_commit()) {
 522     event.set_compileID(C->compile_id());
 523     event.set_message(inline_msg);
 524     event.set_succeeded(success);
 525     event.set_bci(caller_bci);
 526     event.set_caller(caller_method->get_Method());
 527     event.set_callee(callee_method->to_trace_struct());
 528     event.commit();
 529   }
 530 #endif // INCLUDE_TRACE
 531 }
 532 
 533 //------------------------------ok_to_inline-----------------------------------
 534 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci, bool& should_delay) {
 535   assert(callee_method != NULL, "caller checks for optimized virtual!");
 536   assert(!should_delay, "should be initialized to false");
 537 #ifdef ASSERT
 538   // Make sure the incoming jvms has the same information content as me.
 539   // This means that we can eventually make this whole class AllStatic.
 540   if (jvms->caller() == NULL) {
 541     assert(_caller_jvms == NULL, "redundant instance state");
 542   } else {
 543     assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state");
 544   }
 545   assert(_method == jvms->method(), "redundant instance state");
 546 #endif
 547   int         caller_bci    = jvms->bci();
 548   ciMethod*   caller_method = jvms->method();
 549 
 550   // Do some initial checks.
 551   if (!pass_initial_checks(caller_method, caller_bci, callee_method)) {
 552     set_msg("failed initial checks");
 553     print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
 554     return NULL;
 555   }
 556 
 557   // Do some parse checks.
 558   set_msg(check_can_parse(callee_method));
 559   if (msg() != NULL) {
 560     print_inlining(callee_method, caller_bci, caller_method, false /* !success */);
 561     return NULL;
 562   }
 563 
 564   // Check if inlining policy says no.
 565   WarmCallInfo wci = *(initial_wci);
 566   bool success = try_to_inline(callee_method, caller_method, caller_bci,
 567                                jvms, profile, &wci, should_delay);
 568 
 569 #ifndef PRODUCT
 570   if (InlineWarmCalls && (PrintOpto || C->print_inlining())) {
 571     bool cold = wci.is_cold();
 572     bool hot  = !cold && wci.is_hot();
 573     bool old_cold = !success;
 574     if (old_cold != cold || (Verbose || WizardMode)) {
 575       if (msg() == NULL) {
 576         set_msg("OK");
 577       }
 578       tty->print("   OldInlining= %4s : %s\n           WCI=",
 579                  old_cold ? "cold" : "hot", msg());
 580       wci.print();
 581     }
 582   }
 583 #endif
 584   if (success) {
 585     wci = *(WarmCallInfo::always_hot());
 586   } else {
 587     wci = *(WarmCallInfo::always_cold());
 588   }
 589 
 590   if (!InlineWarmCalls) {
 591     if (!wci.is_cold() && !wci.is_hot()) {
 592       // Do not inline the warm calls.
 593       wci = *(WarmCallInfo::always_cold());
 594     }
 595   }
 596 
 597   if (!wci.is_cold()) {
 598     // Inline!
 599     if (msg() == NULL) {
 600       set_msg("inline (hot)");
 601     }
 602     print_inlining(callee_method, caller_bci, caller_method, true /* success */);
 603     build_inline_tree_for_callee(callee_method, jvms, caller_bci);
 604     if (InlineWarmCalls && !wci.is_hot()) {
 605       return new (C) WarmCallInfo(wci);  // copy to heap
 606     }
 607     return WarmCallInfo::always_hot();
 608   }
 609 
 610   // Do not inline
 611   if (msg() == NULL) {
 612     set_msg("too cold to inline");
 613   }
 614   print_inlining(callee_method, caller_bci, caller_method, false /* !success */ );
 615   return NULL;
 616 }
 617 
 618 //------------------------------compute_callee_frequency-----------------------
 619 float InlineTree::compute_callee_frequency( int caller_bci ) const {
 620   int count  = method()->interpreter_call_site_count(caller_bci);
 621   int invcnt = method()->interpreter_invocation_count();
 622   float freq = (float)count/(float)invcnt;
 623   // Call-site count / interpreter invocation count, scaled recursively.
 624   // Always between 0.0 and 1.0.  Represents the percentage of the method's
 625   // total execution time used at this call site.
 626 
 627   return freq;
 628 }
 629 
 630 //------------------------------build_inline_tree_for_callee-------------------
 631 InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) {
 632   float recur_frequency = _site_invoke_ratio * compute_callee_frequency(caller_bci);
 633   // Attempt inlining.
 634   InlineTree* old_ilt = callee_at(caller_bci, callee_method);
 635   if (old_ilt != NULL) {
 636     return old_ilt;
 637   }
 638   int max_inline_level_adjust = 0;
 639   if (caller_jvms->method() != NULL) {
 640     if (caller_jvms->method()->is_compiled_lambda_form()) {
 641       max_inline_level_adjust += 1;  // don't count actions in MH or indy adapter frames
 642     } else if (callee_method->is_method_handle_intrinsic() ||
 643                callee_method->is_compiled_lambda_form()) {
 644       max_inline_level_adjust += 1;  // don't count method handle calls from java.lang.invoke implementation
 645     }
 646     if (max_inline_level_adjust != 0 && C->print_inlining() && (Verbose || WizardMode)) {
 647       CompileTask::print_inline_indent(inline_level());
 648       tty->print_cr(" \\-> discounting inline depth");
 649     }
 650     if (max_inline_level_adjust != 0 && C->log()) {
 651       int id1 = C->log()->identify(caller_jvms->method());
 652       int id2 = C->log()->identify(callee_method);
 653       C->log()->elem("inline_level_discount caller='%d' callee='%d'", id1, id2);
 654     }
 655   }
 656   InlineTree* ilt = new InlineTree(C, this, callee_method, caller_jvms, caller_bci, recur_frequency, _max_inline_level + max_inline_level_adjust);
 657   _subtrees.append(ilt);
 658 
 659   NOT_PRODUCT( _count_inlines += 1; )
 660 
 661   return ilt;
 662 }
 663 
 664 
 665 //---------------------------------------callee_at-----------------------------
 666 InlineTree *InlineTree::callee_at(int bci, ciMethod* callee) const {
 667   for (int i = 0; i < _subtrees.length(); i++) {
 668     InlineTree* sub = _subtrees.at(i);
 669     if (sub->caller_bci() == bci && callee == sub->method()) {
 670       return sub;
 671     }
 672   }
 673   return NULL;
 674 }
 675 
 676 
 677 //------------------------------build_inline_tree_root-------------------------
 678 InlineTree *InlineTree::build_inline_tree_root() {
 679   Compile* C = Compile::current();
 680 
 681   // Root of inline tree
 682   InlineTree* ilt = new InlineTree(C, NULL, C->method(), NULL, -1, 1.0F, MaxInlineLevel);
 683 
 684   return ilt;
 685 }
 686 
 687 
 688 //-------------------------find_subtree_from_root-----------------------------
 689 // Given a jvms, which determines a call chain from the root method,
 690 // find the corresponding inline tree.
 691 // Note: This method will be removed or replaced as InlineTree goes away.
 692 InlineTree* InlineTree::find_subtree_from_root(InlineTree* root, JVMState* jvms, ciMethod* callee) {
 693   InlineTree* iltp = root;
 694   uint depth = jvms && jvms->has_method() ? jvms->depth() : 0;
 695   for (uint d = 1; d <= depth; d++) {
 696     JVMState* jvmsp  = jvms->of_depth(d);
 697     // Select the corresponding subtree for this bci.
 698     assert(jvmsp->method() == iltp->method(), "tree still in sync");
 699     ciMethod* d_callee = (d == depth) ? callee : jvms->of_depth(d+1)->method();
 700     InlineTree* sub = iltp->callee_at(jvmsp->bci(), d_callee);
 701     if (sub == NULL) {
 702       if (d == depth) {
 703         sub = iltp->build_inline_tree_for_callee(d_callee, jvmsp, jvmsp->bci());
 704       }
 705       guarantee(sub != NULL, "should be a sub-ilt here");
 706       return sub;
 707     }
 708     iltp = sub;
 709   }
 710   return iltp;
 711 }
 712 
 713 // Count number of nodes in this subtree
 714 int InlineTree::count() const {
 715   int result = 1;
 716   for (int i = 0 ; i < _subtrees.length(); i++) {
 717     result += _subtrees.at(i)->count();
 718   }
 719   return result;
 720 }
 721 
 722 void InlineTree::dump_replay_data(outputStream* out) {
 723   out->print(" %d %d ", inline_level(), caller_bci());
 724   method()->dump_name_as_ascii(out);
 725   for (int i = 0 ; i < _subtrees.length(); i++) {
 726     _subtrees.at(i)->dump_replay_data(out);
 727   }
 728 }
 729 
 730 
 731 #ifndef PRODUCT
 732 void InlineTree::print_impl(outputStream* st, int indent) const {
 733   for (int i = 0; i < indent; i++) st->print(" ");
 734   st->print(" @ %d", caller_bci());
 735   method()->print_short_name(st);
 736   st->cr();
 737 
 738   for (int i = 0 ; i < _subtrees.length(); i++) {
 739     _subtrees.at(i)->print_impl(st, indent + 2);
 740   }
 741 }
 742 
 743 void InlineTree::print_value_on(outputStream* st) const {
 744   print_impl(st, 2);
 745 }
 746 #endif