793 |
793 |
794 // scale the counts to be commensurate with invocation counts: |
794 // scale the counts to be commensurate with invocation counts: |
795 taken = method()->scale_count(taken); |
795 taken = method()->scale_count(taken); |
796 not_taken = method()->scale_count(not_taken); |
796 not_taken = method()->scale_count(not_taken); |
797 |
797 |
798 // Give up if too few counts to be meaningful |
798 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. |
799 if (taken + not_taken < 40) { |
799 // We also check that individual counters are positive first, overwise the sum can become positive. |
|
800 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) { |
800 if (C->log() != NULL) { |
801 if (C->log() != NULL) { |
801 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); |
802 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken); |
802 } |
803 } |
803 return PROB_UNKNOWN; |
804 return PROB_UNKNOWN; |
804 } |
805 } |
805 |
806 |
806 // Compute frequency that we arrive here |
807 // Compute frequency that we arrive here |
807 int sum = taken + not_taken; |
808 float sum = taken + not_taken; |
808 // Adjust, if this block is a cloned private block but the |
809 // Adjust, if this block is a cloned private block but the |
809 // Jump counts are shared. Taken the private counts for |
810 // Jump counts are shared. Taken the private counts for |
810 // just this path instead of the shared counts. |
811 // just this path instead of the shared counts. |
811 if( block()->count() > 0 ) |
812 if( block()->count() > 0 ) |
812 sum = block()->count(); |
813 sum = block()->count(); |
813 cnt = (float)sum / (float)FreqCountInvocations; |
814 cnt = sum / FreqCountInvocations; |
814 |
815 |
815 // Pin probability to sane limits |
816 // Pin probability to sane limits |
816 float prob; |
817 float prob; |
817 if( !taken ) |
818 if( !taken ) |
818 prob = (0+PROB_MIN) / 2; |
819 prob = (0+PROB_MIN) / 2; |