diff options
author | Christian W. Damus | 2014-04-24 15:56:25 +0000 |
---|---|---|
committer | Christian W. Damus | 2014-04-24 15:56:38 +0000 |
commit | 4aa9a42b72f2739e5a336b32822afb5298be301c (patch) | |
tree | 8ba637954211fa67fc943a74a3cdb5fb141ad577 /tests | |
parent | 84e4fbec33d491362f971ac45d1c9405fdc86154 (diff) | |
download | org.eclipse.papyrus-4aa9a42b72f2739e5a336b32822afb5298be301c.tar.gz org.eclipse.papyrus-4aa9a42b72f2739e5a336b32822afb5298be301c.tar.xz org.eclipse.papyrus-4aa9a42b72f2739e5a336b32822afb5298be301c.zip |
422257: [Performances] Memory leaks
https://bugs.eclipse.org/bugs/show_bug.cgi?id=422257
Attempting a more robust forcing of soft reference clearing (the tests weren't as consistent on Mac as I had thought, either).
Diffstat (limited to 'tests')
2 files changed, 19 insertions, 24 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditorMemoryLeakTest.java b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditorMemoryLeakTest.java index 8617b6f354f..ca561cb00d8 100644 --- a/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditorMemoryLeakTest.java +++ b/tests/junit/plugins/core/org.eclipse.papyrus.editor.integration.tests/src/org/eclipse/papyrus/editor/integration/tests/tests/EditorMemoryLeakTest.java @@ -16,12 +16,9 @@ import static org.junit.Assert.fail; import java.util.Collections; -import org.eclipse.core.runtime.Platform; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.junit.utils.rules.Condition; -import org.eclipse.papyrus.junit.utils.rules.Conditional; import org.eclipse.papyrus.junit.utils.rules.MemoryLeakRule; import org.eclipse.papyrus.junit.utils.rules.MemoryLeakRule.SoftReferenceSensitive; import org.eclipse.ui.IEditorPart; @@ -74,7 +71,6 @@ public class EditorMemoryLeakTest extends AbstractEditorIntegrationTest { */ @Test @SoftReferenceSensitive - @Conditional(key = "isSupportedPlatform") public void testModelExplorerContentDoesNotLeak() { memory.add(getRootUMLModel()); } @@ -94,7 +90,6 @@ public class EditorMemoryLeakTest extends AbstractEditorIntegrationTest { */ @Test @SoftReferenceSensitive - @Conditional(key = "isSupportedPlatform") public void testPropertySheetContentDoesNotLeak() { // Activate the Properties view getView(PROPERTY_SHEET, true); @@ -112,17 +107,6 @@ public class EditorMemoryLeakTest extends AbstractEditorIntegrationTest { // Test framework // - /** - * The memory leak tests all pass consistently on Mac OS X, but the {@link #testPropertySheetContentDoesNotLeak()} test - * fails (at least intermittently) on the Linux build server. - * - * @return whether the current platform is supported by the conditional test - */ - @Condition - public boolean isSupportedPlatform() { - return !Platform.OS_LINUX.equals(Platform.getOS()); - } - @Before public void openEditor() throws Exception { openEditor("simple_class_model"); diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/MemoryLeakRule.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/MemoryLeakRule.java index f64095c2ca2..c9678946e0f 100644 --- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/MemoryLeakRule.java +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/MemoryLeakRule.java @@ -54,6 +54,14 @@ import com.google.common.collect.Lists; */ public class MemoryLeakRule extends TestWatcher { + private static final int DEQUEUE_REF_ITERATIONS = 3; + + private static final int DEQUEUE_REF_TIMEOUT = 1000; // Millis + + private static final int GC_ITERATIONS = 10; + + private static final int CLEAR_SOFT_REFS_ITERATIONS = 3; + private static final Map<Class<?>, Boolean> WARMED_UP_SUITES = new WeakHashMap<Class<?>, Boolean>(); private static boolean warmingUp; @@ -122,8 +130,10 @@ public class MemoryLeakRule extends TestWatcher { while(!tracker.isEmpty()) { Reference<?> ref = dequeueTracker(); - if((ref == null) && isSoftReferenceSensitive) { - // Maybe there are soft references retaining our objects? Desperation move + for(int i = 0; ((ref == null) && isSoftReferenceSensitive) && (i < CLEAR_SOFT_REFS_ITERATIONS); i++) { + // Maybe there are soft references retaining our objects? Desperation move. + // On some platforms, our simulated OOME doesn't actually purge all soft + // references (contrary to Java spec!), so we have to repeat forceClearSoftReferenceCaches(); // Try once more @@ -157,11 +167,11 @@ public class MemoryLeakRule extends TestWatcher { Reference<?> result = null; try { - for(int i = 0; (result == null) && (i < 3); i++) { + for(int i = 0; (result == null) && (i < DEQUEUE_REF_ITERATIONS); i++) { // Try to force GC collectGarbage(); - result = queue.remove(1000); + result = queue.remove(DEQUEUE_REF_TIMEOUT); } } catch (InterruptedException e) { e.printStackTrace(); @@ -198,7 +208,7 @@ public class MemoryLeakRule extends TestWatcher { Long usedMem = rt.totalMemory() - rt.freeMemory(); Long prevUsedMem = usedMem; - for(int i = 0; (prevUsedMem <= usedMem) && (i < 10); i++) { + for(int i = 0; (prevUsedMem <= usedMem) && (i < GC_ITERATIONS); i++) { rt.gc(); Thread.yield(); @@ -216,8 +226,8 @@ public class MemoryLeakRule extends TestWatcher { // This is a really gross HACK and runs the risk that some other thread(s) also may see OOMEs! try { List<Object[]> hog = Lists.newLinkedList(); - for(int size = getLargeMemorySize(); size > 0; size = getLargeMemorySize()) { - hog.add(new Object[size]); + for(;;) { + hog.add(new Object[getLargeMemorySize()]); } } catch (OutOfMemoryError e) { // Good! The JVM guarantees that all soft references are cleared before throwing OOME, @@ -231,7 +241,8 @@ public class MemoryLeakRule extends TestWatcher { } private static int getLargeMemorySize() { - return Math.min(Math.abs((int)Runtime.getRuntime().freeMemory()), Integer.MAX_VALUE); + // These 64 megs are multiplied by the size of a pointer! + return 64 * 1024 * 1024; } private boolean isWarmedUp() { |