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