{"record":{"id":"27f20a5a2a813239","repo":"oracle/graal","slug":"performance-warning-detected-and-is-treated-as-a-c","errorCode":null,"errorMessage":"Performance warning detected and is treated as a compilation error.","messagePattern":"Performance warning detected and is treated as a compilation error\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PerformanceInformationHandler.java","lineNumber":241,"sourceCode":"                        if (!ProfileSource.isTrusted(split.getProfileData().getProfileSource())) {\n                            logPerformanceWarning(TruffleCompilerOptions.PerformanceWarningKind.MISSING_LOOP_FREQUENCY_INFO, context.compilable, Arrays.asList(loop.getHeader().getBeginNode()),\n                                            String.format(\"Missing loop profile for %s at loop %s.\", split, loop.getHeader().getBeginNode()), null);\n                        }\n                    }\n                }\n            }\n        }\n\n        if (debug.areScopesEnabled() && !warnings.isEmpty()) {\n            try (DebugContext.Scope s = debug.scope(\"TrufflePerformanceWarnings\", graph)) {\n                debug.dump(DebugContext.BASIC_LEVEL, graph, \"performance warnings %s\", warnings);\n            } catch (Throwable t) {\n                debug.handle(t);\n            }\n        }\n\n        if (!Collections.disjoint(getWarnings(), TruffleCompilerOptions.TreatPerformanceWarningsAsErrors.getValue(options).kinds())) {\n            throw new AssertionError(\"Performance warning detected and is treated as a compilation error.\");\n        }\n    }\n\n    /**\n     * On HotSpot, a type check against a class that is at a depth <= 8 in the class hierarchy\n     * (including Object) is just one extra memory load.\n     */\n    private static boolean isPrimarySupertype(ResolvedJavaType type) {\n        if (type.isInterface()) {\n            return false;\n        }\n        ResolvedJavaType supr = type;\n        int depth = 0;\n        while (supr != null) {\n            depth++;\n            supr = supr.getSuperclass();\n        }\n        return depth <= 8;","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PerformanceInformationHandler.java#L223-L259","documentation":"Thrown as an AssertionError at the end of Truffle performance-warning reporting when any warning kind recorded for the compiled graph intersects the kinds listed in TruffleCompilerOptions.TreatPerformanceWarningsAsErrors. It is a deliberate escape hatch: the compiler detected a coding pattern known to hurt Truffle peak performance (e.g. megamorphic virtual calls in hot code) and the configuration says to fail the compilation instead of just logging. This is not a compiler bug; it is a lint gate for guest-language bytecode produced by partial evaluation.","triggerScenarios":"Compiling a Truffle guest-language method whose graph accumulates performance warnings (via PerformanceInformationHandler.getWarnings()), while -Dgraal.TrufflePerformanceWarningsAsErrors (TreatPerformanceWarningsAsErrors) is set to a kind set such as 'all' or 'Megamorphic' that overlaps those warnings. The check runs Collections.disjoint(getWarnings(), optionKinds) after every compilation, so any single matching warning triggers it.","commonSituations":"Language implementers enabling strict performance checking in CI to catch regressions; upgrading a Truffle language after new warning kinds were added (a pattern previously silent now fails); running with TreatPerformanceWarningsAsErrors=AnNOTATED/Bailout on code that uses @NeverValidTruffleBundle or optimistic assumptions that became megamorphic.","solutions":["Run with -Dgraal.TrufflePerformanceWarningsAsErrors= to disable the error conversion, or remove the specific kind matching the warning, then recompile to see the dumped warnings (enable -Dgraal.Dump=TrufflePerformanceWarnings to get the 'performance warnings %s' dump).","Inspect the graph dump named 'performance warnings' to identify which node/warning kind fired (e.g. megamorphic dispatch, virtual call not inlined).","Fix the guest-language code or node implementation that produced the warning (specialize, use @Specialization guards, avoid megamorphic call sites).","If the warning is a false positive for your language, exclude only that warning kind from TreatPerformanceWarningsAsErrors instead of disabling the check entirely."],"exampleFix":"// before\n-Dgraal.TrufflePerformanceWarningsAsErrors=all\n\n// after: narrow to the kinds you actually enforce, dump details first\n-Dgraal.Dump=TrufflePerformanceWarnings,level=1 -Dgraal.TrufflePerformanceWarningsAsErrors=Megamorphic","handlingStrategy":"try-catch","validationCode":"// Before compiling, check the option value yourself\nimport static jdk.graal.compiler.truffle.TruffleCompilerOptions.TreatPerformanceWarningsAsErrors;\n\nvar kinds = TreatPerformanceWarningsAsErrors.getValue(options).kinds();\nif (!kinds.isEmpty()) {\n    System.err.println(\"strict perf warnings active: \" + kinds);\n}","typeGuard":null,"tryCatchPattern":"// At the compilation-request boundary\ntry {\n    compile(graph, options);\n} catch (AssertionError e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Performance warning detected\")) {\n        // treat as code-quality failure: log, collect CI artifact, recompile with warnings non-fatal\n        reportPerfWarnings(compilationId);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep TreatPerformanceWarningsAsErrors limited to specific warning kinds you actually police, not 'all'.","Run CI with -Dgraal.Dump=TrufflePerformanceWarnings so any failure ships with the graph dump that explains it.","Re-baseline the warning-kind set after every GraalVM upgrade; new kinds can start failing previously-clean code."],"tags":["truffle","graalvm","performance","compiler-options","assertion"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}