src/share/vm/opto/parse2.cpp

changeset 7789
eb8b5cc64669
parent 7154
42460b71ba70
child 7994
04ff2f6cd0eb
child 8285
535618ab1c04
child 8368
32b682649973
equal deleted inserted replaced
7788:c97ba20ad404 7789:eb8b5cc64669
759 profile_ret(target->flow()->start()); 759 profile_ret(target->flow()->start());
760 int pnum = target->next_path_num(); 760 int pnum = target->next_path_num();
761 merge_common(target, pnum); 761 merge_common(target, pnum);
762 } 762 }
763 763
764 static bool has_injected_profile(BoolTest::mask btest, Node* test, int& taken, int& not_taken) {
765 if (btest != BoolTest::eq && btest != BoolTest::ne) {
766 // Only ::eq and ::ne are supported for profile injection.
767 return false;
768 }
769 if (test->is_Cmp() &&
770 test->in(1)->Opcode() == Op_ProfileBoolean) {
771 ProfileBooleanNode* profile = (ProfileBooleanNode*)test->in(1);
772 int false_cnt = profile->false_count();
773 int true_cnt = profile->true_count();
774
775 // Counts matching depends on the actual test operation (::eq or ::ne).
776 // No need to scale the counts because profile injection was designed
777 // to feed exact counts into VM.
778 taken = (btest == BoolTest::eq) ? false_cnt : true_cnt;
779 not_taken = (btest == BoolTest::eq) ? true_cnt : false_cnt;
780
781 profile->consume();
782 return true;
783 }
784 return false;
785 }
764 //--------------------------dynamic_branch_prediction-------------------------- 786 //--------------------------dynamic_branch_prediction--------------------------
765 // Try to gather dynamic branch prediction behavior. Return a probability 787 // Try to gather dynamic branch prediction behavior. Return a probability
766 // of the branch being taken and set the "cnt" field. Returns a -1.0 788 // of the branch being taken and set the "cnt" field. Returns a -1.0
767 // if we need to use static prediction for some reason. 789 // if we need to use static prediction for some reason.
768 float Parse::dynamic_branch_prediction(float &cnt) { 790 float Parse::dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test) {
769 ResourceMark rm; 791 ResourceMark rm;
770 792
771 cnt = COUNT_UNKNOWN; 793 cnt = COUNT_UNKNOWN;
772 794
773 // Use MethodData information if it is available 795 int taken = 0;
774 // FIXME: free the ProfileData structure
775 ciMethodData* methodData = method()->method_data();
776 if (!methodData->is_mature()) return PROB_UNKNOWN;
777 ciProfileData* data = methodData->bci_to_data(bci());
778 if (!data->is_JumpData()) return PROB_UNKNOWN;
779
780 // get taken and not taken values
781 int taken = data->as_JumpData()->taken();
782 int not_taken = 0; 796 int not_taken = 0;
783 if (data->is_BranchData()) { 797
784 not_taken = data->as_BranchData()->not_taken(); 798 bool use_mdo = !has_injected_profile(btest, test, taken, not_taken);
785 } 799
786 800 if (use_mdo) {
787 // scale the counts to be commensurate with invocation counts: 801 // Use MethodData information if it is available
788 taken = method()->scale_count(taken); 802 // FIXME: free the ProfileData structure
789 not_taken = method()->scale_count(not_taken); 803 ciMethodData* methodData = method()->method_data();
804 if (!methodData->is_mature()) return PROB_UNKNOWN;
805 ciProfileData* data = methodData->bci_to_data(bci());
806 if (!data->is_JumpData()) return PROB_UNKNOWN;
807
808 // get taken and not taken values
809 taken = data->as_JumpData()->taken();
810 not_taken = 0;
811 if (data->is_BranchData()) {
812 not_taken = data->as_BranchData()->not_taken();
813 }
814
815 // scale the counts to be commensurate with invocation counts:
816 taken = method()->scale_count(taken);
817 not_taken = method()->scale_count(not_taken);
818 }
790 819
791 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. 820 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
792 // We also check that individual counters are positive first, overwise the sum can become positive. 821 // We also check that individual counters are positive first, otherwise the sum can become positive.
793 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { 822 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) {
794 if (C->log() != NULL) { 823 if (C->log() != NULL) {
795 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); 824 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
796 } 825 }
797 return PROB_UNKNOWN; 826 return PROB_UNKNOWN;
837 } 866 }
838 867
839 //-----------------------------branch_prediction------------------------------- 868 //-----------------------------branch_prediction-------------------------------
840 float Parse::branch_prediction(float& cnt, 869 float Parse::branch_prediction(float& cnt,
841 BoolTest::mask btest, 870 BoolTest::mask btest,
842 int target_bci) { 871 int target_bci,
843 float prob = dynamic_branch_prediction(cnt); 872 Node* test) {
873 float prob = dynamic_branch_prediction(cnt, btest, test);
844 // If prob is unknown, switch to static prediction 874 // If prob is unknown, switch to static prediction
845 if (prob != PROB_UNKNOWN) return prob; 875 if (prob != PROB_UNKNOWN) return prob;
846 876
847 prob = PROB_FAIR; // Set default value 877 prob = PROB_FAIR; // Set default value
848 if (btest == BoolTest::eq) // Exactly equal test? 878 if (btest == BoolTest::eq) // Exactly equal test?
928 958
929 Block* branch_block = successor_for_bci(target_bci); 959 Block* branch_block = successor_for_bci(target_bci);
930 Block* next_block = successor_for_bci(iter().next_bci()); 960 Block* next_block = successor_for_bci(iter().next_bci());
931 961
932 float cnt; 962 float cnt;
933 float prob = branch_prediction(cnt, btest, target_bci); 963 float prob = branch_prediction(cnt, btest, target_bci, c);
934 if (prob == PROB_UNKNOWN) { 964 if (prob == PROB_UNKNOWN) {
935 // (An earlier version of do_ifnull omitted this trap for OSR methods.) 965 // (An earlier version of do_ifnull omitted this trap for OSR methods.)
936 #ifndef PRODUCT 966 #ifndef PRODUCT
937 if (PrintOpto && Verbose) 967 if (PrintOpto && Verbose)
938 tty->print_cr("Never-taken edge stops compilation at bci %d",bci()); 968 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
1009 1039
1010 Block* branch_block = successor_for_bci(target_bci); 1040 Block* branch_block = successor_for_bci(target_bci);
1011 Block* next_block = successor_for_bci(iter().next_bci()); 1041 Block* next_block = successor_for_bci(iter().next_bci());
1012 1042
1013 float cnt; 1043 float cnt;
1014 float prob = branch_prediction(cnt, btest, target_bci); 1044 float prob = branch_prediction(cnt, btest, target_bci, c);
1015 float untaken_prob = 1.0 - prob; 1045 float untaken_prob = 1.0 - prob;
1016 1046
1017 if (prob == PROB_UNKNOWN) { 1047 if (prob == PROB_UNKNOWN) {
1018 #ifndef PRODUCT 1048 #ifndef PRODUCT
1019 if (PrintOpto && Verbose) 1049 if (PrintOpto && Verbose)

mercurial