diff options
author | Julian Honnen | 2020-10-20 15:22:13 +0000 |
---|---|---|
committer | Julian Honnen | 2020-10-22 06:06:04 +0000 |
commit | 5b5b4b786f679ba15f8bffbbde3fb6dea1e01bfc (patch) | |
tree | a825c5160b34bbc833365768f3178e8e05e9ba88 | |
parent | 49a5770c15f2cef2d0f10cfc9359312e9f38186b (diff) | |
download | eclipse.platform.debug-I20201023-0250.tar.gz eclipse.platform.debug-I20201023-0250.tar.xz eclipse.platform.debug-I20201023-0250.zip |
Bug 568042 - provide ILogicalStructureTypeDelegate3#releaseValue APIY20201025-1200Y20201024-1200Y20201023-1200I20201026-0840I20201026-0650I20201025-1800I20201025-0040I20201024-1800I20201023-1800I20201023-0250
Provide an API to allow logical structure type delegates to garbage
collect their logical structures once they're no longer displayed.
Change-Id: I25e78c4d5fb84d54d6e47a6b0f12998b6b8b4f37
Signed-off-by: Julian Honnen <julian.honnen@vector.com>
10 files changed, 234 insertions, 4 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILogicalStructureTypeDelegate3.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILogicalStructureTypeDelegate3.java new file mode 100644 index 000000000..8ba0d52e6 --- /dev/null +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/model/ILogicalStructureTypeDelegate3.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2020 Julian Honnen + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Julian Honnen <julian.honnen@vector.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.core.model; + +/** + * Optional extension to <code>ILogicalStructureTypeDelegate</code> that allows + * a logical structure type delegate to garbage collect its logical structures + * once they're no longer displayed. + * + * @since 3.17 + * @see ILogicalStructureTypeDelegate + */ +public interface ILogicalStructureTypeDelegate3 { + + /** + * Called when the logical structure returned from + * {@link ILogicalStructureTypeDelegate#getLogicalStructure(IValue)} is no + * longer used and can be discarded. + * + * @param logicalStructure the logical structure value to discard + */ + void releaseValue(IValue logicalStructure); + +} diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LogicalStructureType.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LogicalStructureType.java index 7fc9d1739..074fc67d7 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LogicalStructureType.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LogicalStructureType.java @@ -23,6 +23,7 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILogicalStructureType; import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate; import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate2; +import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate3; import org.eclipse.debug.core.model.IValue; /** @@ -30,7 +31,7 @@ import org.eclipse.debug.core.model.IValue; * * @see IConfigurationElementConstants */ -public class LogicalStructureType implements ILogicalStructureType { +public class LogicalStructureType implements ILogicalStructureType, ILogicalStructureTypeDelegate3 { private IConfigurationElement fConfigurationElement; private ILogicalStructureTypeDelegate fDelegate; @@ -108,6 +109,14 @@ public class LogicalStructureType implements ILogicalStructureType { return false; } + @Override + public void releaseValue(IValue logicalStructure) { + ILogicalStructureTypeDelegate delegate = getDelegate(); + if (delegate instanceof ILogicalStructureTypeDelegate3) { + ((ILogicalStructureTypeDelegate3) delegate).releaseValue(logicalStructure); + } + } + /** * Returns the <code>ILogicalStructuresTypeDelegate</code> delegate * @return the delegate diff --git a/org.eclipse.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.debug.tests/META-INF/MANIFEST.MF index b580480a2..6e3069839 100644 --- a/org.eclipse.debug.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.tests/META-INF/MANIFEST.MF @@ -24,6 +24,7 @@ Export-Package: org.eclipse.debug.tests, org.eclipse.debug.tests.console, org.eclipse.debug.tests.expressions, org.eclipse.debug.tests.launching, + org.eclipse.debug.tests.logicalstructure, org.eclipse.debug.tests.sourcelookup, org.eclipse.debug.tests.statushandlers, org.eclipse.debug.tests.stepfilters, diff --git a/org.eclipse.debug.tests/plugin.xml b/org.eclipse.debug.tests/plugin.xml index ab1d612ec..a350e91c8 100644 --- a/org.eclipse.debug.tests/plugin.xml +++ b/org.eclipse.debug.tests/plugin.xml @@ -134,4 +134,12 @@ id="org.eclipse.debug.tests"> </debugModelPresentation> </extension> + <extension + point="org.eclipse.debug.core.logicalStructureTypes"> + <logicalStructureType + class="org.eclipse.debug.tests.logicalstructure.TestLogicalStructureTypeDelegate" + id="org.eclipse.debug.tests.logicalStructureType1" + modelIdentifier="org.eclipse.debug.tests"> + </logicalStructureType> + </extension> </plugin> diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java index 825625830..b28236add 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java @@ -39,6 +39,7 @@ import org.eclipse.debug.tests.launching.LaunchHistoryTests; import org.eclipse.debug.tests.launching.LaunchManagerTests; import org.eclipse.debug.tests.launching.LaunchTests; import org.eclipse.debug.tests.launching.RefreshTabTests; +import org.eclipse.debug.tests.logicalstructure.LogicalStructureCacheTest; import org.eclipse.debug.tests.sourcelookup.SourceLookupFacilityTests; import org.eclipse.debug.tests.statushandlers.StatusHandlerTests; import org.eclipse.debug.tests.stepfilters.StepFiltersTests; @@ -85,7 +86,7 @@ import org.junit.runners.Suite; FilterTransformTests.class, ChildrenUpdateTests.class, PresentationContextTests.class, - + // Memory view MemoryRenderingTests.class, @@ -122,6 +123,9 @@ import org.junit.runners.Suite; // Launch Groups LaunchGroupTests.class, + + // Logical structure + LogicalStructureCacheTest.class, }) public class AutomatedSuite { } diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/LogicalStructureCacheTest.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/LogicalStructureCacheTest.java new file mode 100644 index 000000000..ed58260c8 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/LogicalStructureCacheTest.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2020 Julian Honnen + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Julian Honnen <julian.honnen@vector.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.logicalstructure; + +import static org.junit.Assert.*; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILogicalStructureType; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.internal.ui.views.variables.LogicalStructureCache; +import org.eclipse.debug.tests.AbstractDebugTest; +import org.junit.Test; + +public class LogicalStructureCacheTest extends AbstractDebugTest { + + @Test + public void testReleaseValuesOnClear() throws Exception { + TestValue rawValue = new TestValue("raw"); + ILogicalStructureType[] logicalStructureTypes = DebugPlugin.getLogicalStructureTypes(rawValue); + + LogicalStructureCache cache = new LogicalStructureCache(); + IValue logicalStructure = cache.getLogicalStructure(logicalStructureTypes[0], rawValue); + + assertTrue(logicalStructure.isAllocated()); + + cache.clear(); + + assertFalse(logicalStructure.isAllocated()); + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestLogicalStructureTypeDelegate.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestLogicalStructureTypeDelegate.java new file mode 100644 index 000000000..13576c139 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestLogicalStructureTypeDelegate.java @@ -0,0 +1,29 @@ +package org.eclipse.debug.tests.logicalstructure; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate; +import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate3; +import org.eclipse.debug.core.model.IValue; + +public class TestLogicalStructureTypeDelegate implements ILogicalStructureTypeDelegate, ILogicalStructureTypeDelegate3 { + + @Override + public boolean providesLogicalStructure(IValue value) { + if (value instanceof TestValue) { + TestValue testValue = (TestValue) value; + return "raw".equals(testValue.getValueString()); + } + return false; + } + + @Override + public IValue getLogicalStructure(IValue value) throws CoreException { + return new TestValue("logical structure"); + } + + @Override + public void releaseValue(IValue logicalStructure) { + ((TestValue) logicalStructure).release(); + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestValue.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestValue.java new file mode 100644 index 000000000..742f34853 --- /dev/null +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/logicalstructure/TestValue.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2020 Julian Honnen + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Julian Honnen <julian.honnen@vector.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.tests.logicalstructure; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IVariable; +import org.eclipse.debug.tests.TestsPlugin; + +class TestValue implements IValue { + + private final String value; + + private boolean allocated = true; + + public TestValue(String value) { + this.value = value; + } + + @Override + public String getModelIdentifier() { + return TestsPlugin.PLUGIN_ID; + } + + @Override + public IDebugTarget getDebugTarget() { + return null; + } + + @Override + public ILaunch getLaunch() { + return null; + } + + @Override + public <T> T getAdapter(Class<T> adapter) { + return null; + } + + @Override + public String getReferenceTypeName() throws DebugException { + return null; + } + + @Override + public String getValueString() { + return value; + } + + @Override + public boolean isAllocated() { + return allocated; + } + + @Override + public IVariable[] getVariables() throws DebugException { + return new IVariable[0]; + } + + @Override + public boolean hasVariables() throws DebugException { + return false; + } + + public void release() { + allocated = false; + } + + @Override + public String toString() { + return getValueString(); + } +} diff --git a/org.eclipse.debug.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.ui/META-INF/MANIFEST.MF index 8b9329f50..039f99a7c 100644 --- a/org.eclipse.debug.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.ui/META-INF/MANIFEST.MF @@ -40,7 +40,7 @@ Export-Package: org.eclipse.debug.internal.ui; org.eclipse.debug.internal.ui.model.elements;x-friends:="org.eclipse.debug.examples.ui,org.eclipse.jdt.debug.ui,org.eclipse.wst.jsdt.debug.ui", org.eclipse.debug.internal.ui.preferences;x-internal:=true, org.eclipse.debug.internal.ui.quickaccess;x-internal:=true, - org.eclipse.debug.internal.ui.sourcelookup;x-friends:="org.eclipse.debug.tests, org.eclipse.jdt.debug.ui", + org.eclipse.debug.internal.ui.sourcelookup;x-friends:="org.eclipse.debug.tests,org.eclipse.jdt.debug.ui", org.eclipse.debug.internal.ui.sourcelookup.browsers;x-internal:=true, org.eclipse.debug.internal.ui.stringsubstitution;x-friends:="org.eclipse.jdt.debug.ui", org.eclipse.debug.internal.ui.viewers;x-friends:="org.eclipse.debug.examples.ui", @@ -68,7 +68,7 @@ Export-Package: org.eclipse.debug.internal.ui; org.eclipse.debug.internal.ui.views.memory.renderings;x-internal:=true, org.eclipse.debug.internal.ui.views.modules;x-internal:=true, org.eclipse.debug.internal.ui.views.registers;x-internal:=true, - org.eclipse.debug.internal.ui.views.variables;x-friends:="org.eclipse.jdt.debug.ui,org.eclipse.debug.examples.ui", + org.eclipse.debug.internal.ui.views.variables;x-friends:="org.eclipse.jdt.debug.ui,org.eclipse.debug.examples.ui,org.eclipse.debug.tests", org.eclipse.debug.internal.ui.views.variables.details;x-friends:="org.eclipse.jdt.debug.ui,org.eclipse.wst.jsdt.debug.ui", org.eclipse.debug.ui, org.eclipse.debug.ui.actions, diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java index 2389c3aac..bd4ccc368 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.views.variables; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -22,6 +24,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILogicalStructureType; +import org.eclipse.debug.core.model.ILogicalStructureTypeDelegate3; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.internal.ui.DebugUIPlugin; @@ -59,9 +62,13 @@ public class LogicalStructureCache { * Clears the cache of all evaluated values. */ public void clear(){ + Collection<LogicalStructureTypeCache> caches; synchronized (fCacheForType) { + caches = new ArrayList<>(fCacheForType.values()); fCacheForType.clear(); } + + caches.forEach(LogicalStructureTypeCache::dispose); } /** @@ -147,5 +154,15 @@ public class LogicalStructureCache { } } + public void dispose() { + if (!(fType instanceof ILogicalStructureTypeDelegate3)) { + return; + } + ILogicalStructureTypeDelegate3 typeDelegate = (ILogicalStructureTypeDelegate3) fType; + synchronized (fKnownValues) { + fKnownValues.values().forEach(typeDelegate::releaseValue); + } + } + } } |