src/share/vm/opto/bytecodeInfo.cpp

Thu, 14 Nov 2013 09:14:39 -0800

author
vlivanov
date
Thu, 14 Nov 2013 09:14:39 -0800
changeset 6106
e74074c34312
parent 5901
0c4c40f5c399
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8028159: C2: compiler stack overflow during inlining of @ForceInline methods
Reviewed-by: roland, kvn

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

mercurial