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