back to core sync around creating DFA in decisionToDFA. not thread-safe for dfa update.

This commit is contained in:
Terence Parr 2012-07-29 14:33:18 -07:00
parent 4fe9efeb85
commit f5f6715a07
3 changed files with 16 additions and 30 deletions

View File

@ -162,10 +162,6 @@ public class LexerATNSimulator extends ATNSimulator {
int mark = input.mark();
traceBeginMatch(input, mode);
try {
synchronized (decisionToDFA[mode]) {
// Synchronizing on the mode DFA causes a lot of contention
// between shared lexers in multiple threads, but is the
// simplest safety measure. We can start with it.
if ( decisionToDFA[mode].s0==null ) {
return matchATN(input);
}
@ -173,7 +169,6 @@ public class LexerATNSimulator extends ATNSimulator {
return execDFA(input, decisionToDFA[mode].s0);
}
}
}
finally {
traceEndMatch();
input.release(mark);

View File

@ -196,18 +196,10 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
}
}
// Now we are certain to have a specific decision's DFA
// Synchronize on the DFA so that nobody can read or write
// to it while we updated during ATN simulation
synchronized (decisionToDFA[decision]) {
return predictATN(dfa, input, outerContext);
}
}
// We can start with an existing DFA
synchronized (decisionToDFA[decision]) {
// Only enter the DFA simulation if nobody else is playing with it.
// This blocks multiple readonly simulations of the same DFA but that's
// unlikely to happen a lot
int m = input.mark();
int index = input.index();
try {
@ -219,7 +211,6 @@ public class ParserATNSimulator<Symbol extends Token> extends ATNSimulator {
input.release(m);
}
}
}
public int predictATN(@NotNull DFA dfa, @NotNull TokenStream input,
@Nullable ParserRuleContext<?> outerContext)

View File

@ -36,7 +36,7 @@ public class PredictionContextCache {
return cache.get(ctx);
}
public synchronized int size() {
public int size() {
return cache.size();
}
}