oracle/graal · error · GraalError
Branch probability could not be injected, because the probab
Error message
Branch probability could not be injected, because the probability value did not reduce to a constant value.
What it means
BranchProbabilityNode.lower throws if lowering is reached at all: by that point the probability input must have constant-folded and the whole node must have been optimized away into the enclosing condition. A non-constant probability (or a usage pattern that blocked simplification) reaching the lowering phase is therefore a usage error — the probability could not be injected.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java:324
*/
@NodeIntrinsic
public static native boolean probability(double probability, boolean condition);
/**
* This intrinsic can be used to inject a truly unknown probability (0.5 for both true and false
* successor) for an {@link IfNode}. While the probability will be 0.5 for both successors this
* method ensures the {@link ProfileSource} is {@link ProfileSource#isTrusted(ProfileSource)},
* i.e., the compiler can trust it.
*
* This intrinsic should be used with great caution only for cases, e.g. inside snippets, for
* which absolutely now probability guess can be made.
*/
@NodeIntrinsic
public static native boolean unknownProbability(boolean condition);
@Override
public void lower(LoweringTool tool) {
throw new GraalError("Branch probability could not be injected, because the probability value did not reduce to a constant value.");
}
}
View on GitHub (pinned to a66e9ccd1d)
Solutions
- Pass a compile-time constant literal (or static final constant) as the probability argument
- If the value must vary, drop the intrinsic and use a plain condition (and rely on runtime profiling instead)
- In snippet frameworks, make the probability a @ConstantParameter so it folds before lowering
Example fix
// before BranchProbabilityNode.probability(computeProb(), cond) // runtime value -> lowers -> error // after private static final double P = 0.99; BranchProbabilityNode.probability(P, cond)
Defensive patterns
Strategy: validation
Validate before calling
private static final double P = 0.99; // compile-time constant
// guard in snippet frameworks: probability must be a ConstantNode at simplification time
if (!probabilityNode.probability().isConstant()) throw new IllegalStateException("branch probability must be constant"); Prevention
- Pass literals or static final constants as the probability argument
- Use @ConstantParameter for snippet probability inputs
- If the value is inherently runtime-dependent, drop the intrinsic entirely
When it happens
Trigger: The probability argument does not reduce to a compile-time constant: a runtime-computed double, a parameter, or a value read from configuration at run time. Simplify() cannot fold it, the node survives to the backend-lowering phase, and lower() throws.
Common situations: Parameterizing snippet probabilities at run time; passing profile-derived or random values instead of literals; constant-folding disabled or blocked by side-effect-free-but-opaque calls around the probability expression.
Related errors
- 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
- Switch case probability could not be injected, because the p
- 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/d601a1ed7dcde210.
Report an issue: GitHub.