{"record":{"id":"f1bc69ec914d7b3e","repo":"oracle/graal","slug":"multiple-garbage-collectors-selected-s-s","errorCode":null,"errorMessage":"Multiple garbage collectors selected: %s %s","messagePattern":"Multiple garbage collectors selected: (.+?) (.+?)","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"critical","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java","lineNumber":109,"sourceCode":"    public boolean useSerialGC() {\n        return gc == HotSpotGraalRuntime.HotSpotGC.Serial;\n    }\n\n    public boolean useG1GC() {\n        return gc == HotSpotGraalRuntime.HotSpotGC.G1;\n    }\n\n    public final HotSpotGraalRuntime.HotSpotGC gc = getSelectedGC();\n\n    private HotSpotGraalRuntime.HotSpotGC getSelectedGC() throws GraalError {\n        HotSpotGraalRuntime.HotSpotGC selected = null;\n        for (HotSpotGraalRuntime.HotSpotGC value : HotSpotGraalRuntime.HotSpotGC.values()) {\n            if (value.isSelected(this)) {\n                if (!value.supported) {\n                    throw new GraalError(value.name() + \" garbage collector is not supported by Graal\");\n                }\n                if (selected != null) {\n                    throw new GraalError(\"Multiple garbage collectors selected: \" + selected + \" \" + value);\n                }\n                selected = value;\n            }\n        }\n        if (selected == null) {\n            // Exactly one GC flag is guaranteed to be selected.\n            selected = HotSpotGraalRuntime.HotSpotGC.Serial;\n        }\n        return selected;\n    }\n\n    /**\n     * Determines if {@code -Xcomp} (or the equivalent thereof) was specified as a JVM argument.\n     */\n    public final boolean xcompMode = !access.getFlag(\"UseInterpreter\", Boolean.class);\n\n    public final boolean ropProtection = access.getFieldValue(\"VM_Version::_rop_protection\", Boolean.class, \"bool\", false);\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/GraalHotSpotVMConfig.java#L91-L127","documentation":"getSelectedGC requires that exactly one HotSpotGC reports isSelected(this). If a second collector also reports selected, it throws GraalError('Multiple garbage collectors selected: A B'). Normally HotSpot guarantees a single -XX:+Use*GC, so this indicates contradictory VM flags or a broken/ported VM where several Use flags are simultaneously true.","triggerScenarios":"Passing multiple -XX:+Use...GC flags (e.g. -XX:+UseG1GC -XX:+UseSerialGC) on a VM build that does not override later flags to false, or running a custom/modified HotSpot where more than one collector's selection check (flag or platform default) returns true; failure happens while GraalHotSpotVMConfig fields initialize.","commonSituations":"Benchmark scripts concatenating GC flags from different templates; custom JVM builds or ports with buggy flag defaults; flags injected both by JAVA_OPTS and the command line in container entrypoints.","solutions":["Leave exactly one GC-selection flag (let the VM default pick one) and remove duplicates from scripts, JAVA_OPTS, and JVM_OPTIONS env vars","Query the effective GC with -XX:+PrintFlagsFinal -version | grep Use.*GC to see which flags ended up true","If the VM really defaults multiple collectors to true, that is a VM build bug — fix the port/build"],"exampleFix":"# before\njava -XX:+UseG1GC -XX:+UseParallelGC -XX:+UseJVMCICompiler MyApp\n\n# after\njava -XX:+UseG1GC -XX:+UseJVMCICompiler MyApp","handlingStrategy":"validation","validationCode":"// ensure exactly one Use*GC flag in the effective command line before enabling JVMCI\nlong gcFlags = Stream.of(\"UseG1GC\", \"UseParallelGC\", \"UseSerialGC\", \"UseZGC\", \"UseShenandoahGC\").filter(f -> args.contains(\"-XX:+\" + f)).count();\nif (gcFlags > 1) throw new IllegalArgumentException(\"multiple GC flags\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive GC flags from a single source of truth in scripts","Check -XX:+PrintFlagsFinal for accidentally-true Use*GC flags","Never concatenate flag sets from multiple templates"],"tags":["graal-compiler","gc","hotspot","configuration"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}