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