{"record":{"id":"ea762a7684632383","repo":"oracle/graal","slug":"too-many-counters-reduce-number-of-counters-or-in","errorCode":null,"errorMessage":"too many counters, reduce number of counters or increase -XX:JVMCICounterSize=... (current value: %s)","messagePattern":"too many counters, reduce number of counters or increase -XX:JVMCICounterSize=\\.\\.\\. \\(current value: (.+?)\\)","errorType":"error_code","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/debug/BenchmarkCounters.java","lineNumber":181,"sourceCode":"    private static Counter getCounter(String name, String group, GraalHotSpotVMConfig config) throws GraalError {\n        if (!enabled) {\n            throw new GraalError(\"cannot access count index when counters are not enabled: \" + group + \", \" + name);\n        }\n        String nameGroup = name + \"#\" + group;\n        Counter counter = counterMap.get(nameGroup);\n        if (counter == null) {\n            synchronized (BenchmarkCounters.class) {\n                counter = counterMap.get(nameGroup);\n                if (counter == null) {\n                    counter = new Counter(counterMap.size(), group, new AtomicLong());\n                    counterMap.put(nameGroup, counter);\n                }\n            }\n        }\n        assert counter.group.equals(group) : \"mismatching groups: \" + counter.group + \" vs. \" + group;\n        int countersSize = config.jvmciCountersSize;\n        if (counter.index >= countersSize) {\n            throw new GraalError(\"too many counters, reduce number of counters or increase -XX:JVMCICounterSize=... (current value: \" + countersSize + \")\");\n        }\n        return counter;\n    }\n\n    private static synchronized void dump(OptionValues options, PrintStream out, double seconds, long[] counters, int maxRows) {\n        if (!counterMap.isEmpty()) {\n            try (Dumper dumper = Dumper.getDumper(options, out, counterMap.size(), seconds, maxRows)) {\n                TreeSet<String> set = new TreeSet<>();\n                counterMap.forEach((nameGroup, counter) -> set.add(counter.group));\n                for (String group : set) {\n                    if (group != null) {\n                        if (Options.BenchmarkCountersDumpStatic.getValue(options)) {\n                            dumper.dumpCounters(true, group, collectStaticCounters(), counterMap.entrySet(), options);\n                        }\n                        if (Options.BenchmarkCountersDumpDynamic.getValue(options)) {\n                            dumper.dumpCounters(false, group, collectDynamicCounters(counters), counterMap.entrySet(), options);\n                        }\n                    }","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/debug/BenchmarkCounters.java#L163-L199","documentation":"GraalError thrown by BenchmarkCounters when a newly allocated counter's index exceeds the native counter array size given by -XX:JVMCICounterSize. The HotSpot side pre-allocates a fixed-size array shared by all benchmark counters; the Java side checks each new (name, group) pair fits. Too many distinct counter names exhaust the array.","triggerScenarios":"Enabling -Dgraal.GenericDynamicCounters / -Dgraal.BenchmarkCounters and compiling enough distinct methods/nodes that the number of unique counters exceeds the default JVMCICounterSize array bound; counters are created lazily per name-group, so long runs or wide benchmarks cross the limit.","commonSituations":"Running large benchmark suites or full applications with benchmark counters enabled; lowering JVMCICounterSize for memory reasons and then hitting more counters than slots.","solutions":["Increase the native array: add -XX:JVMCICounterSize=<larger> (e.g. 65536) to the command line.","Reduce counter churn by disabling counter types you do not need (-Dgraal.BenchmarkCounters=false, generic dynamic counters off).","Scope the run to fewer methods/benchmarks so fewer unique counters are allocated."],"exampleFix":"# before\n-XX:+UseJVMCICompiler -Dgraal.GenericDynamicCounters=true\n# GraalError: too many counters\n\n# after\n-XX:+UseJVMCICompiler -Dgraal.GenericDynamicCounters=true -XX:JVMCICounterSize=65536","handlingStrategy":"validation","validationCode":"# Pre-flight: scale JVMCICounterSize to expected counter count before launching\nif [ -n \"$GRAAL_COUNTERS_ENABLED\" ]; then\n  export JAVA_OPTS=\"$JAVA_OPTS -XX:JVMCICounterSize=${JVMCI_COUNTER_SIZE:-65536}\"\nfi","typeGuard":null,"tryCatchPattern":"try {\n    // workload with benchmark counters enabled\n} catch (com.oracle.graal.compiler.GraalError e) { // jdk.graal.compiler.core.common.GraalError\n    if (e.getMessage().contains(\"JVMCICounterSize\")) {\n        // relaunch with a larger -XX:JVMCICounterSize\n    }\n    throw e;\n}","preventionTips":["Always pair counter options with an explicitly sized -XX:JVMCICounterSize.","Prefer counter dumps over huge unique-counter sets on full-application runs."],"tags":["graalvm","benchmarking","configuration","jvmci"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}