{"record":{"id":"f5b108b2c4cbb389","repo":"oracle/graal","slug":"map-grown-too-large","errorCode":null,"errorMessage":"map grown too large!","messagePattern":"map grown too large!","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMapImpl.java","lineNumber":472,"sourceCode":"        return null;\n    }\n\n    /**\n     * Number of entries above which a hash table should be constructed.\n     */\n    private int getHashThreshold() {\n        if (strategy == null || strategy == Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE) {\n            return HASH_THRESHOLD_IDENTITY_COMPARE;\n        } else {\n            return HASH_THRESHOLD;\n        }\n    }\n\n    private void grow() {\n        int entriesLength = entries.length;\n        int newSize = (entriesLength >> 1) + Math.max(MIN_CAPACITY_INCREASE, entriesLength >> 2);\n        if (newSize > MAX_ELEMENT_COUNT) {\n            throw new UnsupportedOperationException(\"map grown too large!\");\n        }\n        Object[] newEntries = new Object[newSize << 1];\n        System.arraycopy(entries, 0, newEntries, 0, entriesLength);\n        entries = newEntries;\n        if ((entriesLength < LARGE_HASH_THRESHOLD && newEntries.length >= LARGE_HASH_THRESHOLD) ||\n                        (entriesLength < VERY_LARGE_HASH_THRESHOLD && newEntries.length >= VERY_LARGE_HASH_THRESHOLD) ||\n                        (entriesLength < HUGE_HASH_THRESHOLD && newEntries.length >= HUGE_HASH_THRESHOLD)) {\n            // Rehash in order to change number of bits reserved for hash indices.\n            createHash();\n        }\n    }\n\n    /**\n     * Compresses the graph if there is a large number of deleted entries and returns the translated\n     * new next index.\n     */\n    private int maybeCompress(int nextIndex) {\n        if (entries.length != INITIAL_CAPACITY << 1 && deletedEntries >= (totalEntries >> 1) + (totalEntries >> 2)) {","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMapImpl.java#L454-L490","documentation":"EconomicMapImpl is an open-addressing/sparsely-sized map with a hard capacity ceiling (MAX_ELEMENT_COUNT). grow() computes the next size and, if it would exceed the ceiling, throws UnsupportedOperationException 'map grown too large!' rather than overflow.","triggerScenarios":"Inserting more entries than EconomicMap's design limit into a single EconomicMapImpl instance (long-running compiler maps, huge graphs, caches that never shrink).","commonSituations":"Compilers or tools accumulating unbounded state (e.g. memoization tables) on EconomicMap; tests feeding oversized datasets; memory-constrained configurations where the ceiling is the constraint, not the heap.","solutions":["Bound what goes into the map: evict/reset the structure instead of growing it indefinitely.","Switch to java.util.HashMap (or another map without this ceiling) for data sets that can legitimately exceed the limit.","If you hit this with steady-state workloads, look for a leak of entries (keys never removed) as the real cause."],"exampleFix":"// before\nEconomicMap<Object, Object> m = EconomicMap.create();\nfor (long i = 0; i < HUGE; i++) { m.put(i, i); }   // exceeds MAX_ELEMENT_COUNT\n\n// after\nMap<Object, Object> m = new HashMap<>();\nfor (long i = 0; i < HUGE; i++) { m.put(i, i); }","handlingStrategy":"validation","validationCode":"// EconomicMapImpl.MAX_ELEMENT_COUNT is private; guard by expected workload size instead:\nif (expectedEntries > 30_000_000) {   // well below the ceiling\n    throw new IllegalArgumentException(\"dataset too large for EconomicMap; use HashMap\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    map.put(k, v);\n} catch (UnsupportedOperationException e) {\n    if (!\"map grown too large!\".equals(e.getMessage())) throw e;\n    // switch to a HashMap fallback or spill/reset the structure\n}","preventionTips":["Use EconomicMap for compiler-sized, bounded tables only; not for unbounded user data.","Instrument entry counts on long-lived maps and reset/evict well before the ceiling.","Investigate entry leaks (keys never removed) when a steady workload hits this."],"tags":["graalvm","collections","economic-map","capacity","java"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}