summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-17 16:25:16 (EDT)
committerEike Stepper2007-09-17 16:25:16 (EDT)
commitb901260d71163803dc498a0f2fa23bbbd677c632 (patch)
tree4e5cbff47a30dc40eba0449a1df489c30d19d053
parent3880207b81db9ca5397e8236f8f90c4bd5a8c42f (diff)
downloadcdo-b901260d71163803dc498a0f2fa23bbbd677c632.zip
cdo-b901260d71163803dc498a0f2fa23bbbd677c632.tar.gz
cdo-b901260d71163803dc498a0f2fa23bbbd677c632.tar.bz2
[203538] Limit memory consumption in CDORevisionResolverImpl
https://bugs.eclipse.org/bugs/show_bug.cgi?id=203538
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java67
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICache.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheProbe.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheRegistration.java12
4 files changed, 86 insertions, 6 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java
index 50b160b..7c7fb7f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheRegistration.java
@@ -19,10 +19,18 @@ import org.eclipse.net4j.util.cache.ICacheRegistration;
*/
public class CacheRegistration implements ICacheRegistration
{
+ public static final float DEFAULT_RECONSTRUCTION_COST_DECAY_FACTOR = 0.1f;
+
private ICacheMonitor cacheMonitor;
private ICache cache;
+ private int elementCount;
+
+ private long cacheSize;
+
+ private long reconstructionCost;
+
public CacheRegistration(ICacheMonitor cacheMonitor, ICache cache)
{
this.cacheMonitor = cacheMonitor;
@@ -35,6 +43,11 @@ public class CacheRegistration implements ICacheRegistration
cache = null;
}
+ public boolean isDisposed()
+ {
+ return cacheMonitor == null || cache == null;
+ }
+
public ICacheMonitor getCacheMonitor()
{
return cacheMonitor;
@@ -44,4 +57,58 @@ public class CacheRegistration implements ICacheRegistration
{
return cache;
}
+
+ public int getElementCount()
+ {
+ return elementCount;
+ }
+
+ public long getCacheSize()
+ {
+ return cacheSize;
+ }
+
+ public long getAverageElementSize()
+ {
+ return cacheSize / elementCount;
+ }
+
+ public long getReconstructionCost()
+ {
+ return reconstructionCost;
+ }
+
+ public void elementCached(int elementSize)
+ {
+ checkDisposal();
+ ++elementCount;
+ cacheSize += elementSize;
+ }
+
+ public void elementEvicted(int elementSize)
+ {
+ checkDisposal();
+ --elementCount;
+ cacheSize -= elementSize;
+ }
+
+ public void elementReconstructed(long reconstructionTime)
+ {
+ checkDisposal();
+ float decayFactor = getReconstructionCostDecayFactor();
+ this.reconstructionCost = (long)(decayFactor * this.reconstructionCost + (1 - decayFactor) * reconstructionTime);
+ }
+
+ protected float getReconstructionCostDecayFactor()
+ {
+ return DEFAULT_RECONSTRUCTION_COST_DECAY_FACTOR;
+ }
+
+ private void checkDisposal()
+ {
+ if (isDisposed())
+ {
+ throw new IllegalStateException("disposed");
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICache.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICache.java
index b3593ab..8dec506 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICache.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICache.java
@@ -15,9 +15,6 @@ package org.eclipse.net4j.util.cache;
*/
public interface ICache
{
- public static final int UNKNOWN_ELEMENT_SIZE = -1;
-
- public static final long UNKNOWN_RECONSTRUCTION_TIME = -1L;
public ICacheMonitor getCacheMonitor();
@@ -42,5 +39,5 @@ public interface ICache
/**
* Instructs this cache to evict <b>elementCount</b> elements and return the number of actually evicted elements.
*/
- public int evictElements(int elementCount);
+ public void evictElements(int elementCount);
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheProbe.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheProbe.java
index 835c6ce..66805fa 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheProbe.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheProbe.java
@@ -15,7 +15,11 @@ package org.eclipse.net4j.util.cache;
*/
public interface ICacheProbe
{
- public ICacheMonitor getCacheMonitor();
+ public boolean isDisposed();
- public ICache getCache();
+ public void elementCached(int elementSize);
+
+ public void elementEvicted(int elementSize);
+
+ public void elementReconstructed(long reconstructionTime);
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheRegistration.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheRegistration.java
index 2629c29..ac48580 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheRegistration.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/cache/ICacheRegistration.java
@@ -15,5 +15,17 @@ package org.eclipse.net4j.util.cache;
*/
public interface ICacheRegistration extends ICacheProbe
{
+ public ICacheMonitor getCacheMonitor();
+
+ public ICache getCache();
+
public void dispose();
+
+ public int getElementCount();
+
+ public long getCacheSize();
+
+ public long getAverageElementSize();
+
+ public long getReconstructionCost();
}