@@ -4626,45 +4626,54 @@ private static void dropStack(VirtualFrame frame, int stackPointer, int targetSt
4626
4626
private static final int MAX_PROFILE_VALUE = 0x0000_00ff ;
4627
4627
private static final int MAX_TABLE_PROFILE_VALUE = 0x0000_ffff ;
4628
4628
4629
+ @ SuppressWarnings ("all" ) // "The parameter condition should not be assigned."
4629
4630
private static boolean profileCondition (byte [] data , final int profileOffset , boolean condition ) {
4630
4631
int t = rawPeekU8 (data , profileOffset );
4631
4632
int f = rawPeekU8 (data , profileOffset + 1 );
4632
- boolean val = condition ;
4633
- if (val ) {
4633
+ if (condition ) {
4634
4634
if (t == 0 ) {
4635
4635
CompilerDirectives .transferToInterpreterAndInvalidate ();
4636
4636
}
4637
- if (!CompilerDirectives .inInterpreter ()) {
4638
- if (f == 0 ) {
4639
- // Make this branch fold during PE
4640
- val = true ;
4637
+ if (CompilerDirectives .inInterpreter ()) {
4638
+ if (t < MAX_PROFILE_VALUE ) {
4639
+ t ++;
4640
+ } else {
4641
+ // halve count rounding up, must never go from 1 to 0.
4642
+ f = (f >>> 1 ) + (f & 0x1 );
4643
+ t = (MAX_PROFILE_VALUE >>> 1 ) + 1 ;
4644
+ data [profileOffset + 1 ] = (byte ) f ;
4641
4645
}
4646
+ data [profileOffset ] = (byte ) t ;
4647
+ return condition ;
4642
4648
} else {
4643
- if (t < MAX_PROFILE_VALUE ) {
4644
- data [profileOffset ] = (byte ) (t + 1 );
4649
+ if (f == 0 ) {
4650
+ // Make this branch fold during PE
4651
+ condition = true ;
4645
4652
}
4646
4653
}
4647
4654
} else {
4648
4655
if (f == 0 ) {
4649
4656
CompilerDirectives .transferToInterpreterAndInvalidate ();
4650
4657
}
4651
- if (!CompilerDirectives .inInterpreter ()) {
4652
- if (t == 0 ) {
4653
- // Make this branch fold during PE
4654
- val = false ;
4658
+ if (CompilerDirectives .inInterpreter ()) {
4659
+ if (f < MAX_PROFILE_VALUE ) {
4660
+ f ++;
4661
+ } else {
4662
+ // halve count rounding up, must never go from 1 to 0.
4663
+ t = (t >>> 1 ) + (t & 0x1 );
4664
+ f = (MAX_PROFILE_VALUE >>> 1 ) + 1 ;
4665
+ data [profileOffset ] = (byte ) t ;
4655
4666
}
4667
+ data [profileOffset + 1 ] = (byte ) f ;
4668
+ return condition ;
4656
4669
} else {
4657
- if (f < MAX_PROFILE_VALUE ) {
4658
- data [profileOffset + 1 ] = (byte ) (f + 1 );
4670
+ if (t == 0 ) {
4671
+ // Make this branch fold during PE
4672
+ condition = false ;
4659
4673
}
4660
4674
}
4661
4675
}
4662
- if (CompilerDirectives .inInterpreter ()) {
4663
- return val ;
4664
- } else {
4665
- int sum = t + f ;
4666
- return CompilerDirectives .injectBranchProbability ((double ) t / (double ) sum , val );
4667
- }
4676
+ return CompilerDirectives .injectBranchProbability ((double ) t / (double ) (t + f ), condition );
4668
4677
}
4669
4678
4670
4679
private static void updateBranchTableProfile (byte [] data , final int counterOffset , final int profileOffset ) {
0 commit comments