src/share/vm/opto/bytecodeInfo.cpp

Wed, 08 Jan 2014 10:25:50 -0800

author
kvn
date
Wed, 08 Jan 2014 10:25:50 -0800
changeset 6217
849eb7bfceac
parent 6198
55fb97c4c58d
child 6314
1419657ed891
permissions
-rw-r--r--

8028468: Add inlining information into ciReplay
Summary: Allow dump and replay inlining for specified method during a program execution.
Reviewed-by: roland, twisti

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

mercurial