Mercurial > hg > truffle
annotate src/share/vm/runtime/compilationPolicy.cpp @ 1821:df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
Summary: Fixed NonTieredCompPolicy::compiler_count() to return correct thread count.
Reviewed-by: twisti, kvn
author | iveresov |
---|---|
date | Mon, 27 Sep 2010 15:04:40 -0700 |
parents | d5d065957597 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1202
diff
changeset
|
2 * Copyright (c) 2000, 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:
1202
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1202
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:
1202
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_compilationPolicy.cpp.incl" | |
27 | |
28 CompilationPolicy* CompilationPolicy::_policy; | |
29 elapsedTimer CompilationPolicy::_accumulated_time; | |
30 bool CompilationPolicy::_in_vm_startup; | |
31 | |
32 // Determine compilation policy based on command line argument | |
33 void compilationPolicy_init() { | |
34 CompilationPolicy::set_in_vm_startup(DelayCompilationDuringStartup); | |
35 | |
36 switch(CompilationPolicyChoice) { | |
37 case 0: | |
38 CompilationPolicy::set_policy(new SimpleCompPolicy()); | |
39 break; | |
40 | |
41 case 1: | |
42 #ifdef COMPILER2 | |
43 CompilationPolicy::set_policy(new StackWalkCompPolicy()); | |
44 #else | |
45 Unimplemented(); | |
46 #endif | |
47 break; | |
1783 | 48 case 2: |
49 #ifdef TIERED | |
50 CompilationPolicy::set_policy(new SimpleThresholdPolicy()); | |
51 #else | |
52 Unimplemented(); | |
53 #endif | |
54 break; | |
0 | 55 default: |
1783 | 56 fatal("CompilationPolicyChoice must be in the range: [0-2]"); |
0 | 57 } |
1783 | 58 CompilationPolicy::policy()->initialize(); |
0 | 59 } |
60 | |
61 void CompilationPolicy::completed_vm_startup() { | |
62 if (TraceCompilationPolicy) { | |
63 tty->print("CompilationPolicy: completed vm startup.\n"); | |
64 } | |
65 _in_vm_startup = false; | |
66 } | |
67 | |
68 // Returns true if m must be compiled before executing it | |
69 // This is intended to force compiles for methods (usually for | |
70 // debugging) that would otherwise be interpreted for some reason. | |
1783 | 71 bool CompilationPolicy::must_be_compiled(methodHandle m, int comp_level) { |
0 | 72 if (m->has_compiled_code()) return false; // already compiled |
1783 | 73 if (!can_be_compiled(m, comp_level)) return false; |
0 | 74 |
75 return !UseInterpreter || // must compile all methods | |
1202 | 76 (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods |
0 | 77 } |
78 | |
79 // Returns true if m is allowed to be compiled | |
1783 | 80 bool CompilationPolicy::can_be_compiled(methodHandle m, int comp_level) { |
0 | 81 if (m->is_abstract()) return false; |
82 if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false; | |
83 | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
84 // Math intrinsics should never be compiled as this can lead to |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
85 // monotonicity problems because the interpreter will prefer the |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
86 // compiled code to the intrinsic version. This can't happen in |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
87 // production because the invocation counter can't be incremented |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
88 // but we shouldn't expose the system to this problem in testing |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
89 // modes. |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
90 if (!AbstractInterpreter::can_be_compiled(m)) { |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
91 return false; |
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
92 } |
1783 | 93 if (comp_level == CompLevel_all) { |
94 return !m->is_not_compilable(CompLevel_simple) && !m->is_not_compilable(CompLevel_full_optimization); | |
95 } else { | |
96 return !m->is_not_compilable(comp_level); | |
97 } | |
98 } | |
1174
ddb7834449d0
6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents:
0
diff
changeset
|
99 |
1783 | 100 bool CompilationPolicy::is_compilation_enabled() { |
101 // NOTE: CompileBroker::should_compile_new_jobs() checks for UseCompiler | |
102 return !delay_compilation_during_startup() && CompileBroker::should_compile_new_jobs(); | |
0 | 103 } |
104 | |
105 #ifndef PRODUCT | |
106 void CompilationPolicy::print_time() { | |
107 tty->print_cr ("Accumulated compilationPolicy times:"); | |
108 tty->print_cr ("---------------------------"); | |
109 tty->print_cr (" Total: %3.3f sec.", _accumulated_time.seconds()); | |
110 } | |
111 | |
1783 | 112 void NonTieredCompPolicy::trace_osr_completion(nmethod* osr_nm) { |
0 | 113 if (TraceOnStackReplacement) { |
114 if (osr_nm == NULL) tty->print_cr("compilation failed"); | |
115 else tty->print_cr("nmethod " INTPTR_FORMAT, osr_nm); | |
116 } | |
117 } | |
118 #endif // !PRODUCT | |
119 | |
1783 | 120 void NonTieredCompPolicy::initialize() { |
121 // Setup the compiler thread numbers | |
122 if (CICompilerCountPerCPU) { | |
123 // Example: if CICompilerCountPerCPU is true, then we get | |
124 // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine. | |
125 // May help big-app startup time. | |
126 _compiler_count = MAX2(log2_intptr(os::active_processor_count())-1,1); | |
127 } else { | |
128 _compiler_count = CICompilerCount; | |
129 } | |
130 } | |
131 | |
1821
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
132 // Note: this policy is used ONLY if TieredCompilation is off. |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
133 // compiler_count() behaves the following way: |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
134 // - with TIERED build (with both COMPILER1 and COMPILER2 defined) it should return |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
135 // zero for the c1 compilation levels, hence the particular ordering of the |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
136 // statements. |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
137 // - the same should happen when COMPILER2 is defined and COMPILER1 is not |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
138 // (server build without TIERED defined). |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
139 // - if only COMPILER1 is defined (client build), zero should be returned for |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
140 // the c2 level. |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
141 // - if neither is defined - always return zero. |
1783 | 142 int NonTieredCompPolicy::compiler_count(CompLevel comp_level) { |
1821
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
143 assert(!TieredCompilation, "This policy should not be used with TieredCompilation"); |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
144 #ifdef COMPILER2 |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
145 if (is_c2_compile(comp_level)) { |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
146 return _compiler_count; |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
147 } else { |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
148 return 0; |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
149 } |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
150 #endif |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
151 |
1783 | 152 #ifdef COMPILER1 |
153 if (is_c1_compile(comp_level)) { | |
154 return _compiler_count; | |
1821
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
155 } else { |
df015ec64052
6987115: Non-tiered compilation policy creates unnecessary C1 threads
iveresov
parents:
1783
diff
changeset
|
156 return 0; |
1783 | 157 } |
158 #endif | |
159 | |
160 return 0; | |
161 } | |
162 | |
163 void NonTieredCompPolicy::reset_counter_for_invocation_event(methodHandle m) { | |
0 | 164 // Make sure invocation and backedge counter doesn't overflow again right away |
165 // as would be the case for native methods. | |
166 | |
167 // BUT also make sure the method doesn't look like it was never executed. | |
168 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). | |
169 m->invocation_counter()->set_carry(); | |
170 m->backedge_counter()->set_carry(); | |
171 | |
172 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); | |
173 } | |
174 | |
1783 | 175 void NonTieredCompPolicy::reset_counter_for_back_branch_event(methodHandle m) { |
0 | 176 // Delay next back-branch event but pump up invocation counter to triger |
177 // whole method compilation. | |
178 InvocationCounter* i = m->invocation_counter(); | |
179 InvocationCounter* b = m->backedge_counter(); | |
180 | |
181 // Don't set invocation_counter's value too low otherwise the method will | |
182 // look like immature (ic < ~5300) which prevents the inlining based on | |
183 // the type profiling. | |
184 i->set(i->state(), CompileThreshold); | |
185 // Don't reset counter too low - it is used to check if OSR method is ready. | |
186 b->set(b->state(), CompileThreshold / 2); | |
187 } | |
188 | |
1783 | 189 // |
190 // CounterDecay | |
191 // | |
192 // Interates through invocation counters and decrements them. This | |
193 // is done at each safepoint. | |
194 // | |
195 class CounterDecay : public AllStatic { | |
196 static jlong _last_timestamp; | |
197 static void do_method(methodOop m) { | |
198 m->invocation_counter()->decay(); | |
199 } | |
200 public: | |
201 static void decay(); | |
202 static bool is_decay_needed() { | |
203 return (os::javaTimeMillis() - _last_timestamp) > CounterDecayMinIntervalLength; | |
204 } | |
205 }; | |
206 | |
207 jlong CounterDecay::_last_timestamp = 0; | |
208 | |
209 void CounterDecay::decay() { | |
210 _last_timestamp = os::javaTimeMillis(); | |
211 | |
212 // This operation is going to be performed only at the end of a safepoint | |
213 // and hence GC's will not be going on, all Java mutators are suspended | |
214 // at this point and hence SystemDictionary_lock is also not needed. | |
215 assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint"); | |
216 int nclasses = SystemDictionary::number_of_classes(); | |
217 double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 / | |
218 CounterHalfLifeTime); | |
219 for (int i = 0; i < classes_per_tick; i++) { | |
220 klassOop k = SystemDictionary::try_get_next_class(); | |
221 if (k != NULL && k->klass_part()->oop_is_instance()) { | |
222 instanceKlass::cast(k)->methods_do(do_method); | |
223 } | |
224 } | |
225 } | |
226 | |
227 // Called at the end of the safepoint | |
228 void NonTieredCompPolicy::do_safepoint_work() { | |
229 if(UseCounterDecay && CounterDecay::is_decay_needed()) { | |
230 CounterDecay::decay(); | |
231 } | |
232 } | |
233 | |
234 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { | |
235 ScopeDesc* sd = trap_scope; | |
236 for (; !sd->is_top(); sd = sd->sender()) { | |
237 // Reset ICs of inlined methods, since they can trigger compilations also. | |
238 sd->method()->invocation_counter()->reset(); | |
239 } | |
240 InvocationCounter* c = sd->method()->invocation_counter(); | |
241 if (is_osr) { | |
242 // It was an OSR method, so bump the count higher. | |
243 c->set(c->state(), CompileThreshold); | |
244 } else { | |
245 c->reset(); | |
246 } | |
247 sd->method()->backedge_counter()->reset(); | |
248 } | |
249 | |
250 // This method can be called by any component of the runtime to notify the policy | |
251 // that it's recommended to delay the complation of this method. | |
252 void NonTieredCompPolicy::delay_compilation(methodOop method) { | |
253 method->invocation_counter()->decay(); | |
254 method->backedge_counter()->decay(); | |
255 } | |
256 | |
257 void NonTieredCompPolicy::disable_compilation(methodOop method) { | |
258 method->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); | |
259 method->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); | |
260 } | |
261 | |
262 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { | |
263 return compile_queue->first(); | |
264 } | |
265 | |
266 bool NonTieredCompPolicy::is_mature(methodOop method) { | |
267 methodDataOop mdo = method->method_data(); | |
268 assert(mdo != NULL, "Should be"); | |
269 uint current = mdo->mileage_of(method); | |
270 uint initial = mdo->creation_mileage(); | |
271 if (current < initial) | |
272 return true; // some sort of overflow | |
273 uint target; | |
274 if (ProfileMaturityPercentage <= 0) | |
275 target = (uint) -ProfileMaturityPercentage; // absolute value | |
276 else | |
277 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 ); | |
278 return (current >= initial + target); | |
279 } | |
280 | |
281 nmethod* NonTieredCompPolicy::event(methodHandle method, methodHandle inlinee, int branch_bci, int bci, CompLevel comp_level, TRAPS) { | |
282 assert(comp_level == CompLevel_none, "This should be only called from the interpreter"); | |
283 NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci)); | |
284 if (JvmtiExport::can_post_interpreter_events()) { | |
285 assert(THREAD->is_Java_thread(), "Wrong type of thread"); | |
286 if (((JavaThread*)THREAD)->is_interp_only_mode()) { | |
287 // If certain JVMTI events (e.g. frame pop event) are requested then the | |
288 // thread is forced to remain in interpreted code. This is | |
289 // implemented partly by a check in the run_compiled_code | |
290 // section of the interpreter whether we should skip running | |
291 // compiled code, and partly by skipping OSR compiles for | |
292 // interpreted-only threads. | |
293 if (bci != InvocationEntryBci) { | |
294 reset_counter_for_back_branch_event(method); | |
295 return NULL; | |
296 } | |
297 } | |
298 } | |
299 if (bci == InvocationEntryBci) { | |
300 // when code cache is full, compilation gets switched off, UseCompiler | |
301 // is set to false | |
302 if (!method->has_compiled_code() && UseCompiler) { | |
303 method_invocation_event(method, CHECK_NULL); | |
304 } else { | |
305 // Force counter overflow on method entry, even if no compilation | |
306 // happened. (The method_invocation_event call does this also.) | |
307 reset_counter_for_invocation_event(method); | |
308 } | |
309 // compilation at an invocation overflow no longer goes and retries test for | |
310 // compiled method. We always run the loser of the race as interpreted. | |
311 // so return NULL | |
312 return NULL; | |
313 } else { | |
314 // counter overflow in a loop => try to do on-stack-replacement | |
315 nmethod* osr_nm = method->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true); | |
316 NOT_PRODUCT(trace_osr_request(method, osr_nm, bci)); | |
317 // when code cache is full, we should not compile any more... | |
318 if (osr_nm == NULL && UseCompiler) { | |
319 method_back_branch_event(method, bci, CHECK_NULL); | |
320 osr_nm = method->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true); | |
321 } | |
322 if (osr_nm == NULL) { | |
323 reset_counter_for_back_branch_event(method); | |
324 return NULL; | |
325 } | |
326 return osr_nm; | |
327 } | |
328 return NULL; | |
329 } | |
330 | |
331 #ifndef PRODUCT | |
332 void NonTieredCompPolicy::trace_frequency_counter_overflow(methodHandle m, int branch_bci, int bci) { | |
333 if (TraceInvocationCounterOverflow) { | |
334 InvocationCounter* ic = m->invocation_counter(); | |
335 InvocationCounter* bc = m->backedge_counter(); | |
336 ResourceMark rm; | |
337 const char* msg = | |
338 bci == InvocationEntryBci | |
339 ? "comp-policy cntr ovfl @ %d in entry of " | |
340 : "comp-policy cntr ovfl @ %d in loop of "; | |
341 tty->print(msg, bci); | |
342 m->print_value(); | |
343 tty->cr(); | |
344 ic->print(); | |
345 bc->print(); | |
346 if (ProfileInterpreter) { | |
347 if (bci != InvocationEntryBci) { | |
348 methodDataOop mdo = m->method_data(); | |
349 if (mdo != NULL) { | |
350 int count = mdo->bci_to_data(branch_bci)->as_JumpData()->taken(); | |
351 tty->print_cr("back branch count = %d", count); | |
352 } | |
353 } | |
354 } | |
355 } | |
356 } | |
357 | |
358 void NonTieredCompPolicy::trace_osr_request(methodHandle method, nmethod* osr, int bci) { | |
359 if (TraceOnStackReplacement) { | |
360 ResourceMark rm; | |
361 tty->print(osr != NULL ? "Reused OSR entry for " : "Requesting OSR entry for "); | |
362 method->print_short_name(tty); | |
363 tty->print_cr(" at bci %d", bci); | |
364 } | |
365 } | |
366 #endif // !PRODUCT | |
367 | |
0 | 368 // SimpleCompPolicy - compile current method |
369 | |
370 void SimpleCompPolicy::method_invocation_event( methodHandle m, TRAPS) { | |
371 assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); | |
372 | |
373 int hot_count = m->invocation_count(); | |
374 reset_counter_for_invocation_event(m); | |
375 const char* comment = "count"; | |
376 | |
1783 | 377 if (is_compilation_enabled() && can_be_compiled(m)) { |
0 | 378 nmethod* nm = m->code(); |
379 if (nm == NULL ) { | |
380 const char* comment = "count"; | |
1783 | 381 CompileBroker::compile_method(m, InvocationEntryBci, CompLevel_highest_tier, |
0 | 382 m, hot_count, comment, CHECK); |
383 } | |
384 } | |
385 } | |
386 | |
1783 | 387 void SimpleCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) { |
0 | 388 assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); |
389 | |
390 int hot_count = m->backedge_count(); | |
391 const char* comment = "backedge_count"; | |
392 | |
1783 | 393 if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) { |
394 CompileBroker::compile_method(m, bci, CompLevel_highest_tier, | |
395 m, hot_count, comment, CHECK); | |
396 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));) | |
0 | 397 } |
398 } | |
399 // StackWalkCompPolicy - walk up stack to find a suitable method to compile | |
400 | |
401 #ifdef COMPILER2 | |
402 const char* StackWalkCompPolicy::_msg = NULL; | |
403 | |
404 | |
405 // Consider m for compilation | |
406 void StackWalkCompPolicy::method_invocation_event(methodHandle m, TRAPS) { | |
407 assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); | |
408 | |
409 int hot_count = m->invocation_count(); | |
410 reset_counter_for_invocation_event(m); | |
411 const char* comment = "count"; | |
412 | |
1783 | 413 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m)) { |
0 | 414 ResourceMark rm(THREAD); |
415 JavaThread *thread = (JavaThread*)THREAD; | |
416 frame fr = thread->last_frame(); | |
417 assert(fr.is_interpreted_frame(), "must be interpreted"); | |
418 assert(fr.interpreter_frame_method() == m(), "bad method"); | |
419 | |
420 if (TraceCompilationPolicy) { | |
421 tty->print("method invocation trigger: "); | |
422 m->print_short_name(tty); | |
423 tty->print(" ( interpreted " INTPTR_FORMAT ", size=%d ) ", (address)m(), m->code_size()); | |
424 } | |
425 RegisterMap reg_map(thread, false); | |
426 javaVFrame* triggerVF = thread->last_java_vframe(®_map); | |
427 // triggerVF is the frame that triggered its counter | |
428 RFrame* first = new InterpretedRFrame(triggerVF->fr(), thread, m); | |
429 | |
430 if (first->top_method()->code() != NULL) { | |
431 // called obsolete method/nmethod -- no need to recompile | |
432 if (TraceCompilationPolicy) tty->print_cr(" --> " INTPTR_FORMAT, first->top_method()->code()); | |
433 } else { | |
434 if (TimeCompilationPolicy) accumulated_time()->start(); | |
435 GrowableArray<RFrame*>* stack = new GrowableArray<RFrame*>(50); | |
436 stack->push(first); | |
437 RFrame* top = findTopInlinableFrame(stack); | |
438 if (TimeCompilationPolicy) accumulated_time()->stop(); | |
439 assert(top != NULL, "findTopInlinableFrame returned null"); | |
440 if (TraceCompilationPolicy) top->print(); | |
1783 | 441 CompileBroker::compile_method(top->top_method(), InvocationEntryBci, CompLevel_highest_tier, |
0 | 442 m, hot_count, comment, CHECK); |
443 } | |
444 } | |
445 } | |
446 | |
1783 | 447 void StackWalkCompPolicy::method_back_branch_event(methodHandle m, int bci, TRAPS) { |
0 | 448 assert(UseCompiler || CompileTheWorld, "UseCompiler should be set by now."); |
449 | |
450 int hot_count = m->backedge_count(); | |
451 const char* comment = "backedge_count"; | |
452 | |
1783 | 453 if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) { |
454 CompileBroker::compile_method(m, bci, CompLevel_highest_tier, m, hot_count, comment, CHECK); | |
0 | 455 |
1783 | 456 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, CompLevel_highest_tier, true));) |
0 | 457 } |
458 } | |
459 | |
460 RFrame* StackWalkCompPolicy::findTopInlinableFrame(GrowableArray<RFrame*>* stack) { | |
461 // go up the stack until finding a frame that (probably) won't be inlined | |
462 // into its caller | |
463 RFrame* current = stack->at(0); // current choice for stopping | |
464 assert( current && !current->is_compiled(), "" ); | |
465 const char* msg = NULL; | |
466 | |
467 while (1) { | |
468 | |
469 // before going up the stack further, check if doing so would get us into | |
470 // compiled code | |
471 RFrame* next = senderOf(current, stack); | |
472 if( !next ) // No next frame up the stack? | |
473 break; // Then compile with current frame | |
474 | |
475 methodHandle m = current->top_method(); | |
476 methodHandle next_m = next->top_method(); | |
477 | |
478 if (TraceCompilationPolicy && Verbose) { | |
479 tty->print("[caller: "); | |
480 next_m->print_short_name(tty); | |
481 tty->print("] "); | |
482 } | |
483 | |
484 if( !Inline ) { // Inlining turned off | |
485 msg = "Inlining turned off"; | |
486 break; | |
487 } | |
488 if (next_m->is_not_compilable()) { // Did fail to compile this before/ | |
489 msg = "caller not compilable"; | |
490 break; | |
491 } | |
492 if (next->num() > MaxRecompilationSearchLength) { | |
493 // don't go up too high when searching for recompilees | |
494 msg = "don't go up any further: > MaxRecompilationSearchLength"; | |
495 break; | |
496 } | |
497 if (next->distance() > MaxInterpretedSearchLength) { | |
498 // don't go up too high when searching for recompilees | |
499 msg = "don't go up any further: next > MaxInterpretedSearchLength"; | |
500 break; | |
501 } | |
502 // Compiled frame above already decided not to inline; | |
503 // do not recompile him. | |
504 if (next->is_compiled()) { | |
505 msg = "not going up into optimized code"; | |
506 break; | |
507 } | |
508 | |
509 // Interpreted frame above us was already compiled. Do not force | |
510 // a recompile, although if the frame above us runs long enough an | |
511 // OSR might still happen. | |
512 if( current->is_interpreted() && next_m->has_compiled_code() ) { | |
513 msg = "not going up -- already compiled caller"; | |
514 break; | |
515 } | |
516 | |
517 // Compute how frequent this call site is. We have current method 'm'. | |
518 // We know next method 'next_m' is interpreted. Find the call site and | |
519 // check the various invocation counts. | |
520 int invcnt = 0; // Caller counts | |
521 if (ProfileInterpreter) { | |
522 invcnt = next_m->interpreter_invocation_count(); | |
523 } | |
524 int cnt = 0; // Call site counts | |
525 if (ProfileInterpreter && next_m->method_data() != NULL) { | |
526 ResourceMark rm; | |
527 int bci = next->top_vframe()->bci(); | |
528 ProfileData* data = next_m->method_data()->bci_to_data(bci); | |
529 if (data != NULL && data->is_CounterData()) | |
530 cnt = data->as_CounterData()->count(); | |
531 } | |
532 | |
533 // Caller counts / call-site counts; i.e. is this call site | |
534 // a hot call site for method next_m? | |
535 int freq = (invcnt) ? cnt/invcnt : cnt; | |
536 | |
537 // Check size and frequency limits | |
538 if ((msg = shouldInline(m, freq, cnt)) != NULL) { | |
539 break; | |
540 } | |
541 // Check inlining negative tests | |
542 if ((msg = shouldNotInline(m)) != NULL) { | |
543 break; | |
544 } | |
545 | |
546 | |
547 // If the caller method is too big or something then we do not want to | |
548 // compile it just to inline a method | |
1783 | 549 if (!can_be_compiled(next_m)) { |
0 | 550 msg = "caller cannot be compiled"; |
551 break; | |
552 } | |
553 | |
554 if( next_m->name() == vmSymbols::class_initializer_name() ) { | |
555 msg = "do not compile class initializer (OSR ok)"; | |
556 break; | |
557 } | |
558 | |
559 if (TraceCompilationPolicy && Verbose) { | |
560 tty->print("\n\t check caller: "); | |
561 next_m->print_short_name(tty); | |
562 tty->print(" ( interpreted " INTPTR_FORMAT ", size=%d ) ", (address)next_m(), next_m->code_size()); | |
563 } | |
564 | |
565 current = next; | |
566 } | |
567 | |
568 assert( !current || !current->is_compiled(), "" ); | |
569 | |
570 if (TraceCompilationPolicy && msg) tty->print("(%s)\n", msg); | |
571 | |
572 return current; | |
573 } | |
574 | |
575 RFrame* StackWalkCompPolicy::senderOf(RFrame* rf, GrowableArray<RFrame*>* stack) { | |
576 RFrame* sender = rf->caller(); | |
577 if (sender && sender->num() == stack->length()) stack->push(sender); | |
578 return sender; | |
579 } | |
580 | |
581 | |
582 const char* StackWalkCompPolicy::shouldInline(methodHandle m, float freq, int cnt) { | |
583 // Allows targeted inlining | |
584 // positive filter: should send be inlined? returns NULL (--> yes) | |
585 // or rejection msg | |
586 int max_size = MaxInlineSize; | |
587 int cost = m->code_size(); | |
588 | |
589 // Check for too many throws (and not too huge) | |
590 if (m->interpreter_throwout_count() > InlineThrowCount && cost < InlineThrowMaxSize ) { | |
591 return NULL; | |
592 } | |
593 | |
594 // bump the max size if the call is frequent | |
595 if ((freq >= InlineFrequencyRatio) || (cnt >= InlineFrequencyCount)) { | |
596 if (TraceFrequencyInlining) { | |
597 tty->print("(Inlined frequent method)\n"); | |
598 m->print(); | |
599 } | |
600 max_size = FreqInlineSize; | |
601 } | |
602 if (cost > max_size) { | |
603 return (_msg = "too big"); | |
604 } | |
605 return NULL; | |
606 } | |
607 | |
608 | |
609 const char* StackWalkCompPolicy::shouldNotInline(methodHandle m) { | |
610 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg | |
611 if (m->is_abstract()) return (_msg = "abstract method"); | |
612 // note: we allow ik->is_abstract() | |
613 if (!instanceKlass::cast(m->method_holder())->is_initialized()) return (_msg = "method holder not initialized"); | |
614 if (m->is_native()) return (_msg = "native method"); | |
615 nmethod* m_code = m->code(); | |
1748 | 616 if (m_code != NULL && m_code->code_size() > InlineSmallCode) |
0 | 617 return (_msg = "already compiled into a big method"); |
618 | |
619 // use frequency-based objections only for non-trivial methods | |
620 if (m->code_size() <= MaxTrivialSize) return NULL; | |
621 if (UseInterpreter) { // don't use counts with -Xcomp | |
622 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed"); | |
623 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times"); | |
624 } | |
625 if (methodOopDesc::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes"); | |
626 | |
627 return NULL; | |
628 } | |
629 | |
630 | |
631 | |
632 #endif // COMPILER2 |