From cdb4b9a22bc330e4f886823be4ea00c16c5f8e10 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 11 Jul 2025 15:07:43 +0200 Subject: [PATCH] do not hard-retain changed documents (via myUncommitInfos->UncommitInfo.events) to allow even changed documents to gc (part of IJPL-50077 freezing on replace) GitOrigin-RevId: 48006283b99d61fb71f2a591cb87a534fd52a2df --- .../psi/impl/PsiDocumentManagerBase.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java index 4078fcc72b45..34a3ae7e7846 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java @@ -75,8 +75,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen @ApiStatus.Internal protected final Set myUncommittedDocuments = Collections.newSetFromMap(CollectionFactory.createConcurrentWeakMap()); private final Map myUncommittedDocumentTraces = CollectionFactory.createConcurrentWeakMap(); - private final Map myUncommittedInfos = new ConcurrentHashMap<>(); - private /*non-static*/ final Key FREE_THREADED_UNCOMMITTED_INFO = Key.create("FREE_THREADED_UNCOMMITTED_INFO"); + private /*non-static*/ final Key UNCOMMITTED_INFO_KEY = Key.create("UNCOMMITTED_INFO"); @ApiStatus.Internal protected boolean myStopTrackingDocuments; @@ -903,7 +902,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen } UncommittedInfo info = getUncommittedInfo(delegate); - DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document); + DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(window); if (answer == null) answer = freezeWindow(window); if (info != null) answer = ConcurrencyUtil.cacheOrGet(info.myFrozenWindows, window, answer); return (DocumentEx)answer; @@ -915,17 +914,11 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen } private @Nullable UncommittedInfo getUncommittedInfo(@NotNull Document document) { - UncommittedInfo info = myUncommittedInfos.get(document); - return info != null ? info : document.getUserData(FREE_THREADED_UNCOMMITTED_INFO); + return document.getUserData(UNCOMMITTED_INFO_KEY); } private void associateUncommittedInfo(Document document, UncommittedInfo info) { - if (isEventSystemEnabled(document)) { - myUncommittedInfos.put(document, info); - } - else { - document.putUserData(FREE_THREADED_UNCOMMITTED_INFO, info); - } + document.putUserData(UNCOMMITTED_INFO_KEY, info); } protected @NotNull DocumentWindow freezeWindow(@NotNull DocumentWindow document) { @@ -1164,8 +1157,7 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen private @Nullable UncommittedInfo clearUncommittedInfo(@NotNull Document document) { UncommittedInfo info = getUncommittedInfo(document); if (info != null) { - myUncommittedInfos.remove(document); - document.putUserData(FREE_THREADED_UNCOMMITTED_INFO, null); + document.putUserData(UNCOMMITTED_INFO_KEY, null); getSmartPointerManager().updatePointers(document, info.myFrozen, info.myEvents); } return info; @@ -1245,7 +1237,6 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen @TestOnly public void clearUncommittedDocuments() { - myUncommittedInfos.clear(); myUncommittedDocuments.clear(); myUncommittedDocumentTraces.clear(); mySynchronizer.cleanupForNextTest();