oracle/graal · error · GraalError
Switch case probability could not be injected, because the p
Error message
Switch case probability could not be injected, because the probability value did not reduce to a constant value.
What it means
SwitchCaseProbabilityNode is the switch-case analogue of BranchProbabilityNode: during simplification its probability array should constant-fold and be consumed into the switch's key probabilities. If the node survives to the lowering phase, the probability value did not reduce to a constant, and lower() throws — mirroring the branch-probability rule that these hints must be compile-time constants.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/SwitchCaseProbabilityNode.java:73
@Input ValueNode probability;
public SwitchCaseProbabilityNode(ValueNode probability) {
super(TYPE, StampFactory.forKind(JavaKind.Void));
this.probability = probability;
}
public ValueNode getProbability() {
return probability;
}
public void setProbability(ValueNode probability) {
updateUsages(this.probability, probability);
this.probability = probability;
}
@Override
public void lower(LoweringTool tool) {
throw new GraalError("Switch case probability could not be injected, because the probability value did not reduce to a constant value.");
}
}
View on GitHub (pinned to a66e9ccd1d)
Solutions
- Supply a compile-time constant for the case probability (literal or static final)
- If probabilities vary at run time, remove the hint node and rely on regular profile-based switch probabilities
- In snippet/substitution code, mark probability inputs as constant parameters so they fold before lowering
Example fix
// before
SwitchCaseProbabilityNode.probability(dynamicProbs[i], key)
// after
private static final double[] CASE_PROBS = {0.7, 0.2, 0.1};
SwitchCaseProbabilityNode.probability(CASE_PROBS[i], key) Defensive patterns
Strategy: validation
Validate before calling
private static final double[] CASE_PROBS = {0.7, 0.2, 0.1};
// ensure any probability fed to the switch-case hint is a compile-time constant:
if (!probabilityInput.isConstant()) throw new IllegalStateException("switch case probability must be constant"); Prevention
- Use static final constants for switch-case probabilities
- Mark probability parameters as constant in snippet definitions
- For runtime-varying profiles, omit the hint and let profiling supply switch probabilities
When it happens
Trigger: Constructing a SwitchCaseProbabilityNode (via the switch-case probability intrinsic/annotation support) with a non-constant probability input: runtime-computed doubles, non-final fields, or values blocked from constant folding, so the node is still present during lowering.
Common situations: Passing profile-derived or computed probabilities to switch probability hints; refactoring constants into non-static-final fields; snippet parameters not marked constant.
Related errors
- Branch probability could not be injected, because the probab
- A negative probability of + probabilityValue + is not allo
- A probability of more than 1.0 ( + probabilityValue + ) is n
- Wrong usage of branch probability injection + this
- LogFile substitution %s cannot be combined with any other ch
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/077df12e6199cd5b.
Report an issue: GitHub.