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