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