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