summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-18 14:10:02 (EDT)
committerEike Stepper2007-09-18 14:10:02 (EDT)
commitfd9a16dac57842d56863795ea644c27da4464ddc (patch)
tree9208669775fadb16344cff3bb46ed8b85a2dccf3
parentc561762431c67d37c46ca1de7a0788473a1b3c6d (diff)
downloadcdo-fd9a16dac57842d56863795ea644c27da4464ddc.zip
cdo-fd9a16dac57842d56863795ea644c27da4464ddc.tar.gz
cdo-fd9a16dac57842d56863795ea644c27da4464ddc.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.tests/CacheTest.launch2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java54
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java50
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java2
5 files changed, 61 insertions, 49 deletions
diff --git a/plugins/org.eclipse.net4j.tests/CacheTest.launch b/plugins/org.eclipse.net4j.tests/CacheTest.launch
index 63894f3..25a25a0 100644
--- a/plugins/org.eclipse.net4j.tests/CacheTest.launch
+++ b/plugins/org.eclipse.net4j.tests/CacheTest.launch
@@ -17,5 +17,5 @@
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.net4j.util.tests.cache.CacheTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.net4j.tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms10M&#13;&#10;-Xmx100M"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms10M&#13;&#10;-Xmx100M&#13;&#10;-XX:SoftRefLRUPolicyMSPerMB=1000&#13;&#10;-server"/>
</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
index 2d1f72a..53f6676 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java
@@ -41,7 +41,7 @@ public class CacheTest extends AbstractOMTest
for (int id = 1; id <= 100; id++)
{
Revision revision = revisionManager.getRevision(id, version);
- Thread.sleep(20);
+ Thread.sleep(200);
}
System.gc();
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java
index 1dd267e..5abff09 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java
@@ -10,30 +10,31 @@
**************************************************************************/
package org.eclipse.net4j.util.tests.cache;
-import java.lang.ref.PhantomReference;
-import java.lang.ref.ReferenceQueue;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
/**
* @author Eike Stepper
*/
public class Revision
{
+ private RevisionManager revisionManager;
+
private int id;
private int version;
private byte[] data = new byte[100000];
- public Revision(int id, int version)
+ public Revision(RevisionManager revisionManager, int id, int version)
{
+ this.revisionManager = revisionManager;
this.id = id;
this.version = version;
}
+ public RevisionManager getRevisionManager()
+ {
+ return revisionManager;
+ }
+
public int getID()
{
return id;
@@ -55,27 +56,28 @@ public class Revision
return "R" + id + "v" + version;
}
- @SuppressWarnings("unchecked")
- private static Set finalized = new HashSet();
-
- @SuppressWarnings("unchecked")
- private static List refs = new ArrayList();
-
- @SuppressWarnings("unchecked")
- private static ReferenceQueue queue = new ReferenceQueue();
-
+ // @SuppressWarnings("unchecked")
+ // private static Set finalized = new HashSet();
+ //
+ // @SuppressWarnings("unchecked")
+ // private static List refs = new ArrayList();
+ //
+ // @SuppressWarnings("unchecked")
+ // private static ReferenceQueue queue = new ReferenceQueue();
+ //
@Override
protected void finalize() throws Throwable
{
System.err.println("FINALIZE " + this);
- long token = id;
- token <<= 32;
- token |= version;
- if (!finalized.add(token))
- {
- System.err.println("************************************************************************");
- }
-
- refs.add(new PhantomReference<Revision>(this, queue));
+ revisionManager.finalizeRevision(this);
+ // long token = id;
+ // token <<= 32;
+ // token |= version;
+ // if (!finalized.add(token))
+ // {
+ // System.err.println("************************************************************************");
+ // }
+ //
+ // refs.add(new PhantomReference<Revision>(this, queue));
}
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java
index 9b4fa66..3fb6d4a 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java
@@ -14,7 +14,8 @@ import org.eclipse.net4j.internal.util.cache.Cache;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -34,6 +35,16 @@ public class RevisionManager extends Cache<Revision>
public Revision getRevision(int id, int version)
{
+ TimeLine timeLine = getTimeLine(id);
+ return timeLine.getRevision(version);
+ }
+
+ public void evictElements(int elementCount)
+ {
+ }
+
+ protected TimeLine getTimeLine(int id)
+ {
TimeLine timeLine = timeLines.get(id);
if (timeLine == null)
{
@@ -41,24 +52,21 @@ public class RevisionManager extends Cache<Revision>
timeLines.put(id, timeLine);
}
- return timeLine.getRevision(version);
- }
-
- public void evictElements(int elementCount)
- {
+ return timeLine;
}
protected Revision loadRevision(int id, int version)
{
- Revision revision = new Revision(id, version);
- System.out.println("Loaded " + revision + " (free=" + Runtime.getRuntime().freeMemory() + ", total="
- + Runtime.getRuntime().totalMemory() + ", max=" + Runtime.getRuntime().maxMemory() + ")");
+ Revision revision = new Revision(this, id, version);
+ System.out.println(MessageFormat.format("Loaded {0} (free={1}, total={2}, max={3})", revision, Runtime.getRuntime()
+ .freeMemory(), Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory()));
return revision;
}
- protected int getRevisionSize(Revision revision)
+ protected void finalizeRevision(Revision revision)
{
- return 1;
+ // TimeLine timeLine = getTimeLine(revision.getID());
+ // timeLine.addRevision(revision);
}
@Override
@@ -109,25 +117,32 @@ public class RevisionManager extends Cache<Revision>
long time = System.currentTimeMillis();
Revision revision = loadRevision(id, version);
time = System.currentTimeMillis() - time;
- int size = getRevisionSize(revision);
- revisions.add(new CacheElement(revision, getReferenceQueue()));
+ addRevision(revision);
return revision;
}
+
+ public void addRevision(Revision revision)
+ {
+ revisions.add(new CacheElement(revision, getReferenceQueue()));
+ }
}
/**
* @author Eike Stepper
*/
- private static final class CacheElement extends WeakReference<Revision>
+ private static final class CacheElement extends SoftReference<Revision>
{
private int id;
private int version;
+ // private Reference<Revision> ref;
+
public CacheElement(Revision revision, ReferenceQueue<Revision> queue)
{
super(revision, queue);
+ // ref = new WeakReference<Revision>(revision, queue);
id = revision.getID();
version = revision.getVersion();
}
@@ -142,15 +157,10 @@ public class RevisionManager extends Cache<Revision>
return version;
}
- public Revision getRevision()
- {
- return get();
- }
-
@Override
public String toString()
{
- return "Ref" + id + "v" + version + (get() == null ? " cleared" : " set");
+ return "R" + id + "v" + version + (get() == null ? "" : " UNCLEARED");
}
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java
index 055cc66..1b885e1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/cache/CacheMonitor.java
@@ -203,7 +203,7 @@ public class CacheMonitor extends Worker implements ICacheMonitor
protected void handleConditionRED()
{
- System.err.println("\n\n\nCache monitor condition RED\n\n\n\n");
+ System.err.println("CONDITION RED");
}
/**