oracle/graal · error · UnsupportedOperationException

map grown too large!

Error message

map grown too large!

What it means

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.

Source

Thrown at sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMapImpl.java:472

        return null;
    }

    /**
     * Number of entries above which a hash table should be constructed.
     */
    private int getHashThreshold() {
        if (strategy == null || strategy == Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE) {
            return HASH_THRESHOLD_IDENTITY_COMPARE;
        } else {
            return HASH_THRESHOLD;
        }
    }

    private void grow() {
        int entriesLength = entries.length;
        int newSize = (entriesLength >> 1) + Math.max(MIN_CAPACITY_INCREASE, entriesLength >> 2);
        if (newSize > MAX_ELEMENT_COUNT) {
            throw new UnsupportedOperationException("map grown too large!");
        }
        Object[] newEntries = new Object[newSize << 1];
        System.arraycopy(entries, 0, newEntries, 0, entriesLength);
        entries = newEntries;
        if ((entriesLength < LARGE_HASH_THRESHOLD && newEntries.length >= LARGE_HASH_THRESHOLD) ||
                        (entriesLength < VERY_LARGE_HASH_THRESHOLD && newEntries.length >= VERY_LARGE_HASH_THRESHOLD) ||
                        (entriesLength < HUGE_HASH_THRESHOLD && newEntries.length >= HUGE_HASH_THRESHOLD)) {
            // Rehash in order to change number of bits reserved for hash indices.
            createHash();
        }
    }

    /**
     * Compresses the graph if there is a large number of deleted entries and returns the translated
     * new next index.
     */
    private int maybeCompress(int nextIndex) {
        if (entries.length != INITIAL_CAPACITY << 1 && deletedEntries >= (totalEntries >> 1) + (totalEntries >> 2)) {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Bound what goes into the map: evict/reset the structure instead of growing it indefinitely.
  2. Switch to java.util.HashMap (or another map without this ceiling) for data sets that can legitimately exceed the limit.
  3. If you hit this with steady-state workloads, look for a leak of entries (keys never removed) as the real cause.

Example fix

// before
EconomicMap<Object, Object> m = EconomicMap.create();
for (long i = 0; i < HUGE; i++) { m.put(i, i); }   // exceeds MAX_ELEMENT_COUNT

// after
Map<Object, Object> m = new HashMap<>();
for (long i = 0; i < HUGE; i++) { m.put(i, i); }
Defensive patterns

Strategy: validation

Validate before calling

// EconomicMapImpl.MAX_ELEMENT_COUNT is private; guard by expected workload size instead:
if (expectedEntries > 30_000_000) {   // well below the ceiling
    throw new IllegalArgumentException("dataset too large for EconomicMap; use HashMap");
}

Try / catch

try {
    map.put(k, v);
} catch (UnsupportedOperationException e) {
    if (!"map grown too large!".equals(e.getMessage())) throw e;
    // switch to a HashMap fallback or spill/reset the structure
}

Prevention

When it happens

Trigger: Inserting more entries than EconomicMap's design limit into a single EconomicMapImpl instance (long-running compiler maps, huge graphs, caches that never shrink).

Common situations: 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.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/f5b108b2c4cbb389. Report an issue: GitHub.