Skip to content

Commit d9387e3

Browse files
committed
[GR-60196] Adjust jump table threshold
PullRequest: graal/19485
2 parents 6237596 + c1d94eb commit d9387e3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/gen/LIRGenerator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState frameS
501501
}
502502
}
503503

504+
private static final double JUMP_TABLE_THRESHOLD = 3;
505+
504506
public void emitStrategySwitch(JavaConstant[] keyConstants, double[] keyProbabilities, LabelRef[] keyTargets, LabelRef defaultTarget, AllocatableValue value) {
505507
SwitchStrategy strategy = SwitchStrategy.getBestStrategy(keyProbabilities, keyConstants, keyTargets);
506508

@@ -513,12 +515,12 @@ public void emitStrategySwitch(JavaConstant[] keyConstants, double[] keyProbabil
513515

514516
/*
515517
* 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.
519521
*/
520522
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)) {
522524
emitStrategySwitch(strategy, value, keyTargets, defaultTarget);
523525
} else {
524526
if (hashTableSwitchDensity > tableSwitchDensity) {

0 commit comments

Comments
 (0)