Class ParseWorkload
java.lang.Object
org.antlr.v4.test.runtime.java.api.perf.jmh.ParseWorkload
Shared parse/lex helpers for JMH and the comparative harness.
Threading model matches real multi-file front ends (Groovy, etc.):
- Each worker owns its own lexer/parser (simulators are not shared across concurrent predictions).
- DFA is stored on the static ATN and is therefore shared across workers when not cleared — the common "warm shared cache" case.
clearDfaforces ATN simulation on the hot path (stresses retained scratch, HPPC maps, hash cache, sparse clear).
Language-specific construction is a ParseWorkload.FrontEnd. Java and the
compact Groovy-like grammar share parseSerial(java.util.List<org.antlr.v4.test.runtime.java.api.perf.jmh.CorpusLoader.SourceFile>, org.antlr.v4.test.runtime.java.api.perf.jmh.ParseWorkload.PredictionStrategy, boolean, boolean) /
parseParallel(java.util.List<org.antlr.v4.test.runtime.java.api.perf.jmh.CorpusLoader.SourceFile>, org.antlr.v4.test.runtime.java.api.perf.jmh.ParseWorkload.PredictionStrategy, boolean, boolean, int) instead of copying the thread pool.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceLexer/parser factory for one generated language front end.static enumstatic final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanacceptsTwoStage(String text) True if two-stage parse completes without throwing.static booleanacceptsTwoStage(ParseWorkload.FrontEnd frontEnd, String text) static voidprivate static voidinvokeJava(JavaParser parser, CommonTokenStream tokens, ParseWorkload.PredictionStrategy strategy, boolean buildTree) static intstatic intlexFile(ParseWorkload.FrontEnd frontEnd, String text, boolean clearDfa) static intRebindlexertotextand fill a token stream.static intparseFile(String text, ParseWorkload.PredictionStrategy strategy, boolean clearDfa, boolean buildTree) static intparseFile(ParseWorkload.FrontEnd frontEnd, String text, ParseWorkload.PredictionStrategy strategy, boolean clearDfa, boolean buildTree) static ParseWorkload.StatsparseParallel(List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaAtStart, boolean buildTree, int threads) Parse all files withthreadsworkers (file-granularity parallelism).static ParseWorkload.StatsparseParallel(ParseWorkload.FrontEnd frontEnd, List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaAtStart, boolean buildTree, int threads) static ParseWorkload.StatsparseSerial(List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaPerFile, boolean buildTree) Parse all files on the calling thread.static ParseWorkload.StatsparseSerial(ParseWorkload.FrontEnd frontEnd, List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaPerFile, boolean buildTree) private static voidrunStartRule(ParseWorkload.FrontEnd frontEnd, Parser parser, CommonTokenStream tokens, ParseWorkload.PredictionStrategy strategy, boolean buildTree) static voidtouch()Force class/ATN initialization and a tiny parse for JIT warmup helpers.
-
Field Details
-
JAVA
-
-
Constructor Details
-
ParseWorkload
private ParseWorkload()
-
-
Method Details
-
lexFile
-
lexFile
-
lexReuse
Rebindlexertotextand fill a token stream. ExercisesLexer.setInputStream(org.antlr.v4.runtime.CharStream)/Lexer.reset()without allocating a new lexer class (IDE / REPL / batch reuse). -
parseFile
public static int parseFile(String text, ParseWorkload.PredictionStrategy strategy, boolean clearDfa, boolean buildTree) - Returns:
- token count; never throws for ordinary syntax issues when using
ParseWorkload.PredictionStrategy.LLorParseWorkload.PredictionStrategy.TWO_STAGE(error recovery / two-stage retry).ParseWorkload.PredictionStrategy.SLLuses BailErrorStrategy and may throwParseCancellationException.
-
invokeJava
private static void invokeJava(JavaParser parser, CommonTokenStream tokens, ParseWorkload.PredictionStrategy strategy, boolean buildTree) -
parseFile
public static int parseFile(ParseWorkload.FrontEnd frontEnd, String text, ParseWorkload.PredictionStrategy strategy, boolean clearDfa, boolean buildTree) -
runStartRule
private static void runStartRule(ParseWorkload.FrontEnd frontEnd, Parser parser, CommonTokenStream tokens, ParseWorkload.PredictionStrategy strategy, boolean buildTree) -
acceptsTwoStage
True if two-stage parse completes without throwing. -
acceptsTwoStage
-
parseSerial
public static ParseWorkload.Stats parseSerial(List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaPerFile, boolean buildTree) Parse all files on the calling thread.- Parameters:
clearDfaPerFile- when true, clear shared DFA before each file (serial-only ATN hot path; invalid under concurrent shared-ATN use)
-
parseSerial
public static ParseWorkload.Stats parseSerial(ParseWorkload.FrontEnd frontEnd, List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaPerFile, boolean buildTree) -
parseParallel
public static ParseWorkload.Stats parseParallel(List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaAtStart, boolean buildTree, int threads) throws InterruptedException, ExecutionException Parse all files withthreadsworkers (file-granularity parallelism). Each task uses its own lexer/parser; DFA is shared via the static ATN (Groovy-style parallel front end).- Parameters:
clearDfaAtStart- when true, clear shared DFA once before the batch so this iteration measures concurrent DFA construction; never clears per-file (would race on the shared ATN)- Throws:
InterruptedExceptionExecutionException
-
parseParallel
public static ParseWorkload.Stats parseParallel(ParseWorkload.FrontEnd frontEnd, List<CorpusLoader.SourceFile> files, ParseWorkload.PredictionStrategy strategy, boolean clearDfaAtStart, boolean buildTree, int threads) throws InterruptedException, ExecutionException -
touch
public static void touch()Force class/ATN initialization and a tiny parse for JIT warmup helpers.