35 #include "opto/divnode.hpp" |
35 #include "opto/divnode.hpp" |
36 #include "opto/idealGraphPrinter.hpp" |
36 #include "opto/idealGraphPrinter.hpp" |
37 #include "opto/matcher.hpp" |
37 #include "opto/matcher.hpp" |
38 #include "opto/memnode.hpp" |
38 #include "opto/memnode.hpp" |
39 #include "opto/mulnode.hpp" |
39 #include "opto/mulnode.hpp" |
|
40 #include "opto/opaquenode.hpp" |
40 #include "opto/parse.hpp" |
41 #include "opto/parse.hpp" |
41 #include "opto/runtime.hpp" |
42 #include "opto/runtime.hpp" |
42 #include "runtime/deoptimization.hpp" |
43 #include "runtime/deoptimization.hpp" |
43 #include "runtime/sharedRuntime.hpp" |
44 #include "runtime/sharedRuntime.hpp" |
44 |
45 |
761 profile_ret(target->flow()->start()); |
762 profile_ret(target->flow()->start()); |
762 int pnum = target->next_path_num(); |
763 int pnum = target->next_path_num(); |
763 merge_common(target, pnum); |
764 merge_common(target, pnum); |
764 } |
765 } |
765 |
766 |
|
767 static bool has_injected_profile(BoolTest::mask btest, Node* test, int& taken, int& not_taken) { |
|
768 if (btest != BoolTest::eq && btest != BoolTest::ne) { |
|
769 // Only ::eq and ::ne are supported for profile injection. |
|
770 return false; |
|
771 } |
|
772 if (test->is_Cmp() && |
|
773 test->in(1)->Opcode() == Op_ProfileBoolean) { |
|
774 ProfileBooleanNode* profile = (ProfileBooleanNode*)test->in(1); |
|
775 int false_cnt = profile->false_count(); |
|
776 int true_cnt = profile->true_count(); |
|
777 |
|
778 // Counts matching depends on the actual test operation (::eq or ::ne). |
|
779 // No need to scale the counts because profile injection was designed |
|
780 // to feed exact counts into VM. |
|
781 taken = (btest == BoolTest::eq) ? false_cnt : true_cnt; |
|
782 not_taken = (btest == BoolTest::eq) ? true_cnt : false_cnt; |
|
783 |
|
784 profile->consume(); |
|
785 return true; |
|
786 } |
|
787 return false; |
|
788 } |
766 //--------------------------dynamic_branch_prediction-------------------------- |
789 //--------------------------dynamic_branch_prediction-------------------------- |
767 // Try to gather dynamic branch prediction behavior. Return a probability |
790 // Try to gather dynamic branch prediction behavior. Return a probability |
768 // of the branch being taken and set the "cnt" field. Returns a -1.0 |
791 // of the branch being taken and set the "cnt" field. Returns a -1.0 |
769 // if we need to use static prediction for some reason. |
792 // if we need to use static prediction for some reason. |
770 float Parse::dynamic_branch_prediction(float &cnt) { |
793 float Parse::dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test) { |
771 ResourceMark rm; |
794 ResourceMark rm; |
772 |
795 |
773 cnt = COUNT_UNKNOWN; |
796 cnt = COUNT_UNKNOWN; |
774 |
797 |
775 // Use MethodData information if it is available |
798 int taken = 0; |
776 // FIXME: free the ProfileData structure |
|
777 ciMethodData* methodData = method()->method_data(); |
|
778 if (!methodData->is_mature()) return PROB_UNKNOWN; |
|
779 ciProfileData* data = methodData->bci_to_data(bci()); |
|
780 if (!data->is_JumpData()) return PROB_UNKNOWN; |
|
781 |
|
782 // get taken and not taken values |
|
783 int taken = data->as_JumpData()->taken(); |
|
784 int not_taken = 0; |
799 int not_taken = 0; |
785 if (data->is_BranchData()) { |
800 |
786 not_taken = data->as_BranchData()->not_taken(); |
801 bool use_mdo = !has_injected_profile(btest, test, taken, not_taken); |
787 } |
802 |
788 |
803 if (use_mdo) { |
789 // scale the counts to be commensurate with invocation counts: |
804 // Use MethodData information if it is available |
790 taken = method()->scale_count(taken); |
805 // FIXME: free the ProfileData structure |
791 not_taken = method()->scale_count(not_taken); |
806 ciMethodData* methodData = method()->method_data(); |
|
807 if (!methodData->is_mature()) return PROB_UNKNOWN; |
|
808 ciProfileData* data = methodData->bci_to_data(bci()); |
|
809 if (!data->is_JumpData()) return PROB_UNKNOWN; |
|
810 |
|
811 // get taken and not taken values |
|
812 taken = data->as_JumpData()->taken(); |
|
813 not_taken = 0; |
|
814 if (data->is_BranchData()) { |
|
815 not_taken = data->as_BranchData()->not_taken(); |
|
816 } |
|
817 |
|
818 // scale the counts to be commensurate with invocation counts: |
|
819 taken = method()->scale_count(taken); |
|
820 not_taken = method()->scale_count(not_taken); |
|
821 } |
792 |
822 |
793 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. |
823 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. |
794 // We also check that individual counters are positive first, overwise the sum can become positive. |
824 // We also check that individual counters are positive first, otherwise the sum can become positive. |
795 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { |
825 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { |
796 if (C->log() != NULL) { |
826 if (C->log() != NULL) { |
797 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); |
827 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); |
798 } |
828 } |
799 return PROB_UNKNOWN; |
829 return PROB_UNKNOWN; |
839 } |
869 } |
840 |
870 |
841 //-----------------------------branch_prediction------------------------------- |
871 //-----------------------------branch_prediction------------------------------- |
842 float Parse::branch_prediction(float& cnt, |
872 float Parse::branch_prediction(float& cnt, |
843 BoolTest::mask btest, |
873 BoolTest::mask btest, |
844 int target_bci) { |
874 int target_bci, |
845 float prob = dynamic_branch_prediction(cnt); |
875 Node* test) { |
|
876 float prob = dynamic_branch_prediction(cnt, btest, test); |
846 // If prob is unknown, switch to static prediction |
877 // If prob is unknown, switch to static prediction |
847 if (prob != PROB_UNKNOWN) return prob; |
878 if (prob != PROB_UNKNOWN) return prob; |
848 |
879 |
849 prob = PROB_FAIR; // Set default value |
880 prob = PROB_FAIR; // Set default value |
850 if (btest == BoolTest::eq) // Exactly equal test? |
881 if (btest == BoolTest::eq) // Exactly equal test? |
930 |
961 |
931 Block* branch_block = successor_for_bci(target_bci); |
962 Block* branch_block = successor_for_bci(target_bci); |
932 Block* next_block = successor_for_bci(iter().next_bci()); |
963 Block* next_block = successor_for_bci(iter().next_bci()); |
933 |
964 |
934 float cnt; |
965 float cnt; |
935 float prob = branch_prediction(cnt, btest, target_bci); |
966 float prob = branch_prediction(cnt, btest, target_bci, c); |
936 if (prob == PROB_UNKNOWN) { |
967 if (prob == PROB_UNKNOWN) { |
937 // (An earlier version of do_ifnull omitted this trap for OSR methods.) |
968 // (An earlier version of do_ifnull omitted this trap for OSR methods.) |
938 #ifndef PRODUCT |
969 #ifndef PRODUCT |
939 if (PrintOpto && Verbose) |
970 if (PrintOpto && Verbose) |
940 tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); |
971 tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); |