189 #endif |
189 #endif |
190 return compile_queue->first(); |
190 return compile_queue->first(); |
191 } |
191 } |
192 |
192 |
193 #ifndef PRODUCT |
193 #ifndef PRODUCT |
194 void NonTieredCompPolicy::trace_osr_completion(nmethod* osr_nm) { |
194 void SimpleCompPolicy::trace_osr_completion(nmethod* osr_nm) { |
195 if (TraceOnStackReplacement) { |
195 if (TraceOnStackReplacement) { |
196 if (osr_nm == NULL) tty->print_cr("compilation failed"); |
196 if (osr_nm == NULL) tty->print_cr("compilation failed"); |
197 else tty->print_cr("nmethod " INTPTR_FORMAT, p2i(osr_nm)); |
197 else tty->print_cr("nmethod " INTPTR_FORMAT, p2i(osr_nm)); |
198 } |
198 } |
199 } |
199 } |
200 #endif // !PRODUCT |
200 #endif // !PRODUCT |
201 |
201 |
202 void NonTieredCompPolicy::initialize() { |
202 void SimpleCompPolicy::initialize() { |
203 // Setup the compiler thread numbers |
203 // Setup the compiler thread numbers |
204 if (CICompilerCountPerCPU) { |
204 if (CICompilerCountPerCPU) { |
205 // Example: if CICompilerCountPerCPU is true, then we get |
205 // Example: if CICompilerCountPerCPU is true, then we get |
206 // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine. |
206 // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine. |
207 // May help big-app startup time. |
207 // May help big-app startup time. |
231 // zero for the c1 compilation levels in server compilation mode runs |
231 // zero for the c1 compilation levels in server compilation mode runs |
232 // and c2 compilation levels in client compilation mode runs. |
232 // and c2 compilation levels in client compilation mode runs. |
233 // - with COMPILER2 not defined it should return zero for c2 compilation levels. |
233 // - with COMPILER2 not defined it should return zero for c2 compilation levels. |
234 // - with COMPILER1 not defined it should return zero for c1 compilation levels. |
234 // - with COMPILER1 not defined it should return zero for c1 compilation levels. |
235 // - if neither is defined - always return zero. |
235 // - if neither is defined - always return zero. |
236 int NonTieredCompPolicy::compiler_count(CompLevel comp_level) { |
236 int SimpleCompPolicy::compiler_count(CompLevel comp_level) { |
237 assert(!TieredCompilation, "This policy should not be used with TieredCompilation"); |
237 assert(!TieredCompilation, "This policy should not be used with TieredCompilation"); |
238 if (COMPILER2_PRESENT(is_server_compilation_mode_vm() && is_c2_compile(comp_level) ||) |
238 if (COMPILER2_PRESENT(is_server_compilation_mode_vm() && is_c2_compile(comp_level) ||) |
239 is_client_compilation_mode_vm() && is_c1_compile(comp_level)) { |
239 is_client_compilation_mode_vm() && is_c1_compile(comp_level)) { |
240 return _compiler_count; |
240 return _compiler_count; |
241 } |
241 } |
242 return 0; |
242 return 0; |
243 } |
243 } |
244 |
244 |
245 void NonTieredCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) { |
245 void SimpleCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) { |
246 // Make sure invocation and backedge counter doesn't overflow again right away |
246 // Make sure invocation and backedge counter doesn't overflow again right away |
247 // as would be the case for native methods. |
247 // as would be the case for native methods. |
248 |
248 |
249 // BUT also make sure the method doesn't look like it was never executed. |
249 // BUT also make sure the method doesn't look like it was never executed. |
250 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). |
250 // Set carry bit and reduce counter's value to min(count, CompileThreshold/2). |
254 mcs->backedge_counter()->set_carry(); |
254 mcs->backedge_counter()->set_carry(); |
255 |
255 |
256 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); |
256 assert(!m->was_never_executed(), "don't reset to 0 -- could be mistaken for never-executed"); |
257 } |
257 } |
258 |
258 |
259 void NonTieredCompPolicy::reset_counter_for_back_branch_event(const methodHandle& m) { |
259 void SimpleCompPolicy::reset_counter_for_back_branch_event(const methodHandle& m) { |
260 // Delay next back-branch event but pump up invocation counter to trigger |
260 // Delay next back-branch event but pump up invocation counter to trigger |
261 // whole method compilation. |
261 // whole method compilation. |
262 MethodCounters* mcs = m->method_counters(); |
262 MethodCounters* mcs = m->method_counters(); |
263 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
263 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
264 InvocationCounter* i = mcs->invocation_counter(); |
264 InvocationCounter* i = mcs->invocation_counter(); |
312 } |
312 } |
313 } |
313 } |
314 } |
314 } |
315 |
315 |
316 // Called at the end of the safepoint |
316 // Called at the end of the safepoint |
317 void NonTieredCompPolicy::do_safepoint_work() { |
317 void SimpleCompPolicy::do_safepoint_work() { |
318 if(UseCounterDecay && CounterDecay::is_decay_needed()) { |
318 if(UseCounterDecay && CounterDecay::is_decay_needed()) { |
319 CounterDecay::decay(); |
319 CounterDecay::decay(); |
320 } |
320 } |
321 } |
321 } |
322 |
322 |
323 void NonTieredCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
323 void SimpleCompPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) { |
324 ScopeDesc* sd = trap_scope; |
324 ScopeDesc* sd = trap_scope; |
325 MethodCounters* mcs; |
325 MethodCounters* mcs; |
326 InvocationCounter* c; |
326 InvocationCounter* c; |
327 for (; !sd->is_top(); sd = sd->sender()) { |
327 for (; !sd->is_top(); sd = sd->sender()) { |
328 mcs = sd->method()->method_counters(); |
328 mcs = sd->method()->method_counters(); |
344 } |
344 } |
345 } |
345 } |
346 |
346 |
347 // This method can be called by any component of the runtime to notify the policy |
347 // This method can be called by any component of the runtime to notify the policy |
348 // that it's recommended to delay the compilation of this method. |
348 // that it's recommended to delay the compilation of this method. |
349 void NonTieredCompPolicy::delay_compilation(Method* method) { |
349 void SimpleCompPolicy::delay_compilation(Method* method) { |
350 MethodCounters* mcs = method->method_counters(); |
350 MethodCounters* mcs = method->method_counters(); |
351 if (mcs != NULL) { |
351 if (mcs != NULL) { |
352 mcs->invocation_counter()->decay(); |
352 mcs->invocation_counter()->decay(); |
353 mcs->backedge_counter()->decay(); |
353 mcs->backedge_counter()->decay(); |
354 } |
354 } |
355 } |
355 } |
356 |
356 |
357 void NonTieredCompPolicy::disable_compilation(Method* method) { |
357 void SimpleCompPolicy::disable_compilation(Method* method) { |
358 MethodCounters* mcs = method->method_counters(); |
358 MethodCounters* mcs = method->method_counters(); |
359 if (mcs != NULL) { |
359 if (mcs != NULL) { |
360 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
360 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
361 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
361 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
362 } |
362 } |
363 } |
363 } |
364 |
364 |
365 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
365 CompileTask* SimpleCompPolicy::select_task(CompileQueue* compile_queue) { |
366 return select_task_helper(compile_queue); |
366 return select_task_helper(compile_queue); |
367 } |
367 } |
368 |
368 |
369 bool NonTieredCompPolicy::is_mature(Method* method) { |
369 bool SimpleCompPolicy::is_mature(Method* method) { |
370 MethodData* mdo = method->method_data(); |
370 MethodData* mdo = method->method_data(); |
371 assert(mdo != NULL, "Should be"); |
371 assert(mdo != NULL, "Should be"); |
372 uint current = mdo->mileage_of(method); |
372 uint current = mdo->mileage_of(method); |
373 uint initial = mdo->creation_mileage(); |
373 uint initial = mdo->creation_mileage(); |
374 if (current < initial) |
374 if (current < initial) |
379 else |
379 else |
380 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 ); |
380 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 ); |
381 return (current >= initial + target); |
381 return (current >= initial + target); |
382 } |
382 } |
383 |
383 |
384 nmethod* NonTieredCompPolicy::event(const methodHandle& method, const methodHandle& inlinee, int branch_bci, |
384 nmethod* SimpleCompPolicy::event(const methodHandle& method, const methodHandle& inlinee, int branch_bci, |
385 int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread) { |
385 int bci, CompLevel comp_level, CompiledMethod* nm, JavaThread* thread) { |
386 assert(comp_level == CompLevel_none, "This should be only called from the interpreter"); |
386 assert(comp_level == CompLevel_none, "This should be only called from the interpreter"); |
387 NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci)); |
387 NOT_PRODUCT(trace_frequency_counter_overflow(method, branch_bci, bci)); |
388 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) { |
388 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) { |
389 // If certain JVMTI events (e.g. frame pop event) are requested then the |
389 // If certain JVMTI events (e.g. frame pop event) are requested then the |
438 } |
438 } |
439 return NULL; |
439 return NULL; |
440 } |
440 } |
441 |
441 |
442 #ifndef PRODUCT |
442 #ifndef PRODUCT |
443 void NonTieredCompPolicy::trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci) { |
443 void SimpleCompPolicy::trace_frequency_counter_overflow(const methodHandle& m, int branch_bci, int bci) { |
444 if (TraceInvocationCounterOverflow) { |
444 if (TraceInvocationCounterOverflow) { |
445 MethodCounters* mcs = m->method_counters(); |
445 MethodCounters* mcs = m->method_counters(); |
446 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
446 assert(mcs != NULL, "MethodCounters cannot be NULL for profiling"); |
447 InvocationCounter* ic = mcs->invocation_counter(); |
447 InvocationCounter* ic = mcs->invocation_counter(); |
448 InvocationCounter* bc = mcs->backedge_counter(); |
448 InvocationCounter* bc = mcs->backedge_counter(); |
470 } |
470 } |
471 } |
471 } |
472 } |
472 } |
473 } |
473 } |
474 |
474 |
475 void NonTieredCompPolicy::trace_osr_request(const methodHandle& method, nmethod* osr, int bci) { |
475 void SimpleCompPolicy::trace_osr_request(const methodHandle& method, nmethod* osr, int bci) { |
476 if (TraceOnStackReplacement) { |
476 if (TraceOnStackReplacement) { |
477 ResourceMark rm; |
477 ResourceMark rm; |
478 tty->print(osr != NULL ? "Reused OSR entry for " : "Requesting OSR entry for "); |
478 tty->print(osr != NULL ? "Reused OSR entry for " : "Requesting OSR entry for "); |
479 method->print_short_name(tty); |
479 method->print_short_name(tty); |
480 tty->print_cr(" at bci %d", bci); |
480 tty->print_cr(" at bci %d", bci); |
481 } |
481 } |
482 } |
482 } |
483 #endif // !PRODUCT |
483 #endif // !PRODUCT |
484 |
484 |
485 // SimpleCompPolicy - compile current method |
|
486 |
|
487 void SimpleCompPolicy::method_invocation_event(const methodHandle& m, JavaThread* thread) { |
485 void SimpleCompPolicy::method_invocation_event(const methodHandle& m, JavaThread* thread) { |
488 const int comp_level = CompLevel_highest_tier; |
486 const int comp_level = CompLevel_highest_tier; |
489 const int hot_count = m->invocation_count(); |
487 const int hot_count = m->invocation_count(); |
490 reset_counter_for_invocation_event(m); |
488 reset_counter_for_invocation_event(m); |
491 |
489 |