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