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,16 +162,11 @@ 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);
}
else {
return execDFA(input, decisionToDFA[mode].s0);
}
if ( decisionToDFA[mode].s0==null ) {
return matchATN(input);
}
else {
return execDFA(input, decisionToDFA[mode].s0);
}
}
finally {

View File

@ -196,28 +196,19 @@ 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);
}
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 {
int alt = execDFA(dfa, dfa.s0, input, index, outerContext);
return alt;
}
finally {
input.seek(index);
input.release(m);
}
int m = input.mark();
int index = input.index();
try {
int alt = execDFA(dfa, dfa.s0, input, index, outerContext);
return alt;
}
finally {
input.seek(index);
input.release(m);
}
}

View File

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