{"record":{"id":"e23e0f95099ae523","repo":"oracle/graal","slug":"a-probability-of-more-than-1-0-probabilityvalu","errorCode":null,"errorMessage":"A probability of more than 1.0 ( + probabilityValue + ) is not allowed!","messagePattern":"A probability of more than 1\\.0 \\( \\+ probabilityValue \\+ \\) is not allowed!","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java","lineNumber":156,"sourceCode":"    public Node canonical(CanonicalizerTool tool) {\n        if (condition.isConstant()) {\n            // fold constant conditions early during PE\n            return condition;\n        }\n        return this;\n    }\n\n    @Override\n    public void simplify(SimplifierTool tool) {\n        if (!hasUsages()) {\n            return;\n        }\n        if (probability.isConstant()) {\n            double probabilityValue = probability.asJavaConstant().asDouble();\n            if (probabilityValue < 0.0) {\n                throw new GraalError(\"A negative probability of \" + probabilityValue + \" is not allowed!\");\n            } else if (probabilityValue > 1.0) {\n                throw new GraalError(\"A probability of more than 1.0 (\" + probabilityValue + \") is not allowed!\");\n            } else if (Double.isNaN(probabilityValue)) {\n                /*\n                 * We allow NaN if the node is in unreachable code that will eventually fall away,\n                 * or else an error will be thrown during lowering since we keep the node around.\n                 */\n                return;\n            }\n            boolean usageFound = false;\n            for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {\n                assert node.condition() == CanonicalCondition.EQ : Assertions.errorMessage(node, node.condition());\n                ValueNode other = node.getX();\n                if (node.getX() == this) {\n                    other = node.getY();\n                }\n                if (other.isConstant()) {\n                    double probabilityToSet = probabilityValue;\n                    if (other.asJavaConstant().asInt() == 0) {\n                        probabilityToSet = 1.0 - probabilityToSet;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java#L138-L174","documentation":"The sibling check in BranchProbabilityNode.simplify: a probability constant greater than 1.0 throws GraalError with the value in the message. Probabilities are true likelihoods, so anything above 1.0 is invalid input to the branch-probability intrinsic.","triggerScenarios":"probability(1.5, cond) or an arithmetic expression over likelihood constants that constant-folds above 1.0 (e.g., LIKELY_PROBABILITY + 0.1) reaching the intrinsic's probability input.","commonSituations":"Developers treating probability as a weight/hint multiplier; combining several probability constants additively; porting 'weights' from another compiler's API (e.g., __builtin_expect semantics) into probability semantics.","solutions":["Normalize the value into [0.0, 1.0]; for 'very likely' use the provided constants such as LIKELY_PROBABILITY or 1.0 - DELTA_ON_TAKEN","Replace weight-style arithmetic with direct selection of a probability constant","Add a unit assertion in snippet frameworks that probability inputs stay within [0,1]"],"exampleFix":"// before\nBranchProbabilityNode.probability(1.2, cond)\n\n// after\nBranchProbabilityNode.probability(BranchProbabilityNode.LIKELY_PROBABILITY, cond)","handlingStrategy":"validation","validationCode":"static double clampProbability(double p) {\n    if (p < 0.0) return 0.0;\n    if (p > 1.0) return 1.0;\n    return p;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never treat probability as a multiplier or weight; stay within [0.0, 1.0]","Do not combine probability constants arithmetically","Use LIKELY_PROBABILITY / NOT_FREQUENT_PROBABILITY constants for the extreme cases"],"tags":["graalvm","branch-probability","intrinsic-misuse","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}