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

  1. Supply a compile-time constant for the case probability (literal or static final)
  2. If probabilities vary at run time, remove the hint node and rely on regular profile-based switch probabilities
  3. 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

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


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/077df12e6199cd5b. Report an issue: GitHub.