summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-12-17 03:00:54 (EST)
committerEike Stepper2007-12-17 03:00:54 (EST)
commite7406ce08c8af0940c791ec85a2a6a3b5fe63b23 (patch)
tree1460b26695e0c65dd392934dff090258a09477f3
parent6ada774aba2b0e12a35bdaa7c54f828f4b611446 (diff)
downloadcdo-e7406ce08c8af0940c791ec85a2a6a3b5fe63b23.zip
cdo-e7406ce08c8af0940c791ec85a2a6a3b5fe63b23.tar.gz
cdo-e7406ce08c8af0940c791ec85a2a6a3b5fe63b23.tar.bz2
[209490] Put purging mechanism in CDOViewIMpl::objects to avoid OutOfMemory
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209490
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedPhantomReference.java7
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedSoftReference.java7
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedStrongReference.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedWeakReference.java7
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java20
6 files changed, 48 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 64b3b9d..8699112 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -102,7 +102,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
protected ConcurrentMap<CDOID, InternalCDOObject> createObjectsMap()
{
- return new ReferenceValueMap.Weak<CDOID, InternalCDOObject>();
+ return new ReferenceValueMap.Soft<CDOID, InternalCDOObject>();
}
public int getViewID()
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedPhantomReference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedPhantomReference.java
index d75c8fa..132852f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedPhantomReference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedPhantomReference.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.util.ref;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
+import java.text.MessageFormat;
/**
* @author Eike Stepper
@@ -35,4 +36,10 @@ public class KeyedPhantomReference<K, T> extends PhantomReference<T> implements
{
return key;
}
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("KeyedPhantomReference[{0} -> {1}]", key, isEnqueued() ? "ENQUEUED" : get());
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedSoftReference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedSoftReference.java
index 5552248..9187aed 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedSoftReference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedSoftReference.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.util.ref;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
+import java.text.MessageFormat;
/**
* @author Eike Stepper
@@ -41,4 +42,10 @@ public class KeyedSoftReference<K, T> extends SoftReference<T> implements KeyedR
{
return key;
}
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("KeyedSoftReference[{0} -> {1}]", key, isEnqueued() ? "ENQUEUED" : get());
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedStrongReference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedStrongReference.java
index 33b14d3..3eff9f3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedStrongReference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedStrongReference.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.ref;
+import java.text.MessageFormat;
+
/**
* @author Eike Stepper
*/
@@ -54,4 +56,10 @@ public class KeyedStrongReference<K, T> implements KeyedReference<K, T>
{
return false;
}
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("KeyedStrongReference[{0} -> {1}]", key, ref);
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedWeakReference.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedWeakReference.java
index ce15b20..a27bdc8 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedWeakReference.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/KeyedWeakReference.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.util.ref;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
+import java.text.MessageFormat;
/**
* @author Eike Stepper
@@ -41,4 +42,10 @@ public class KeyedWeakReference<K, T> extends WeakReference<T> implements KeyedR
{
return key;
}
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("KeyedWeakReference[{0} -> {1}]", key, isEnqueued() ? "ENQUEUED" : get());
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java
index ff630db..dc605dd 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java
@@ -52,19 +52,33 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
@Override
public int size()
{
+ purgeQueue();
return map.size();
}
@Override
public boolean isEmpty()
{
+ purgeQueue();
return map.isEmpty();
}
@Override
public boolean containsKey(Object key)
{
- return map.containsKey(key);
+ KeyedReference<K, V> ref = map.get(key);
+ if (ref != null)
+ {
+ if (ref.isEnqueued())
+ {
+ map.remove(key);
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
}
@Override
@@ -77,7 +91,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
for (KeyedReference<K, V> ref : map.values())
{
- if (ObjectUtil.equals(value, dereference(ref)))
+ if (!ref.isEnqueued() && ObjectUtil.equals(value, dereference(ref)))
{
return true;
}
@@ -167,6 +181,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
@Override
public void clear()
{
+ purgeQueue();
map.clear();
}
@@ -175,6 +190,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
{
if (entrySet == null)
{
+ purgeQueue();
entrySet = new EntrySet();
}