1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 212998: CModelManager consumes a lot of memory during project refresh

This commit is contained in:
Anton Leherbauer 2008-01-31 11:17:28 +00:00
parent e88356657e
commit 645d096b60
6 changed files with 50 additions and 37 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -91,7 +91,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/**
* Used to convert <code>IResourceDelta</code>s into <code>ICElementDelta</code>s.
*/
protected DeltaProcessor fDeltaProcessor = new DeltaProcessor();
protected final DeltaProcessor fDeltaProcessor = new DeltaProcessor();
/**
* Queue of deltas created explicitly by the C Model that
@ -101,7 +101,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
/**
* Queue of reconcile deltas on working copies that have yet to be fired.
* This is a table form IWorkingCopy to IJavaElementDelta
* This is a table form IWorkingCopy to ICElementDelta
*/
HashMap reconcileDeltas = new HashMap();
@ -902,7 +902,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
private void firePreAutoBuildDelta(ICElementDelta deltaToNotify,
IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.println("FIRING PRE_AUTO_BUILD Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
}
@ -914,7 +914,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
private void firePostChangeDelta(ICElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
// post change deltas
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.println("FIRING POST_CHANGE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
}
@ -927,7 +927,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
private void fireReconcileDelta(IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
ICElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas.values());
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.println("FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
}
@ -941,7 +941,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
private void fireShiftEvent(ICElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) {
// post change deltas
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.println("FIRING POST_SHIFT event [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
}
@ -959,7 +959,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (listenerMask == null || (listenerMask[i] & eventType) != 0) {
final IElementChangedListener listener = listeners[i];
long start = -1;
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.print("Listener #" + (i + 1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$
start = System.currentTimeMillis();
}
@ -974,7 +974,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
listener.elementChanged(extraEvent);
}
});
if (VERBOSE) {
if (Util.VERBOSE_DELTA) {
System.out.println(" -> " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 IBM Corporation and others.
* Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -35,24 +35,17 @@ import org.eclipse.core.runtime.IPath;
* It also does some processing on the <code>CElement</code>s involved
* (e.g. closing them or updating classpaths).
*/
public class DeltaProcessor {
final class DeltaProcessor {
/**
* The <code>CElementDelta</code> corresponding to the <code>IResourceDelta</code> being translated.
*/
protected CElementDelta fCurrentDelta;
/* The C element that was last created (see createElement(IResource).
* This is used as a stack of C elements (using getParent() to pop it, and
* using the various get*(...) to push it. */
ICElement currentElement;
private CElementDelta fCurrentDelta;
static final ICElementDelta[] NO_DELTA = new ICElementDelta[0];
public static boolean VERBOSE = false;
// Hold on the element bein renamed.
ICElement movedFromElement = null;
private ICElement movedFromElement = null;
/**
* Creates the create corresponding to this resource.
@ -440,7 +433,10 @@ public class DeltaProcessor {
traverseDelta(root, delta); // traverse delta
translatedDeltas[i] = fCurrentDelta;
}
return filterRealDeltas(translatedDeltas);
ICElementDelta[] filteredDeltas= filterRealDeltas(translatedDeltas);
// release deltas
fCurrentDelta= null;
return filteredDeltas;
} finally {
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 IBM Corporation and others.
* Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -40,6 +40,7 @@ public class Util implements ICLogConstants {
public static boolean VERBOSE_PARSER = false;
public static boolean VERBOSE_SCANNER = false;
public static boolean VERBOSE_MODEL = false;
public static boolean VERBOSE_DELTA = false;
public static boolean PARSER_EXCEPTIONS= false;
public static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation and others.
* Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -231,6 +231,12 @@ public class LRUCache implements Cloneable {
return fEntryTable.keys();
}
/**
* Tests if this cache is empty.
*/
public boolean isEmpty() {
return fEntryTable.isEmpty();
}
/**
* Returns an enumeration that iterates over all the keys and values
* currently in the cache.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -49,7 +49,6 @@ import org.eclipse.cdt.internal.core.cdtvariables.CdtVariableManager;
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
import org.eclipse.cdt.internal.core.model.BufferManager;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.DeltaProcessor;
import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.Util;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
@ -1060,7 +1059,7 @@ public class CCorePlugin extends Plugin {
if(option != null) Util.VERBOSE_MODEL = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
option = Platform.getDebugOption(DELTA);
if(option != null) DeltaProcessor.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
if(option != null) Util.VERBOSE_DELTA= option.equalsIgnoreCase("true") ; //$NON-NLS-1$
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,14 +7,17 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.parser;
import java.io.File;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.parser.EmptyIterator;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.util.ILRUCacheable;
import org.eclipse.cdt.internal.core.util.LRUCache;
import org.eclipse.cdt.internal.core.util.OverflowingLRUCache;
@ -53,7 +56,7 @@ public class CodeReaderCache implements ICodeReaderCache {
public static final String DEFAULT_CACHE_SIZE_IN_MB_STRING = String.valueOf(DEFAULT_CACHE_SIZE_IN_MB);
private static final int MB_TO_KB_FACTOR = 1024;
private CodeReaderLRUCache cache = null; // the actual cache
private IResourceChangeListener listener = new UpdateCodeReaderCacheListener(this);
private final IResourceChangeListener listener = new UpdateCodeReaderCacheListener(this);
private class UpdateCodeReaderCacheListener implements IResourceChangeListener {
ICodeReaderCache c = null;
@ -88,7 +91,7 @@ public class CodeReaderCache implements ICodeReaderCache {
if (event.getSource() instanceof IWorkspace && event.getDelta() != null) {
removeKeys(event.getDelta().getAffectedChildren());
}
event = null;
return Status.OK_STATUS;
}
@ -127,15 +130,11 @@ public class CodeReaderCache implements ICodeReaderCache {
*/
public CodeReaderCache(int size) {
cache = new CodeReaderLRUCache(size * MB_TO_KB_FACTOR);
if (ResourcesPlugin.getWorkspace() != null)
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
}
protected void finalize() throws Throwable {
flush();
super.finalize();
if (ResourcesPlugin.getWorkspace() != null)
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
}
/**
@ -155,7 +154,8 @@ public class CodeReaderCache implements ICodeReaderCache {
if (!(new File(key).exists()))
return null;
ret = ParserUtil.createReader(key, EmptyIterator.EMPTY_ITERATOR);
final List<IWorkingCopy> emptyList= Collections.emptyList();
ret = ParserUtil.createReader(key, emptyList.iterator());
if (cache.getSpaceLimit() > 0)
put(ret);
@ -172,6 +172,10 @@ public class CodeReaderCache implements ICodeReaderCache {
*/
private synchronized CodeReader put(CodeReader value) {
if (value==null) return null;
if (cache.isEmpty()) {
if (ResourcesPlugin.getWorkspace() != null)
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
}
return cache.put(String.valueOf(value.filename), value);
}
@ -302,7 +306,12 @@ public class CodeReaderCache implements ICodeReaderCache {
* @param key
*/
public synchronized CodeReader remove(String key) {
return cache.remove(key);
CodeReader removed= cache.remove(key);
if (cache.isEmpty()) {
if (ResourcesPlugin.getWorkspace() != null)
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
}
return removed;
}
/**
@ -315,6 +324,8 @@ public class CodeReaderCache implements ICodeReaderCache {
public void flush() {
cache.flush();
if (ResourcesPlugin.getWorkspace() != null)
ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
}
}