diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java index 8742d8a3e..9b4549cd9 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -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 { diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 828e09dad..fd807be25 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -196,28 +196,19 @@ public class ParserATNSimulator 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); } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java index ee5da0a6a..04d7b1529 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContextCache.java @@ -36,7 +36,7 @@ public class PredictionContextCache { return cache.get(ctx); } - public synchronized int size() { + public int size() { return cache.size(); } }