src/share/vm/opto/bytecodeInfo.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 7994
04ff2f6cd0eb
child 9640
017b3a2aca37
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial