Suppress low memory notifications and restrict max wait time when unloading plugins (IDEA-225451)

GitOrigin-RevId: 41945ba547de7a7e449bb7a549551cc5ef652a59
This commit is contained in:
Dmitry Jemerov
2019-10-24 17:02:44 +00:00
committed by intellij-monorepo-bot
parent 5d43865203
commit 3245268db3
2 changed files with 15 additions and 16 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.util;
import com.intellij.openapi.Disposable;
@@ -21,6 +7,8 @@ import com.intellij.util.containers.WeakList;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* @author Eugene Zhuravlev
*/
@@ -35,8 +23,10 @@ public class LowMemoryWatcher {
private static final WeakList<LowMemoryWatcher> ourListeners = new WeakList<>();
private final Runnable myRunnable;
private final LowMemoryWatcherType myType;
public static final AtomicBoolean ourNotificationsSuppressed = new AtomicBoolean();
public static void onLowMemorySignalReceived(boolean afterGc) {
if (ourNotificationsSuppressed.get()) return;
LOG.info("Low memory signal received: afterGc=" + afterGc);
for (LowMemoryWatcher watcher : ourListeners.toStrongList()) {
try {
@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.ref;
import com.intellij.openapi.util.LowMemoryWatcher;
import com.intellij.openapi.util.Ref;
import com.intellij.reference.SoftReference;
import com.intellij.util.MemoryDumpHelper;
@@ -68,7 +69,15 @@ public class GCWatcher {
}
public boolean tryCollect() {
return GCUtil.allocateTonsOfMemory(new StringBuilder(), this::isEverythingCollected);
LowMemoryWatcher.ourNotificationsSuppressed.set(true);
try {
long startTime = System.currentTimeMillis();
GCUtil.allocateTonsOfMemory(new StringBuilder(), () -> isEverythingCollected() && System.currentTimeMillis() - startTime < 5000);
return isEverythingCollected();
}
finally {
LowMemoryWatcher.ourNotificationsSuppressed.set(false);
}
}
/**