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