oracle/graal · error · GraalError

A probability of more than 1.0 ({}) is not allowed!

Error message

A probability of more than 1.0 ({}) is not allowed!

What it means

SwitchNode's simplification (SwitchNode.java:343) validates that every constant case probability is in [0.0, 1.0]. This variant fires when a probability constant exceeds 1.0 (100%), which is invalid because probabilities are ratios. It usually indicates unnormalized counts were passed where ratios were expected.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/SwitchNode.java:343

            assertTrue(succ.next() instanceof SwitchCaseProbabilityNode,
                            "Cannot inject switch probability, since key successor %s is not a SwitchCaseProbabilityNode",
                            succ.next());
            SwitchCaseProbabilityNode caseProbabilityNode = (SwitchCaseProbabilityNode) succ.next();

            ValueNode probabilityNode = caseProbabilityNode.getProbability();
            if (!probabilityNode.isConstant()) {
                /*
                 * If any of the probabilities are not constant we bail out of simplification, which
                 * will cause compilation to fail later during lowering since the node will be left
                 * behind
                 */
                return;
            }
            double probabilityValue = probabilityNode.asJavaConstant().asDouble();
            if (probabilityValue < 0.0) {
                throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
            } else if (probabilityValue > 1.0) {
                throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
            } else if (Double.isNaN(probabilityValue)) {
                /*
                 * We allow NaN if the node is in unreachable code that will eventually fall away,
                 * or else an error will be thrown during lowering since we keep the node around.
                 * See analogous case in BranchProbabilityNode.
                 */
                return;
            }
            nodeProbabilities[i] = probabilityValue / numKeysPerBlock[keySuccessorIndex(i)];
        }

        for (AbstractBeginNode blockSuccessor : successors) {
            AbstractBeginNode succ = blockSuccessor;
            while (succ.next() instanceof AbstractBeginNode next) {
                succ = next;
            }
            SwitchCaseProbabilityNode caseProbabilityNode = (SwitchCaseProbabilityNode) succ.next();
            caseProbabilityNode.replaceAtUsages(null);

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Normalize the values: divide each entry by the sum of all entries so they sum to <= 1.0
  2. Check the denominator used to compute each probability (should be total key count or total weight, not the maximum)
  3. Guard the array with an assert/validation loop before constructing the switch

Example fix

// before
double[] probs = {120, 30, 900}; // raw counts, >1.0
SwitchNode.create(..., probs, ...);

// after
double total = 1050;
double[] probs = {120 / total, 30 / total, 900 / total};
SwitchNode.create(..., probs, ...);
Defensive patterns

Strategy: validation

Validate before calling

static double[] normalize(double[] weights) {
    double total = Arrays.stream(weights).sum();
    double[] out = new double[weights.length];
    for (int i = 0; i < weights.length; i++) out[i] = weights[i] / total;
    return out; // every entry now <= 1.0
}

Prevention

When it happens

Trigger: Calling SwitchNode.create(...) / IntegerSwitchNode with a constant probabilities array entry > 1.0; most often raw execution counts from profiling instead of ratios.

Common situations: Passing profile hit counts (e.g., {120, 30, 900}) directly as probabilities; computing a ratio with the wrong denominator (dividing by the max instead of the total).

Related errors


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