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 3665d1e92..e635dd95f 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -602,7 +602,7 @@ public class LexerATNSimulator extends ATNSimulator { } DFA dfa = decisionToDFA[mode]; - synchronized (dfa) { + synchronized (p) { if ( p.edges==null ) { // make room for tokens 1..n and -1 masquerading as index 0 p.edges = new DFAState[MAX_DFA_EDGE-MIN_DFA_EDGE+1]; @@ -641,7 +641,7 @@ public class LexerATNSimulator extends ATNSimulator { } DFA dfa = decisionToDFA[mode]; - synchronized (dfa) { + synchronized (dfa.states) { DFAState existing = dfa.states.get(proposed); if ( existing!=null ) return existing; @@ -650,7 +650,7 @@ public class LexerATNSimulator extends ATNSimulator { newState.stateNumber = dfa.states.size(); configs.setReadonly(true); newState.configs = configs; - decisionToDFA[mode].states.put(newState, newState); + dfa.states.put(newState, newState); return newState; } } 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 fc7e94e10..b1ad17a26 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -1546,7 +1546,7 @@ public class ParserATNSimulator extends ATNSimulator { if ( debug ) System.out.println("EDGE "+from+" -> "+to+" upon "+getTokenName(t)); if ( from==null || t < -1 || to == null ) return; to = addDFAState(dfa, to); // used existing if possible not incoming - synchronized (dfa) { + synchronized (from) { if ( from.edges==null ) { from.edges = new DFAState[atn.maxTokenType+1+1]; // TODO: make adaptive } @@ -1557,7 +1557,7 @@ public class ParserATNSimulator extends ATNSimulator { /** Add D if not there and return D. Return previous if already present. */ protected DFAState addDFAState(@NotNull DFA dfa, @NotNull DFAState D) { - synchronized (dfa) { + synchronized (dfa.states) { DFAState existing = dfa.states.get(D); if ( existing!=null ) return existing;