{"record":{"id":"d601a1ed7dcde210","repo":"oracle/graal","slug":"branch-probability-could-not-be-injected-because","errorCode":null,"errorMessage":"Branch probability could not be injected, because the probability value did not reduce to a constant value.","messagePattern":"Branch probability could not be injected, because the probability value did not reduce to a constant value\\.","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java","lineNumber":324,"sourceCode":"     */\n    @NodeIntrinsic\n    public static native boolean probability(double probability, boolean condition);\n\n    /**\n     * This intrinsic can be used to inject a truly unknown probability (0.5 for both true and false\n     * successor) for an {@link IfNode}. While the probability will be 0.5 for both successors this\n     * method ensures the {@link ProfileSource} is {@link ProfileSource#isTrusted(ProfileSource)},\n     * i.e., the compiler can trust it.\n     *\n     * This intrinsic should be used with great caution only for cases, e.g. inside snippets, for\n     * which absolutely now probability guess can be made.\n     */\n    @NodeIntrinsic\n    public static native boolean unknownProbability(boolean condition);\n\n    @Override\n    public void lower(LoweringTool tool) {\n        throw new GraalError(\"Branch probability could not be injected, because the probability value did not reduce to a constant value.\");\n    }\n}\n","sourceCodeStart":306,"sourceCodeEnd":327,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java#L306-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nBranchProbabilityNode.probability(computeProb(), cond) // runtime value -> lowers -> error\n\n// after\nprivate static final double P = 0.99;\nBranchProbabilityNode.probability(P, cond)","handlingStrategy":"validation","validationCode":"private static final double P = 0.99;            // compile-time constant\n// guard in snippet frameworks: probability must be a ConstantNode at simplification time\nif (!probabilityNode.probability().isConstant()) throw new IllegalStateException(\"branch probability must be constant\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["graalvm","branch-probability","intrinsic-misuse","lowering"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}