oracle/graal · error · GraalError
Wrong usage of branch probability injection + this
Error message
Wrong usage of branch probability injection + this
What it means
After simplification, if the BranchProbabilityNode's condition was consumed but some usage remains that is not the recognized pattern, simplify() throws 'Wrong usage of branch probability injection' — unless isSubstitutionGraph() (exactly one usage which is a ReturnNode) holds, which supports returning the probability value itself from snippets. The error means the intrinsic result was consumed in a way that never feeds an if-condition, so the probability can never be injected.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java:239
((ConditionalNode) currentCondition).trueValue().isConstant() && ((ConditionalNode) currentCondition).falseValue().isConstant()) {
for (IntegerEqualsNode eq : currentCondition.usages().filter(IntegerEqualsNode.class).snapshot()) {
if (eq.getY().isConstant() || eq.getX().isConstant()) {
ValueNode canonical = eq.canonical(tool);
if (canonical != eq && canonical != null) {
tool.addToWorkList(eq.usages());
eq.replaceAtUsages(graph().addOrUnique(canonical));
GraphUtil.killWithUnusedFloatingInputs(eq);
}
}
}
}
if (currentCondition.hasUsages()) {
tool.addToWorkList(currentCondition.usages());
}
}
} else {
if (!isSubstitutionGraph()) {
throw new GraalError("Wrong usage of branch probability injection " + this);
}
}
}
}
private boolean isSubstitutionGraph() {
return hasExactlyOneUsage() && usages().first() instanceof ReturnNode;
}
/**
* Normally a branch probability should be consumed directly as a condition, but in some cases
* it can be used as a value itself. For example:
*
* <pre>
* boolean helper() {
* if (probability(a, ...) || probability(b, ...) || probability(c, condition)) {
* return true;
* } else {View on GitHub (pinned to a66e9ccd1d)
Solutions
- Use the intrinsic result directly as the if condition: if (probability(p, cond)) { ... }
- If you need the value returned (substitution graph), keep exactly one usage that is the ReturnNode — any other shape throws
- Remove the intrinsic if you only need the boolean, not the probability
Example fix
// before
boolean b = BranchProbabilityNode.probability(p, cond);
map.put(k, b); // non-condition usage -> error
if (map.get(k)) { ... }
// after
if (BranchProbabilityNode.probability(p, cond)) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Structural check: the intrinsic result must feed an if-condition (or a single return) // lint rule / review check: forbid assignments or map/list insertions of probability(...) results boolean ok = usage instanceof IfNode condition || (singleUsage && usage instanceof ReturnNode);
Prevention
- Always write if (probability(p, cond)) directly, with no intermediates
- Do not store, pass around, or combine the intrinsic's boolean result
- In snippets, the only non-condition usage allowed is returning the value itself
When it happens
Trigger: Using probability(p, cond)'s boolean result in non-condition positions: storing it in a variable, passing it to another method, combining it with && / || in ways the simplifier cannot rewrite, or using it as a value — while not matching the single-ReturnNode substitution exception.
Common situations: Refactoring a snippet so the intrinsic result flows through a phi or helper before reaching an if; new snippet authors assuming probability() works like a plain boolean; using it inside complex boolean expressions.
Related errors
- A negative probability of + probabilityValue + is not allo
- A probability of more than 1.0 ( + probabilityValue + ) is n
- Branch probability could not be injected, because the probab
- 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/429852a1ddf12ec1.
Report an issue: GitHub.