244 // zero for the c1 compilation levels in server compilation mode runs |
231 // zero for the c1 compilation levels in server compilation mode runs |
245 // and c2 compilation levels in client compilation mode runs. |
232 // and c2 compilation levels in client compilation mode runs. |
246 // - 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. |
247 // - 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. |
248 // - if neither is defined - always return zero. |
235 // - if neither is defined - always return zero. |
249 int NonTieredCompPolicy::compiler_count(CompLevel comp_level) { |
236 int SimpleCompPolicy::compiler_count(CompLevel comp_level) { |
250 assert(!TieredCompilation, "This policy should not be used with TieredCompilation"); |
237 assert(!TieredCompilation, "This policy should not be used with TieredCompilation"); |
251 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) ||) |
252 is_client_compilation_mode_vm() && is_c1_compile(comp_level)) { |
239 is_client_compilation_mode_vm() && is_c1_compile(comp_level)) { |
253 return _compiler_count; |
240 return _compiler_count; |
254 } |
241 } |
255 return 0; |
242 return 0; |
256 } |
243 } |
257 |
244 |
258 void NonTieredCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) { |
245 void SimpleCompPolicy::reset_counter_for_invocation_event(const methodHandle& m) { |
259 // 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 |
260 // as would be the case for native methods. |
247 // as would be the case for native methods. |
261 |
248 |
262 // 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. |
263 // 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). |
357 } |
344 } |
358 } |
345 } |
359 |
346 |
360 // 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 |
361 // that it's recommended to delay the compilation of this method. |
348 // that it's recommended to delay the compilation of this method. |
362 void NonTieredCompPolicy::delay_compilation(Method* method) { |
349 void SimpleCompPolicy::delay_compilation(Method* method) { |
363 MethodCounters* mcs = method->method_counters(); |
350 MethodCounters* mcs = method->method_counters(); |
364 if (mcs != NULL) { |
351 if (mcs != NULL) { |
365 mcs->invocation_counter()->decay(); |
352 mcs->invocation_counter()->decay(); |
366 mcs->backedge_counter()->decay(); |
353 mcs->backedge_counter()->decay(); |
367 } |
354 } |
368 } |
355 } |
369 |
356 |
370 void NonTieredCompPolicy::disable_compilation(Method* method) { |
357 void SimpleCompPolicy::disable_compilation(Method* method) { |
371 MethodCounters* mcs = method->method_counters(); |
358 MethodCounters* mcs = method->method_counters(); |
372 if (mcs != NULL) { |
359 if (mcs != NULL) { |
373 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
360 mcs->invocation_counter()->set_state(InvocationCounter::wait_for_nothing); |
374 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
361 mcs->backedge_counter()->set_state(InvocationCounter::wait_for_nothing); |
375 } |
362 } |
376 } |
363 } |
377 |
364 |
378 CompileTask* NonTieredCompPolicy::select_task(CompileQueue* compile_queue) { |
365 CompileTask* SimpleCompPolicy::select_task(CompileQueue* compile_queue) { |
379 return select_task_helper(compile_queue); |
366 return select_task_helper(compile_queue); |
380 } |
367 } |
381 |
368 |
382 bool NonTieredCompPolicy::is_mature(Method* method) { |
369 bool SimpleCompPolicy::is_mature(Method* method) { |
383 MethodData* mdo = method->method_data(); |
370 MethodData* mdo = method->method_data(); |
384 assert(mdo != NULL, "Should be"); |
371 assert(mdo != NULL, "Should be"); |
385 uint current = mdo->mileage_of(method); |
372 uint current = mdo->mileage_of(method); |
386 uint initial = mdo->creation_mileage(); |
373 uint initial = mdo->creation_mileage(); |
387 if (current < initial) |
374 if (current < initial) |
517 if (is_compilation_enabled() && can_be_osr_compiled(m, comp_level)) { |
502 if (is_compilation_enabled() && can_be_osr_compiled(m, comp_level)) { |
518 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, CompileTask::Reason_BackedgeCount, thread); |
503 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, CompileTask::Reason_BackedgeCount, thread); |
519 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) |
504 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) |
520 } |
505 } |
521 } |
506 } |
522 // StackWalkCompPolicy - walk up stack to find a suitable method to compile |
|
523 |
|
524 #ifdef COMPILER2 |
|
525 const char* StackWalkCompPolicy::_msg = NULL; |
|
526 |
|
527 |
|
528 // Consider m for compilation |
|
529 void StackWalkCompPolicy::method_invocation_event(const methodHandle& m, JavaThread* thread) { |
|
530 const int comp_level = CompLevel_highest_tier; |
|
531 const int hot_count = m->invocation_count(); |
|
532 reset_counter_for_invocation_event(m); |
|
533 |
|
534 if (is_compilation_enabled() && m->code() == NULL && can_be_compiled(m, comp_level)) { |
|
535 ResourceMark rm(thread); |
|
536 frame fr = thread->last_frame(); |
|
537 assert(fr.is_interpreted_frame(), "must be interpreted"); |
|
538 assert(fr.interpreter_frame_method() == m(), "bad method"); |
|
539 |
|
540 RegisterMap reg_map(thread, false); |
|
541 javaVFrame* triggerVF = thread->last_java_vframe(®_map); |
|
542 // triggerVF is the frame that triggered its counter |
|
543 RFrame* first = new InterpretedRFrame(triggerVF->fr(), thread, m()); |
|
544 |
|
545 if (first->top_method()->code() != NULL) { |
|
546 // called obsolete method/nmethod -- no need to recompile |
|
547 } else { |
|
548 GrowableArray<RFrame*>* stack = new GrowableArray<RFrame*>(50); |
|
549 stack->push(first); |
|
550 RFrame* top = findTopInlinableFrame(stack); |
|
551 assert(top != NULL, "findTopInlinableFrame returned null"); |
|
552 CompileBroker::compile_method(top->top_method(), InvocationEntryBci, comp_level, |
|
553 m, hot_count, CompileTask::Reason_InvocationCount, thread); |
|
554 } |
|
555 } |
|
556 } |
|
557 |
|
558 void StackWalkCompPolicy::method_back_branch_event(const methodHandle& m, int bci, JavaThread* thread) { |
|
559 const int comp_level = CompLevel_highest_tier; |
|
560 const int hot_count = m->backedge_count(); |
|
561 |
|
562 if (is_compilation_enabled() && can_be_osr_compiled(m, comp_level)) { |
|
563 CompileBroker::compile_method(m, bci, comp_level, m, hot_count, CompileTask::Reason_BackedgeCount, thread); |
|
564 NOT_PRODUCT(trace_osr_completion(m->lookup_osr_nmethod_for(bci, comp_level, true));) |
|
565 } |
|
566 } |
|
567 |
|
568 RFrame* StackWalkCompPolicy::findTopInlinableFrame(GrowableArray<RFrame*>* stack) { |
|
569 // go up the stack until finding a frame that (probably) won't be inlined |
|
570 // into its caller |
|
571 RFrame* current = stack->at(0); // current choice for stopping |
|
572 assert( current && !current->is_compiled(), "" ); |
|
573 const char* msg = NULL; |
|
574 |
|
575 while (1) { |
|
576 |
|
577 // before going up the stack further, check if doing so would get us into |
|
578 // compiled code |
|
579 RFrame* next = senderOf(current, stack); |
|
580 if( !next ) // No next frame up the stack? |
|
581 break; // Then compile with current frame |
|
582 |
|
583 Method* m = current->top_method(); |
|
584 Method* next_m = next->top_method(); |
|
585 |
|
586 if( !Inline ) { // Inlining turned off |
|
587 msg = "Inlining turned off"; |
|
588 break; |
|
589 } |
|
590 if (next_m->is_not_compilable()) { // Did fail to compile this before/ |
|
591 msg = "caller not compilable"; |
|
592 break; |
|
593 } |
|
594 if (next->num() > MaxRecompilationSearchLength) { |
|
595 // don't go up too high when searching for recompilees |
|
596 msg = "don't go up any further: > MaxRecompilationSearchLength"; |
|
597 break; |
|
598 } |
|
599 if (next->distance() > MaxInterpretedSearchLength) { |
|
600 // don't go up too high when searching for recompilees |
|
601 msg = "don't go up any further: next > MaxInterpretedSearchLength"; |
|
602 break; |
|
603 } |
|
604 // Compiled frame above already decided not to inline; |
|
605 // do not recompile him. |
|
606 if (next->is_compiled()) { |
|
607 msg = "not going up into optimized code"; |
|
608 break; |
|
609 } |
|
610 |
|
611 // Interpreted frame above us was already compiled. Do not force |
|
612 // a recompile, although if the frame above us runs long enough an |
|
613 // OSR might still happen. |
|
614 if( current->is_interpreted() && next_m->has_compiled_code() ) { |
|
615 msg = "not going up -- already compiled caller"; |
|
616 break; |
|
617 } |
|
618 |
|
619 // Compute how frequent this call site is. We have current method 'm'. |
|
620 // We know next method 'next_m' is interpreted. Find the call site and |
|
621 // check the various invocation counts. |
|
622 int invcnt = 0; // Caller counts |
|
623 if (ProfileInterpreter) { |
|
624 invcnt = next_m->interpreter_invocation_count(); |
|
625 } |
|
626 int cnt = 0; // Call site counts |
|
627 if (ProfileInterpreter && next_m->method_data() != NULL) { |
|
628 ResourceMark rm; |
|
629 int bci = next->top_vframe()->bci(); |
|
630 ProfileData* data = next_m->method_data()->bci_to_data(bci); |
|
631 if (data != NULL && data->is_CounterData()) |
|
632 cnt = data->as_CounterData()->count(); |
|
633 } |
|
634 |
|
635 // Caller counts / call-site counts; i.e. is this call site |
|
636 // a hot call site for method next_m? |
|
637 int freq = (invcnt) ? cnt/invcnt : cnt; |
|
638 |
|
639 // Check size and frequency limits |
|
640 if ((msg = shouldInline(m, freq, cnt)) != NULL) { |
|
641 break; |
|
642 } |
|
643 // Check inlining negative tests |
|
644 if ((msg = shouldNotInline(m)) != NULL) { |
|
645 break; |
|
646 } |
|
647 |
|
648 |
|
649 // If the caller method is too big or something then we do not want to |
|
650 // compile it just to inline a method |
|
651 if (!can_be_compiled(next_m, CompLevel_any)) { |
|
652 msg = "caller cannot be compiled"; |
|
653 break; |
|
654 } |
|
655 |
|
656 if( next_m->name() == vmSymbols::class_initializer_name() ) { |
|
657 msg = "do not compile class initializer (OSR ok)"; |
|
658 break; |
|
659 } |
|
660 |
|
661 current = next; |
|
662 } |
|
663 |
|
664 assert( !current || !current->is_compiled(), "" ); |
|
665 |
|
666 return current; |
|
667 } |
|
668 |
|
669 RFrame* StackWalkCompPolicy::senderOf(RFrame* rf, GrowableArray<RFrame*>* stack) { |
|
670 RFrame* sender = rf->caller(); |
|
671 if (sender && sender->num() == stack->length()) stack->push(sender); |
|
672 return sender; |
|
673 } |
|
674 |
|
675 |
|
676 const char* StackWalkCompPolicy::shouldInline(const methodHandle& m, float freq, int cnt) { |
|
677 // Allows targeted inlining |
|
678 // positive filter: should send be inlined? returns NULL (--> yes) |
|
679 // or rejection msg |
|
680 int max_size = MaxInlineSize; |
|
681 int cost = m->code_size(); |
|
682 |
|
683 // Check for too many throws (and not too huge) |
|
684 if (m->interpreter_throwout_count() > InlineThrowCount && cost < InlineThrowMaxSize ) { |
|
685 return NULL; |
|
686 } |
|
687 |
|
688 // bump the max size if the call is frequent |
|
689 if ((freq >= InlineFrequencyRatio) || (cnt >= InlineFrequencyCount)) { |
|
690 if (TraceFrequencyInlining) { |
|
691 tty->print("(Inlined frequent method)\n"); |
|
692 m->print(); |
|
693 } |
|
694 max_size = FreqInlineSize; |
|
695 } |
|
696 if (cost > max_size) { |
|
697 return (_msg = "too big"); |
|
698 } |
|
699 return NULL; |
|
700 } |
|
701 |
|
702 |
|
703 const char* StackWalkCompPolicy::shouldNotInline(const methodHandle& m) { |
|
704 // negative filter: should send NOT be inlined? returns NULL (--> inline) or rejection msg |
|
705 if (m->is_abstract()) return (_msg = "abstract method"); |
|
706 // note: we allow ik->is_abstract() |
|
707 if (!m->method_holder()->is_initialized()) return (_msg = "method holder not initialized"); |
|
708 if (m->is_native()) return (_msg = "native method"); |
|
709 CompiledMethod* m_code = m->code(); |
|
710 if (m_code != NULL && m_code->code_size() > InlineSmallCode) |
|
711 return (_msg = "already compiled into a big method"); |
|
712 |
|
713 // use frequency-based objections only for non-trivial methods |
|
714 if (m->code_size() <= MaxTrivialSize) return NULL; |
|
715 if (UseInterpreter) { // don't use counts with -Xcomp |
|
716 if ((m->code() == NULL) && m->was_never_executed()) return (_msg = "never executed"); |
|
717 if (!m->was_executed_more_than(MIN2(MinInliningThreshold, CompileThreshold >> 1))) return (_msg = "executed < MinInliningThreshold times"); |
|
718 } |
|
719 if (Method::has_unloaded_classes_in_signature(m, JavaThread::current())) return (_msg = "unloaded signature classes"); |
|
720 |
|
721 return NULL; |
|
722 } |
|
723 |
|
724 |
|
725 |
|
726 #endif // COMPILER2 |
|