Mercurial > hg > truffle
annotate src/share/vm/opto/bytecodeInfo.cpp @ 497:7aadaf46ecd7
Merge
author | jmasa |
---|---|
date | Fri, 19 Dec 2008 12:15:34 -0800 |
parents | 194b8e3a2fc4 |
children | f6da6f0174ac |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_bytecodeInfo.cpp.incl" | |
27 | |
28 //============================================================================= | |
29 //------------------------------InlineTree------------------------------------- | |
30 InlineTree::InlineTree( Compile* c, const InlineTree *caller_tree, ciMethod* callee, JVMState* caller_jvms, int caller_bci, float site_invoke_ratio ) | |
31 : C(c), _caller_jvms(caller_jvms), | |
32 _caller_tree((InlineTree*)caller_tree), | |
33 _method(callee), _site_invoke_ratio(site_invoke_ratio), | |
34 _count_inline_bcs(method()->code_size()) { | |
35 NOT_PRODUCT(_count_inlines = 0;) | |
36 if (_caller_jvms != NULL) { | |
37 // Keep a private copy of the caller_jvms: | |
38 _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms()); | |
39 _caller_jvms->set_bci(caller_jvms->bci()); | |
40 } | |
41 assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS"); | |
42 assert((caller_tree == NULL ? 0 : caller_tree->inline_depth() + 1) == inline_depth(), "correct (redundant) depth parameter"); | |
43 assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter"); | |
44 if (UseOldInlining) { | |
45 // Update hierarchical counts, count_inline_bcs() and count_inlines() | |
46 InlineTree *caller = (InlineTree *)caller_tree; | |
47 for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) { | |
48 caller->_count_inline_bcs += count_inline_bcs(); | |
49 NOT_PRODUCT(caller->_count_inlines++;) | |
50 } | |
51 } | |
52 } | |
53 | |
54 InlineTree::InlineTree(Compile* c, ciMethod* callee_method, JVMState* caller_jvms, float site_invoke_ratio) | |
55 : C(c), _caller_jvms(caller_jvms), _caller_tree(NULL), | |
56 _method(callee_method), _site_invoke_ratio(site_invoke_ratio), | |
57 _count_inline_bcs(method()->code_size()) { | |
58 NOT_PRODUCT(_count_inlines = 0;) | |
59 assert(!UseOldInlining, "do not use for old stuff"); | |
60 } | |
61 | |
62 | |
63 | |
64 static void print_indent(int depth) { | |
65 tty->print(" "); | |
66 for (int i = depth; i != 0; --i) tty->print(" "); | |
67 } | |
68 | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
69 static bool is_init_with_ea(ciMethod* callee_method, |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
70 ciMethod* caller_method, Compile* C) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
71 // True when EA is ON and a java constructor is called or |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
72 // a super constructor is called from an inlined java constructor. |
244 | 73 return C->do_escape_analysis() && EliminateAllocations && |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
74 ( callee_method->is_initializer() || |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
75 (caller_method->is_initializer() && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
76 caller_method != C->method() && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
77 caller_method->holder()->is_subclass_of(callee_method->holder())) |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
78 ); |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
79 } |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
80 |
0 | 81 // positive filter: should send be inlined? returns NULL, if yes, or rejection msg |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
82 const char* InlineTree::shouldInline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result) const { |
0 | 83 // Allows targeted inlining |
84 if(callee_method->should_inline()) { | |
85 *wci_result = *(WarmCallInfo::always_hot()); | |
86 if (PrintInlining && Verbose) { | |
87 print_indent(inline_depth()); | |
88 tty->print_cr("Inlined method is hot: "); | |
89 } | |
90 return NULL; | |
91 } | |
92 | |
93 // positive filter: should send be inlined? returns NULL (--> yes) | |
94 // or rejection msg | |
95 int max_size = C->max_inline_size(); | |
96 int size = callee_method->code_size(); | |
97 | |
98 // Check for too many throws (and not too huge) | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
99 if(callee_method->interpreter_throwout_count() > InlineThrowCount && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
100 size < InlineThrowMaxSize ) { |
0 | 101 wci_result->set_profit(wci_result->profit() * 100); |
102 if (PrintInlining && Verbose) { | |
103 print_indent(inline_depth()); | |
104 tty->print_cr("Inlined method with many throws (throws=%d):", callee_method->interpreter_throwout_count()); | |
105 } | |
106 return NULL; | |
107 } | |
108 | |
109 if (!UseOldInlining) { | |
110 return NULL; // size and frequency are represented in a new way | |
111 } | |
112 | |
113 int call_site_count = method()->scale_count(profile.count()); | |
114 int invoke_count = method()->interpreter_invocation_count(); | |
115 assert( invoke_count != 0, "Require invokation count greater than zero"); | |
116 int freq = call_site_count/invoke_count; | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
117 |
0 | 118 // bump the max size if the call is frequent |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
119 if ((freq >= InlineFrequencyRatio) || |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
120 (call_site_count >= InlineFrequencyCount) || |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
121 is_init_with_ea(callee_method, caller_method, C)) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
122 |
0 | 123 max_size = C->freq_inline_size(); |
124 if (size <= max_size && TraceFrequencyInlining) { | |
125 print_indent(inline_depth()); | |
126 tty->print_cr("Inlined frequent method (freq=%d count=%d):", freq, call_site_count); | |
127 print_indent(inline_depth()); | |
128 callee_method->print(); | |
129 tty->cr(); | |
130 } | |
131 } else { | |
132 // Not hot. Check for medium-sized pre-existing nmethod at cold sites. | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
133 if (callee_method->has_compiled_code() && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
134 callee_method->instructions_size() > InlineSmallCode/4) |
0 | 135 return "already compiled into a medium method"; |
136 } | |
137 if (size > max_size) { | |
138 if (max_size > C->max_inline_size()) | |
139 return "hot method too big"; | |
140 return "too big"; | |
141 } | |
142 return NULL; | |
143 } | |
144 | |
145 | |
146 // negative filter: should send NOT be inlined? returns NULL, ok to inline, or rejection msg | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
147 const char* InlineTree::shouldNotInline(ciMethod *callee_method, ciMethod* caller_method, WarmCallInfo* wci_result) const { |
0 | 148 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg |
149 if (!UseOldInlining) { | |
150 const char* fail = NULL; | |
151 if (callee_method->is_abstract()) fail = "abstract method"; | |
152 // note: we allow ik->is_abstract() | |
153 if (!callee_method->holder()->is_initialized()) fail = "method holder not initialized"; | |
154 if (callee_method->is_native()) fail = "native method"; | |
155 | |
156 if (fail) { | |
157 *wci_result = *(WarmCallInfo::always_cold()); | |
158 return fail; | |
159 } | |
160 | |
161 if (callee_method->has_unloaded_classes_in_signature()) { | |
162 wci_result->set_profit(wci_result->profit() * 0.1); | |
163 } | |
164 | |
165 // don't inline exception code unless the top method belongs to an | |
166 // exception class | |
167 if (callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { | |
168 ciMethod* top_method = caller_jvms() ? caller_jvms()->of_depth(1)->method() : method(); | |
169 if (!top_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { | |
170 wci_result->set_profit(wci_result->profit() * 0.1); | |
171 } | |
172 } | |
173 | |
174 if (callee_method->has_compiled_code() && callee_method->instructions_size() > InlineSmallCode) { | |
175 wci_result->set_profit(wci_result->profit() * 0.1); | |
176 // %%% adjust wci_result->size()? | |
177 } | |
178 | |
179 return NULL; | |
180 } | |
181 | |
182 // First check all inlining restrictions which are required for correctness | |
183 if (callee_method->is_abstract()) return "abstract method"; | |
184 // note: we allow ik->is_abstract() | |
185 if (!callee_method->holder()->is_initialized()) return "method holder not initialized"; | |
186 if (callee_method->is_native()) return "native method"; | |
187 if (callee_method->has_unloaded_classes_in_signature()) return "unloaded signature classes"; | |
188 | |
189 if (callee_method->should_inline()) { | |
190 // ignore heuristic controls on inlining | |
191 return NULL; | |
192 } | |
193 | |
194 // Now perform checks which are heuristic | |
195 | |
196 if( callee_method->has_compiled_code() && callee_method->instructions_size() > InlineSmallCode ) | |
197 return "already compiled into a big method"; | |
198 | |
199 // don't inline exception code unless the top method belongs to an | |
200 // exception class | |
201 if (caller_tree() != NULL && | |
202 callee_method->holder()->is_subclass_of(C->env()->Throwable_klass())) { | |
203 const InlineTree *top = this; | |
204 while (top->caller_tree() != NULL) top = top->caller_tree(); | |
205 ciInstanceKlass* k = top->method()->holder(); | |
206 if (!k->is_subclass_of(C->env()->Throwable_klass())) | |
207 return "exception method"; | |
208 } | |
209 | |
210 // use frequency-based objections only for non-trivial methods | |
211 if (callee_method->code_size() <= MaxTrivialSize) return NULL; | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
212 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
213 // don't use counts with -Xcomp or CTW |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
214 if (UseInterpreter && !CompileTheWorld) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
215 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
216 if (!callee_method->has_compiled_code() && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
217 !callee_method->was_executed_more_than(0)) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
218 return "never executed"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
219 } |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
220 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
221 if (is_init_with_ea(callee_method, caller_method, C)) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
222 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
223 // Escape Analysis: inline all executed constructors |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
224 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
225 } else if (!callee_method->was_executed_more_than(MIN2(MinInliningThreshold, |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
226 CompileThreshold >> 1))) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
227 return "executed < MinInliningThreshold times"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
228 } |
0 | 229 } |
230 | |
231 if (callee_method->should_not_inline()) { | |
232 return "disallowed by CompilerOracle"; | |
233 } | |
234 | |
235 return NULL; | |
236 } | |
237 | |
238 //-----------------------------try_to_inline----------------------------------- | |
239 // return NULL if ok, reason for not inlining otherwise | |
240 // Relocated from "InliningClosure::try_to_inline" | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
241 const char* InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method, int caller_bci, ciCallProfile& profile, WarmCallInfo* wci_result) { |
0 | 242 |
243 // Old algorithm had funny accumulating BC-size counters | |
244 if (UseOldInlining && ClipInlining | |
245 && (int)count_inline_bcs() >= DesiredMethodLimit) { | |
246 return "size > DesiredMethodLimit"; | |
247 } | |
248 | |
249 const char *msg = NULL; | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
250 if ((msg = shouldInline(callee_method, caller_method, caller_bci, |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
251 profile, wci_result)) != NULL) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
252 return msg; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
253 } |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
254 if ((msg = shouldNotInline(callee_method, caller_method, |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
255 wci_result)) != NULL) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
256 return msg; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
257 } |
0 | 258 |
259 bool is_accessor = InlineAccessors && callee_method->is_accessor(); | |
260 | |
261 // suppress a few checks for accessors and trivial methods | |
262 if (!is_accessor && callee_method->code_size() > MaxTrivialSize) { | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
263 |
0 | 264 // don't inline into giant methods |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
265 if (C->unique() > (uint)NodeCountInliningCutoff) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
266 return "NodeCountInliningCutoff"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
267 } |
0 | 268 |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
269 if ((!UseInterpreter || CompileTheWorld) && |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
270 is_init_with_ea(callee_method, caller_method, C)) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
271 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
272 // Escape Analysis stress testing when running Xcomp or CTW: |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
273 // inline constructors even if they are not reached. |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
274 |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
275 } else if (profile.count() == 0) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
276 // don't inline unreached call sites |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
277 return "call site not reached"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
278 } |
0 | 279 } |
280 | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
281 if (!C->do_inlining() && InlineAccessors && !is_accessor) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
282 return "not an accessor"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
283 } |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
284 if( inline_depth() > MaxInlineLevel ) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
285 return "inlining too deep"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
286 } |
0 | 287 if( method() == callee_method && |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
288 inline_depth() > MaxRecursiveInlineLevel ) { |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
289 return "recursively inlining too deep"; |
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
290 } |
0 | 291 |
292 int size = callee_method->code_size(); | |
293 | |
294 if (UseOldInlining && ClipInlining | |
295 && (int)count_inline_bcs() + size >= DesiredMethodLimit) { | |
296 return "size > DesiredMethodLimit"; | |
297 } | |
298 | |
299 // ok, inline this method | |
300 return NULL; | |
301 } | |
302 | |
303 //------------------------------pass_initial_checks---------------------------- | |
304 bool pass_initial_checks(ciMethod* caller_method, int caller_bci, ciMethod* callee_method) { | |
305 ciInstanceKlass *callee_holder = callee_method ? callee_method->holder() : NULL; | |
306 // Check if a callee_method was suggested | |
307 if( callee_method == NULL ) return false; | |
308 // Check if klass of callee_method is loaded | |
309 if( !callee_holder->is_loaded() ) return false; | |
310 if( !callee_holder->is_initialized() ) return false; | |
311 if( !UseInterpreter || CompileTheWorld /* running Xcomp or CTW */ ) { | |
312 // Checks that constant pool's call site has been visited | |
313 // stricter than callee_holder->is_initialized() | |
314 ciBytecodeStream iter(caller_method); | |
315 iter.force_bci(caller_bci); | |
316 int index = iter.get_index_big(); | |
317 if( !caller_method->is_klass_loaded(index, true) ) { | |
318 return false; | |
319 } | |
320 // Try to do constant pool resolution if running Xcomp | |
321 Bytecodes::Code call_bc = iter.cur_bc(); | |
322 if( !caller_method->check_call(index, call_bc == Bytecodes::_invokestatic) ) { | |
323 return false; | |
324 } | |
325 } | |
326 // We will attempt to see if a class/field/etc got properly loaded. If it | |
327 // did not, it may attempt to throw an exception during our probing. Catch | |
328 // and ignore such exceptions and do not attempt to compile the method. | |
329 if( callee_method->should_exclude() ) return false; | |
330 | |
331 return true; | |
332 } | |
333 | |
334 #ifndef PRODUCT | |
335 //------------------------------print_inlining--------------------------------- | |
336 // Really, the failure_msg can be a success message also. | |
337 void InlineTree::print_inlining(ciMethod *callee_method, int caller_bci, const char *failure_msg) const { | |
338 print_indent(inline_depth()); | |
339 tty->print("@ %d ", caller_bci); | |
340 if( callee_method ) callee_method->print_short_name(); | |
341 else tty->print(" callee not monotonic or profiled"); | |
342 tty->print(" %s", (failure_msg ? failure_msg : "inline")); | |
343 if( Verbose && callee_method ) { | |
344 const InlineTree *top = this; | |
345 while( top->caller_tree() != NULL ) { top = top->caller_tree(); } | |
346 tty->print(" bcs: %d+%d invoked: %d", top->count_inline_bcs(), callee_method->code_size(), callee_method->interpreter_invocation_count()); | |
347 } | |
348 tty->cr(); | |
349 } | |
350 #endif | |
351 | |
352 //------------------------------ok_to_inline----------------------------------- | |
353 WarmCallInfo* InlineTree::ok_to_inline(ciMethod* callee_method, JVMState* jvms, ciCallProfile& profile, WarmCallInfo* initial_wci) { | |
354 assert(callee_method != NULL, "caller checks for optimized virtual!"); | |
355 #ifdef ASSERT | |
356 // Make sure the incoming jvms has the same information content as me. | |
357 // This means that we can eventually make this whole class AllStatic. | |
358 if (jvms->caller() == NULL) { | |
359 assert(_caller_jvms == NULL, "redundant instance state"); | |
360 } else { | |
361 assert(_caller_jvms->same_calls_as(jvms->caller()), "redundant instance state"); | |
362 } | |
363 assert(_method == jvms->method(), "redundant instance state"); | |
364 #endif | |
365 const char *failure_msg = NULL; | |
366 int caller_bci = jvms->bci(); | |
367 ciMethod *caller_method = jvms->method(); | |
368 | |
369 if( !pass_initial_checks(caller_method, caller_bci, callee_method)) { | |
370 if( PrintInlining ) { | |
371 failure_msg = "failed_initial_checks"; | |
372 print_inlining( callee_method, caller_bci, failure_msg); | |
373 } | |
374 return NULL; | |
375 } | |
376 | |
377 // Check if inlining policy says no. | |
378 WarmCallInfo wci = *(initial_wci); | |
41
874b2c4f43d1
6667605: (Escape Analysis) inline java constructors when EA is on
kvn
parents:
0
diff
changeset
|
379 failure_msg = try_to_inline(callee_method, caller_method, caller_bci, profile, &wci); |
0 | 380 if (failure_msg != NULL && C->log() != NULL) { |
381 C->log()->begin_elem("inline_fail reason='"); | |
382 C->log()->text("%s", failure_msg); | |
383 C->log()->end_elem("'"); | |
384 } | |
385 | |
386 #ifndef PRODUCT | |
387 if (UseOldInlining && InlineWarmCalls | |
388 && (PrintOpto || PrintOptoInlining || PrintInlining)) { | |
389 bool cold = wci.is_cold(); | |
390 bool hot = !cold && wci.is_hot(); | |
391 bool old_cold = (failure_msg != NULL); | |
392 if (old_cold != cold || (Verbose || WizardMode)) { | |
393 tty->print(" OldInlining= %4s : %s\n WCI=", | |
394 old_cold ? "cold" : "hot", failure_msg ? failure_msg : "OK"); | |
395 wci.print(); | |
396 } | |
397 } | |
398 #endif | |
399 if (UseOldInlining) { | |
400 if (failure_msg == NULL) | |
401 wci = *(WarmCallInfo::always_hot()); | |
402 else | |
403 wci = *(WarmCallInfo::always_cold()); | |
404 } | |
405 if (!InlineWarmCalls) { | |
406 if (!wci.is_cold() && !wci.is_hot()) { | |
407 // Do not inline the warm calls. | |
408 wci = *(WarmCallInfo::always_cold()); | |
409 } | |
410 } | |
411 | |
412 if (!wci.is_cold()) { | |
413 // In -UseOldInlining, the failure_msg may also be a success message. | |
414 if (failure_msg == NULL) failure_msg = "inline (hot)"; | |
415 | |
416 // Inline! | |
417 if( PrintInlining ) print_inlining( callee_method, caller_bci, failure_msg); | |
418 if (UseOldInlining) | |
419 build_inline_tree_for_callee(callee_method, jvms, caller_bci); | |
420 if (InlineWarmCalls && !wci.is_hot()) | |
421 return new (C) WarmCallInfo(wci); // copy to heap | |
422 return WarmCallInfo::always_hot(); | |
423 } | |
424 | |
425 // Do not inline | |
426 if (failure_msg == NULL) failure_msg = "too cold to inline"; | |
427 if( PrintInlining ) print_inlining( callee_method, caller_bci, failure_msg); | |
428 return NULL; | |
429 } | |
430 | |
431 //------------------------------compute_callee_frequency----------------------- | |
432 float InlineTree::compute_callee_frequency( int caller_bci ) const { | |
433 int count = method()->interpreter_call_site_count(caller_bci); | |
434 int invcnt = method()->interpreter_invocation_count(); | |
435 float freq = (float)count/(float)invcnt; | |
436 // Call-site count / interpreter invocation count, scaled recursively. | |
437 // Always between 0.0 and 1.0. Represents the percentage of the method's | |
438 // total execution time used at this call site. | |
439 | |
440 return freq; | |
441 } | |
442 | |
443 //------------------------------build_inline_tree_for_callee------------------- | |
444 InlineTree *InlineTree::build_inline_tree_for_callee( ciMethod* callee_method, JVMState* caller_jvms, int caller_bci) { | |
445 float recur_frequency = _site_invoke_ratio * compute_callee_frequency(caller_bci); | |
446 // Attempt inlining. | |
447 InlineTree* old_ilt = callee_at(caller_bci, callee_method); | |
448 if (old_ilt != NULL) { | |
449 return old_ilt; | |
450 } | |
451 InlineTree *ilt = new InlineTree( C, this, callee_method, caller_jvms, caller_bci, recur_frequency ); | |
452 _subtrees.append( ilt ); | |
453 | |
454 NOT_PRODUCT( _count_inlines += 1; ) | |
455 | |
456 return ilt; | |
457 } | |
458 | |
459 | |
460 //---------------------------------------callee_at----------------------------- | |
461 InlineTree *InlineTree::callee_at(int bci, ciMethod* callee) const { | |
462 for (int i = 0; i < _subtrees.length(); i++) { | |
463 InlineTree* sub = _subtrees.at(i); | |
464 if (sub->caller_bci() == bci && callee == sub->method()) { | |
465 return sub; | |
466 } | |
467 } | |
468 return NULL; | |
469 } | |
470 | |
471 | |
472 //------------------------------build_inline_tree_root------------------------- | |
473 InlineTree *InlineTree::build_inline_tree_root() { | |
474 Compile* C = Compile::current(); | |
475 | |
476 // Root of inline tree | |
477 InlineTree *ilt = new InlineTree(C, NULL, C->method(), NULL, -1, 1.0F); | |
478 | |
479 return ilt; | |
480 } | |
481 | |
482 | |
483 //-------------------------find_subtree_from_root----------------------------- | |
484 // Given a jvms, which determines a call chain from the root method, | |
485 // find the corresponding inline tree. | |
486 // Note: This method will be removed or replaced as InlineTree goes away. | |
487 InlineTree* InlineTree::find_subtree_from_root(InlineTree* root, JVMState* jvms, ciMethod* callee, bool create_if_not_found) { | |
488 InlineTree* iltp = root; | |
489 uint depth = jvms && jvms->has_method() ? jvms->depth() : 0; | |
490 for (uint d = 1; d <= depth; d++) { | |
491 JVMState* jvmsp = jvms->of_depth(d); | |
492 // Select the corresponding subtree for this bci. | |
493 assert(jvmsp->method() == iltp->method(), "tree still in sync"); | |
494 ciMethod* d_callee = (d == depth) ? callee : jvms->of_depth(d+1)->method(); | |
495 InlineTree* sub = iltp->callee_at(jvmsp->bci(), d_callee); | |
496 if (!sub) { | |
497 if (create_if_not_found && d == depth) { | |
498 return iltp->build_inline_tree_for_callee(d_callee, jvmsp, jvmsp->bci()); | |
499 } | |
500 assert(sub != NULL, "should be a sub-ilt here"); | |
501 return NULL; | |
502 } | |
503 iltp = sub; | |
504 } | |
505 return iltp; | |
506 } |