src/share/vm/opto/bytecodeInfo.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial