to prevent OOME perform one lightweight document commit

(when there are many uncommitted documents during batch document changes)
This commit is contained in:
Maxim.Mossienko
2017-06-27 20:22:17 +02:00
parent 2ecb0a4b1f
commit bd6c40caa0
2 changed files with 19 additions and 4 deletions
@@ -357,6 +357,13 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen
protected boolean finishCommitInWriteAction(@NotNull final Document document,
@NotNull final List<Processor<Document>> finishProcessors,
final boolean synchronously) {
return finishCommitInWriteAction(document, finishProcessors, synchronously, false);
}
protected boolean finishCommitInWriteAction(@NotNull final Document document,
@NotNull final List<Processor<Document>> finishProcessors,
final boolean synchronously,
boolean forceNoPsiCommit) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myProject.isDisposed()) return false;
assert !(document instanceof DocumentWindow);
@@ -366,7 +373,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen
getSmartPointerManager().fastenBelts(virtualFile);
}
FileViewProvider viewProvider = getCachedViewProvider(document);
FileViewProvider viewProvider = forceNoPsiCommit ? null : getCachedViewProvider(document);
myIsCommitInProgress = true;
boolean success = true;
@@ -53,6 +53,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
//todo listen & notifyListeners readonly events?
@@ -124,7 +125,13 @@ public class PsiDocumentManagerImpl extends PsiDocumentManagerBase implements Se
if (PomModelImpl.isAllowPsiModification()
// it can happen that document(forUseInNonAWTThread=true) outside write action caused this
&& ApplicationManager.getApplication().isWriteAccessAllowed()) {
commitAllDocuments();
// commit document to avoid OOME
for (Document document : myUncommittedDocuments) {
if (document != event.getDocument()) {
finishCommitInWriteAction(document, Collections.emptyList(), true, true);
break;
}
}
}
}
}
@@ -139,11 +146,12 @@ public class PsiDocumentManagerImpl extends PsiDocumentManagerBase implements Se
@Override
protected boolean finishCommitInWriteAction(@NotNull Document document,
@NotNull List<Processor<Document>> finishProcessors,
boolean synchronously) {
boolean synchronously,
boolean forceNoPsiCommit) {
if (ApplicationManager.getApplication().isWriteAccessAllowed()) { // can be false for non-physical PSI
EditorWindowImpl.disposeInvalidEditors();
}
return super.finishCommitInWriteAction(document, finishProcessors, synchronously);
return super.finishCommitInWriteAction(document, finishProcessors, synchronously, forceNoPsiCommit);
}
@Override