@@ -501,6 +501,8 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState frameS
501
501
}
502
502
}
503
503
504
+ private static final double JUMP_TABLE_THRESHOLD = 3 ;
505
+
504
506
public void emitStrategySwitch (JavaConstant [] keyConstants , double [] keyProbabilities , LabelRef [] keyTargets , LabelRef defaultTarget , AllocatableValue value ) {
505
507
SwitchStrategy strategy = SwitchStrategy .getBestStrategy (keyProbabilities , keyConstants , keyTargets );
506
508
@@ -513,12 +515,12 @@ public void emitStrategySwitch(JavaConstant[] keyConstants, double[] keyProbabil
513
515
514
516
/*
515
517
* This heuristic tries to find a compromise between the effort for the best switch strategy
516
- * and the density of a tableswitch. If the effort for the strategy is at least 4, then a
517
- * tableswitch is preferred if better than a certain value that starts at 0.5 and lowers
518
- * gradually with additional effort.
518
+ * and the density of a tableswitch. If the effort for the strategy is at least
519
+ * JUMP_TABLE_THRESHOLD, then a tableswitch is preferred if the density is larger than a
520
+ * certain value that gradually decreases as the aforementioned effort rises .
519
521
*/
520
522
double minDensity = 1 / Math .sqrt (strategy .getAverageEffort ());
521
- if (strategy .getAverageEffort () < 4d || (tableSwitchDensity < minDensity && hashTableSwitchDensity < minDensity )) {
523
+ if (strategy .getAverageEffort () < JUMP_TABLE_THRESHOLD || (tableSwitchDensity < minDensity && hashTableSwitchDensity < minDensity )) {
522
524
emitStrategySwitch (strategy , value , keyTargets , defaultTarget );
523
525
} else {
524
526
if (hashTableSwitchDensity > tableSwitchDensity ) {
0 commit comments