View | Details | Raw Unified | Return to bug 175531
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/BufferCache.java (-1 / +13 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.util.ArrayList;
14
13
import org.eclipse.jdt.core.IBuffer;
15
import org.eclipse.jdt.core.IBuffer;
14
import org.eclipse.jdt.internal.core.util.LRUCache;
16
import org.eclipse.jdt.internal.core.util.LRUCache;
15
17
Lines 17-22 Link Here
17
 * An LRU cache of <code>IBuffers</code>.
19
 * An LRU cache of <code>IBuffers</code>.
18
 */
20
 */
19
public class BufferCache extends OverflowingLRUCache {
21
public class BufferCache extends OverflowingLRUCache {
22
	
23
	private ArrayList buffersToClose = new ArrayList();
20
/**
24
/**
21
 * Constructs a new buffer cache of the given size.
25
 * Constructs a new buffer cache of the given size.
22
 */
26
 */
Lines 44-53 Link Here
44
	if (!((Openable)buffer.getOwner()).canBufferBeRemovedFromCache(buffer)) {
48
	if (!((Openable)buffer.getOwner()).canBufferBeRemovedFromCache(buffer)) {
45
		return false;
49
		return false;
46
	} else {
50
	} else {
47
		buffer.close();
51
		this.buffersToClose.add(buffer);
48
		return true;
52
		return true;
49
	}
53
	}
50
}
54
}
55
56
void closeBuffers() {
57
	ArrayList buffers = this.buffersToClose;
58
	this.buffersToClose = new ArrayList();
59
	for (int i = 0, length = buffers.size(); i < length; i++) {
60
		((IBuffer) buffers.get(i)).close();
61
	}
62
}
51
	/**
63
	/**
52
	 * Returns a new instance of the reciever.
64
	 * Returns a new instance of the reciever.
53
	 */
65
	 */
(-)model/org/eclipse/jdt/internal/core/BufferManager.java (-5 / +19 lines)
Lines 32-38 Link Here
32
	 * LRU cache of buffers. The key and value for an entry
32
	 * LRU cache of buffers. The key and value for an entry
33
	 * in the table is the identical buffer.
33
	 * in the table is the identical buffer.
34
	 */
34
	 */
35
	protected OverflowingLRUCache openBuffers = new BufferCache(60);
35
	private BufferCache openBuffers = new BufferCache(60);
36
	
36
	
37
	/**
37
	/**
38
	 * @deprecated
38
	 * @deprecated
Lines 54-60 Link Here
54
		String owner = ((Openable)buffer.getOwner()).toStringWithAncestors();
54
		String owner = ((Openable)buffer.getOwner()).toStringWithAncestors();
55
		System.out.println("Adding buffer for " + owner); //$NON-NLS-1$
55
		System.out.println("Adding buffer for " + owner); //$NON-NLS-1$
56
	}
56
	}
57
	this.openBuffers.put(buffer.getOwner(), buffer);
57
	synchronized (this.openBuffers) {
58
		this.openBuffers.put(buffer.getOwner(), buffer);	
59
	}
60
	// close buffers that were removed from the cache if space was needed
61
	this.openBuffers.closeBuffers();
58
	if (VERBOSE) {
62
	if (VERBOSE) {
59
		System.out.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
63
		System.out.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
60
	}
64
	}
Lines 74-80 Link Here
74
 * buffer associated with it.
78
 * buffer associated with it.
75
 */
79
 */
76
public IBuffer getBuffer(IOpenable owner) {
80
public IBuffer getBuffer(IOpenable owner) {
77
	return (IBuffer)this.openBuffers.get(owner);
81
	synchronized (this.openBuffers) {
82
		return (IBuffer)this.openBuffers.get(owner);
83
	}
78
}
84
}
79
/**
85
/**
80
 * Returns the default buffer manager.
86
 * Returns the default buffer manager.
Lines 101-110 Link Here
101
 * @return Enumeration of IBuffer
107
 * @return Enumeration of IBuffer
102
 */
108
 */
103
public Enumeration getOpenBuffers() {
109
public Enumeration getOpenBuffers() {
110
	Enumeration result;
104
	synchronized (this.openBuffers) {
111
	synchronized (this.openBuffers) {
105
		this.openBuffers.shrink();
112
		this.openBuffers.shrink();
106
		return this.openBuffers.elements();
113
		result = this.openBuffers.elements();
107
	}
114
	}
115
	// close buffers that were removed from the cache if space was needed
116
	this.openBuffers.closeBuffers();
117
	return result;
108
}
118
}
109
119
110
/**
120
/**
Lines 115-121 Link Here
115
		String owner = ((Openable)buffer.getOwner()).toStringWithAncestors();
125
		String owner = ((Openable)buffer.getOwner()).toStringWithAncestors();
116
		System.out.println("Removing buffer for " + owner); //$NON-NLS-1$
126
		System.out.println("Removing buffer for " + owner); //$NON-NLS-1$
117
	}
127
	}
118
	this.openBuffers.remove(buffer.getOwner());
128
	synchronized (this.openBuffers) {
129
		this.openBuffers.remove(buffer.getOwner());
130
	}
131
	// close buffers that were removed from the cache (should be only one)
132
	this.openBuffers.closeBuffers();	
119
	if (VERBOSE) {
133
	if (VERBOSE) {
120
		System.out.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
134
		System.out.println("-> Buffer cache filling ratio = " + NumberFormat.getInstance().format(this.openBuffers.fillingRatio()) + "%"); //$NON-NLS-1$//$NON-NLS-2$
121
	}
135
	}

Return to bug 175531