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