src/share/vm/opto/bytecodeInfo.cpp

Fri, 11 Jul 2014 19:51:36 -0400

author
drchase
date
Fri, 11 Jul 2014 19:51:36 -0400
changeset 7161
fc2c88ea11a9
parent 6709
73c839dda17e
child 6876
710a3c8b516e
child 7182
1de115720e74
permissions
-rw-r--r--

8036588: VerifyFieldClosure fails instanceKlass:3133
Summary: Changed deopt live-pointer test to use returns-object instead of live-and-returns-object
Reviewed-by: iveresov, kvn, jrose

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

mercurial