Package: org.apache.groovy.parser.antlr4.internal.atnmanager

## [Java] Class AtnManager

- org.apache.groovy.parser.antlr4.internal.atnmanager.AtnManager

-     public abstract class AtnManager
      extends Object

  Manage ATN to avoid memory leak.

  The mutable prediction caches (DFA states, prediction contexts, LL(1) table) live on a private ATN owned by a softly referenced AtnWrapper, not on the generated parser's static ATN. That single decision provides the memory-pressure response: while parsers are active the wrapper is strongly reachable through their interpreters, and once this copy of the runtime goes idle the whole cache graph is only softly reachable, so the collector reclaims it directly — no cleaner thread (which would pin the defining class loader for the life of the JVM, GROOVY-12142), and no clear-on-next-parse canary (which never fires for an idle copy: a build daemon caches one runtime copy per distinct classpath, and every idle copy's fully warmed cache stayed strongly reachable until the daemon spent more time collecting than parsing).

  Two deterministic mechanisms bound the cache while a copy is active, and they compose:

  - a size ceiling — `groovy.antlr4.cache.size` DFA states retained across the shared ATN; exceeding it replaces the wrapper with a fresh one. The default scales with the heap so a large daemon keeps a warm working set while a small JVM stays protected.
  - a parse counter — replaces the wrapper every `groovy.antlr4.cache.threshold` parses, for workloads that want a fixed cadence. Off by default.
  A replaced wrapper is never mutated: parses in flight finish undisturbed on the old ATN, which becomes collectable as they complete. Nothing is cleared in place, so parsing no longer serialises against a write lock.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `protected class` | `AtnManager.AtnWrapper` |

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static ReadLock` | `READ_LOCK` |

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected abstract AtnManager.AtnWrapper` | `createAtnWrapper()`
    `` | `public ATN` | `getATN()`
    `` | `protected AtnManager.AtnWrapper` | `getAtnWrapper()`
    `` | `protected abstract boolean` | `shouldClearDfaCache()`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final ReadLock READ_LOCK

  - ### Method Detail

    - #### protected abstract AtnManager.AtnWrapper createAtnWrapper()

    - #### public ATN getATN()

    - #### protected AtnManager.AtnWrapper getAtnWrapper()

    - #### protected abstract boolean shouldClearDfaCache()