Class PredictionContextCache
PredictionContext objects. It is used for the shared
context cache associated with contexts in DFA states. This cache can be used
for both lexers and parsers.
Cache instances created with PredictionContextCache() are intended
for single-threaded use during a prediction operation. Concurrent access from
multiple threads is not supported (the shared UNCACHED instance is
safe because caching is disabled and no mutable probe state is retained).
PERF: getChild(org.antlr.v4.runtime.atn.PredictionContext, int) and join(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext) use mutable probe keys for map
lookups so a cache hit does not allocate a key object. Permanent keys are
allocated only on a cache miss when the entry is stored. Probe types are
distinct from permanent key types so a probe can never be inserted into the
map: the maps are typed as Map<PredictionContextAndInt, …> and
Map<IdentityCommutativePredictionContextOperands, …>, while
Map.get(Object) still accepts probes because equality is defined on
the shared ChildKey/JoinKey bases.
join(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext) may re-enter itself recursively via
PredictionContext.join(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext); the probe key is only used for the duration
of each individual map lookup, and map insertions always use freshly
allocated immutable keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classShared equality/hash contract for (PredictionContext,int) keys used bygetChild(org.antlr.v4.runtime.atn.PredictionContext, int).private static final classMutable probe forgetChild(org.antlr.v4.runtime.atn.PredictionContext, int)lookups.protected static final classImmutable identity-based commutative key for a pair ofPredictionContextinstances.(package private) static classShared equality/hash contract for identity-based commutative pairs ofPredictionContextused byjoin(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext)and byArrayPredictionContextequality.private static final classMutable probe forjoin(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext)lookups.protected static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<PredictionContextCache.PredictionContextAndInt,PredictionContext> private final PredictionContextCache.ChildKeyProbeReusable probe forgetChild(org.antlr.v4.runtime.atn.PredictionContext, int).private final Map<PredictionContext,PredictionContext> private final booleanprivate final Map<PredictionContextCache.IdentityCommutativePredictionContextOperands,PredictionContext> private final PredictionContextCache.JoinKeyProbestatic final PredictionContextCache -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) final voidclear()Drops every cached entry so this instance can be retained across predictions on a single simulator thread.getAsCached(PredictionContext context) getChild(PredictionContext context, int invokingState) (package private) final booleanReturns whether this cache stores contexts.
-
Field Details
-
UNCACHED
-
childContexts
-
joinContexts
private final Map<PredictionContextCache.IdentityCommutativePredictionContextOperands,PredictionContext> joinContexts -
contexts
-
childProbe
Reusable probe forgetChild(org.antlr.v4.runtime.atn.PredictionContext, int). Never passed toMap.put(K, V). -
joinProbe
Reusable probe forjoin(org.antlr.v4.runtime.atn.PredictionContext, org.antlr.v4.runtime.atn.PredictionContext). Never passed toMap.put(K, V). -
enableCache
private final boolean enableCache
-
-
Constructor Details
-
PredictionContextCache
public PredictionContextCache() -
PredictionContextCache
private PredictionContextCache(boolean enableCache)
-
-
Method Details
-
isEnableCache
final boolean isEnableCache() -
getAsCached
-
clear
final void clear()Drops every cached entry so this instance can be retained across predictions on a single simulator thread. No-op forUNCACHED.Package-private: only the ATN simulators recycle a retained cache.
-
getChild
-
join
-