Class AtnManager
- Direct Known Subclasses:
LexerAtnManager,ParserAtnManager
The mutable prediction caches (DFA states, prediction contexts, LL(1) table) live on a
private ATN owned by a softly referenced AtnManager.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.sizeDFA 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.thresholdparses, for workloads that want a fixed cadence. Off by default.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classOne ATN and the counters that decide when to retire it. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReentrantReadWriteLock.ReadLockRead lock of the fair lock kept for binary compatibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AtnManager.AtnWrapperCreates the wrapper installed whengetAtnWrapper()finds no live reference.org.antlr.v4.runtime.atn.ATNgetATN()Returns the ATN from the current wrapper.protected AtnManager.AtnWrapperReturns the softly referenced wrapper, creating one when the reference is missing or has been cleared.protected abstract booleanWhether this manager participates in cache dropping.
-
Field Details
-
READ_LOCK
Read lock of the fair lock kept for binary compatibility. Parsing does not acquire it. An over-limit cache is replaced rather than cleared under the matching write lock.
-
-
Constructor Details
-
AtnManager
public AtnManager()
-
-
Method Details
-
getATN
public org.antlr.v4.runtime.atn.ATN getATN()Returns the ATN from the current wrapper.AtnManager.AtnWrapper.checkAndReplace()may publish a fresh wrapper for a later call, but the ATN returned here is still the one that was current. Parses already holding it keep using it.- Returns:
- the current wrapper's ATN
-
createAtnWrapper
Creates the wrapper installed whengetAtnWrapper()finds no live reference.- Returns:
- a wrapper owning a fresh ATN
-
getAtnWrapper
Returns the softly referenced wrapper, creating one when the reference is missing or has been cleared. The check outside the lock is repeated inside it, so concurrent misses install a single wrapper.- Returns:
- the live wrapper, never a cleared reference
-
shouldClearDfaCache
protected abstract boolean shouldClearDfaCache()Whether this manager participates in cache dropping. Dropping also requires the global policy: a negativegroovy.antlr4.cache.thresholdswitches it off.- Returns:
truewhen this manager's caches may be retired
-