log.info and print dumps when code cache is (almost) full

This commit is contained in:
peter
2015-12-03 16:48:16 +01:00
parent 4ca05475cf
commit 41c76ae907
@@ -26,10 +26,13 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.management.ListenerNotFoundException;
import javax.management.Notification;
import javax.management.NotificationEmitter;
import javax.management.NotificationListener;
import javax.swing.*;
import java.io.*;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.lang.management.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
@@ -130,6 +133,36 @@ public class PerformanceWatcher implements ApplicationComponent {
}, "Performance watcher");
myThread.setPriority(Thread.MIN_PRIORITY);
myThread.start();
for (MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans()) {
if ("Code Cache".equals(bean.getName())) {
watchCodeCache(bean);
return;
}
}
}
private void watchCodeCache(final MemoryPoolMXBean bean) {
final long threshold = bean.getUsage().getMax() - 5 * 1024 * 1024;
if (!bean.isUsageThresholdSupported() || threshold <= 0) return;
bean.setUsageThreshold(threshold);
final NotificationEmitter emitter = (NotificationEmitter)ManagementFactory.getMemoryMXBean();
emitter.addNotificationListener(new NotificationListener() {
@Override
public void handleNotification(Notification n, Object hb) {
if (bean.getUsage().getUsed() > threshold) {
LOG.info("Code Cache is almost full");
dumpThreads("codeCacheFull", true);
try {
emitter.removeNotificationListener(this);
}
catch (ListenerNotFoundException e) {
LOG.error(e);
}
}
}
}, null, null);
}
private static void deleteOldThreadDumps() {