From 2911f9c876a80e7cad3e46338c69a981bdfdbb18 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 23 May 2011 15:43:08 +0400 Subject: [PATCH] OOME in indexing: more precise limit to simultaneously indexed files size [rev. by cdr] --- .../openapi/project/FileContentQueue.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java index c506347723cd..9eb48b9a19c6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java @@ -40,9 +40,11 @@ public class FileContentQueue { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.startup.FileContentQueue"); private static final long SIZE_THRESHOLD = 1024*1024; private static final long TAKEN_FILES_THRESHOLD = 1024*1024*4; + private static final long LARGE_SIZE_REQUEST_THRESHOLD = TAKEN_FILES_THRESHOLD - SIZE_THRESHOLD; private long myTotalSize; private long myTakenSize; + private boolean myLargeSizeRequested; private final ArrayBlockingQueue myQueue = new ArrayBlockingQueue(256); private final Queue myPushbackBuffer = new ArrayDeque(); @@ -141,21 +143,33 @@ public class FileContentQueue { FileContent content = doTake(); if (content != null) { - synchronized (this) { - while (myTakenSize > TAKEN_FILES_THRESHOLD) { - final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); - if (indicator != null) { - indicator.checkCanceled(); + final long length = content.getLength(); + while (true) { + final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + if (indicator != null) { + indicator.checkCanceled(); + } + synchronized (this) { + boolean requestingLargeSize = length > LARGE_SIZE_REQUEST_THRESHOLD; + if (requestingLargeSize) { + myLargeSizeRequested = true; } try { - wait(300); + if (myLargeSizeRequested && !requestingLargeSize || + myTakenSize + length > Math.max(TAKEN_FILES_THRESHOLD, length)) + wait(300); + else { + myTakenSize += length; + if (requestingLargeSize) { + myLargeSizeRequested = false; + } + return content; + } } catch (InterruptedException ignore) { } } - myTakenSize += content.getLength(); - notifyAll(); } } return content;