summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-12-18 10:06:38 (EST)
committerEike Stepper2007-12-18 10:06:38 (EST)
commit2af988b3fea51871dbbe17e6c3fa1d692cfcbd4e (patch)
tree3dc5b1f7c727e359ba3eaa092cee6777086f1134
parent23cfd7ec7edee9159b40fe593d0e3abb2c90359b (diff)
downloadcdo-2af988b3fea51871dbbe17e6c3fa1d692cfcbd4e.zip
cdo-2af988b3fea51871dbbe17e6c3fa1d692cfcbd4e.tar.gz
cdo-2af988b3fea51871dbbe17e6c3fa1d692cfcbd4e.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.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java43
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceValueMap.java15
3 files changed, 50 insertions, 10 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index e082b34..2d8814e 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.tests;
import org.eclipse.net4j.util.tests.MonitorTest;
+import org.eclipse.net4j.util.tests.ReferenceValueMapTest;
import org.eclipse.net4j.util.tests.SortedFileMapTest;
import org.eclipse.net4j.util.tests.SynchronizingCorrelatorTest;
@@ -30,6 +31,7 @@ public class AllTests
suite.addTestSuite(MonitorTest.class);
suite.addTestSuite(SortedFileMapTest.class);
suite.addTestSuite(SynchronizingCorrelatorTest.class);
+ suite.addTestSuite(ReferenceValueMapTest.class);
suite.addTestSuite(BufferPoolTest.class);
// suite.addTestSuite(SecurityTest.class);
// TODO suite.addTestSuite(ConnectorTest.class);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java
new file mode 100644
index 0000000..c8de516
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.ref.ReferenceValueMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class ReferenceValueMapTest extends AbstractOMTest
+{
+ public void testSameKey() throws Exception
+ {
+ ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
+ for (int i = 0; i < 10; i++)
+ {
+ map.put("SIMON", new Object());
+ System.gc();
+ map.put("SIMON", new Object());
+ assertEquals(1, map.size());
+ }
+ }
+
+ public void testDifferentKey() throws Exception
+ {
+ ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
+ for (int i = 0; i < 10; i++)
+ {
+ map.put("SIMON", new Object());
+ System.gc();
+ map.put("SIMON2", new Object());
+ assertEquals(1, map.size());
+ }
+ }
+}
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 d9fd2ed..fa5f160 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
@@ -81,7 +81,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
{
if (ref.get() == null)
{
- ref.enqueue();
+ // ref.enqueue();
return false;
}
@@ -104,7 +104,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
V v = ref.get();
if (v == null)
{
- ref.enqueue();
+ // ref.enqueue();
return false;
}
@@ -226,7 +226,8 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
KeyedReference<K, V> ref;
while ((ref = (KeyedReference<K, V>)queue.poll()) != null)
{
- map.remove(ref.getKey());
+ // Slightly faster than map.get() + map.remove()
+ map.remove(ref.getKey(), ref);
}
}
}
@@ -238,13 +239,7 @@ public abstract class ReferenceValueMap<K, V> extends AbstractMap<K, V> implemen
return null;
}
- V value = ref.get();
- if (value == null)
- {
- ref.enqueue();
- }
-
- return value;
+ return ref.get();
}
protected abstract KeyedReference<K, V> createReference(K key, V value, ReferenceQueue<V> queue);