Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2007-05-16 16:11:45 +0000
committerCurtis Windatt2007-05-16 16:11:45 +0000
commit3da0781be6b4e291519ae1d8668afa80b199a97c (patch)
tree657ad8c2bb103622b1774127ba5c2f605a74abf0 /org.eclipse.debug.ui
parentdddb6d0064936d6b29c134710d71d3ac14cc5855 (diff)
downloadeclipse.platform.debug-3da0781be6b4e291519ae1d8668afa80b199a97c.tar.gz
eclipse.platform.debug-3da0781be6b4e291519ae1d8668afa80b199a97c.tar.xz
eclipse.platform.debug-3da0781be6b4e291519ae1d8668afa80b199a97c.zip
Bug 173120 - [variables] logical structures re-computed for each visible range
Diffstat (limited to 'org.eclipse.debug.ui')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/VariableContentProvider.java95
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java153
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.java2
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.properties1
4 files changed, 226 insertions, 25 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/VariableContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/VariableContentProvider.java
index 105e0199e..067807e4f 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/VariableContentProvider.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/VariableContentProvider.java
@@ -14,8 +14,10 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILogicalStructureType;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IIndexedValue;
@@ -24,6 +26,7 @@ import org.eclipse.debug.core.model.IVariable;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
import org.eclipse.debug.internal.ui.views.variables.IndexedVariablePartition;
+import org.eclipse.debug.internal.ui.views.variables.LogicalStructureCache;
import org.eclipse.debug.internal.ui.views.variables.VariablesView;
import org.eclipse.debug.ui.IDebugUIConstants;
@@ -32,6 +35,12 @@ import org.eclipse.debug.ui.IDebugUIConstants;
*/
public class VariableContentProvider extends ElementContentProvider {
+ /**
+ * Cache of logical structures to avoid computing structures for different
+ * subranges.
+ */
+ private static LogicalStructureCache fgLogicalCache;
+
/* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext)
*/
@@ -46,6 +55,27 @@ public class VariableContentProvider extends ElementContentProvider {
return getElements(getAllChildren(parent, context), index, length);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
+ */
+ protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
+ return ((IVariable)element).getValue().hasVariables();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#supportsContextId(java.lang.String)
+ */
+ protected boolean supportsContextId(String id) {
+ return id.equals(IDebugUIConstants.ID_EXPRESSION_VIEW) || id.equals(IDebugUIConstants.ID_VARIABLE_VIEW) || id.equals(IDebugUIConstants.ID_REGISTER_VIEW);
+ }
+
+ /**
+ * Gets all the children variables for the parent
+ * @param parent the parent IVariable
+ * @param context the context the children will be presented in
+ * @return an array of all children or an empty array if none
+ * @throws CoreException
+ */
protected Object[] getAllChildren(Object parent, IPresentationContext context) throws CoreException {
IVariable variable = (IVariable) parent;
IValue value = variable.getValue();
@@ -55,13 +85,6 @@ public class VariableContentProvider extends ElementContentProvider {
return EMPTY;
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.internal.ui.viewers.model.provisional.elements.ElementContentProvider#supportsContextId(java.lang.String)
- */
- protected boolean supportsContextId(String id) {
- return id.equals(IDebugUIConstants.ID_EXPRESSION_VIEW) || id.equals(IDebugUIConstants.ID_VARIABLE_VIEW) || id.equals(IDebugUIConstants.ID_REGISTER_VIEW);
- }
-
/**
* Return whether to show compute a logical structure or a raw structure
* in the specified context
@@ -91,9 +114,9 @@ public class VariableContentProvider extends ElementContentProvider {
*
* @param value
* @param context
- * @return
+ * @return logical value for the raw value
*/
- protected IValue getLogicalValue(IValue value, IPresentationContext context) {
+ protected IValue getLogicalValue(IValue value, IPresentationContext context) throws CoreException {
return getLogicalValue(value, new ArrayList(), context);
}
@@ -151,7 +174,7 @@ public class VariableContentProvider extends ElementContentProvider {
*
* @param value
* indexed value
- * @return size of paritions the value should be subdivided into
+ * @return size of partitions the value should be subdivided into
*/
protected int computeParitionSize(IIndexedValue value) {
int partitionSize = 1;
@@ -182,35 +205,57 @@ public class VariableContentProvider extends ElementContentProvider {
* over the returned value until the same structure is encountered again (to
* avoid infinite recursion).
*
- * @param value
+ * @param value raw value to possibly be replaced by a logical value
* @param previousStructureIds
* the list of logical structures that have already been applied
* to the returned value during the recursion of this method.
* Callers should always pass in a new, empty list.
- * @return
+ * @return logical value if one is calculated, otherwise the raw value is returned
*/
- protected IValue getLogicalValue(IValue value, List previousStructureIds, IPresentationContext context) {
+ protected IValue getLogicalValue(IValue value, List previousStructureIds, IPresentationContext context) throws CoreException {
if (isShowLogicalStructure(context)) {
ILogicalStructureType[] types = DebugPlugin.getLogicalStructureTypes(value);
if (types.length > 0) {
ILogicalStructureType type = DebugPlugin.getDefaultStructureType(types);
if (type != null && !previousStructureIds.contains(type.getId())) {
- try {
- value = type.getLogicalStructure(value);
- previousStructureIds.add(type.getId());
- return getLogicalValue(value, previousStructureIds, context);
- } catch (CoreException e) {
- // unable to display logical structure
- }
+ IValue logicalValue = getLogicalStructureCache().getLogicalStructure(type, value);
+ previousStructureIds.add(type.getId());
+ return getLogicalValue(logicalValue, previousStructureIds, context);
}
}
}
return value;
}
-
- protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
- return ((IVariable)element).getValue().hasVariables();
- }
-
+ /**
+ * Returns the logical structure cache to use to store calculated structures. If the cache does not
+ * exist yet, one is created and a debug event listener is added to clear the cache on RESUME and
+ * TERMINATE events.
+ *
+ * @return the logical structure cache to use
+ */
+ protected synchronized LogicalStructureCache getLogicalStructureCache(){
+ if (fgLogicalCache == null){
+ fgLogicalCache = new LogicalStructureCache();
+ // Add a listener to clear the cache when resuming or terminating
+ DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener(){
+ public void handleDebugEvents(DebugEvent[] events) {
+ for (int i = 0; i < events.length; i++) {
+ if (events[i].getKind() == DebugEvent.TERMINATE){
+ fgLogicalCache.clear();
+ break;
+ } else if (events[i].getKind() == DebugEvent.RESUME && !events[i].isEvaluation()){
+ fgLogicalCache.clear();
+ break;
+ } else if (events[i].getKind() == DebugEvent.CHANGE && events[i].getDetail() == DebugEvent.CONTENT){
+ fgLogicalCache.clear();
+ break;
+ }
+ }
+ }
+ });
+ }
+ return fgLogicalCache;
+ }
+
}
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
new file mode 100644
index 000000000..dd72ccc30
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/LogicalStructureCache.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.views.variables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+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.IValue;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+
+/**
+ * Cache that stores evaluated logical structure values to replace raw values. Cache
+ * should be cleared when a RESUME or TERMINATE event is fired so the structure can be
+ * reevaluated for new values.
+ *
+ * @since 3.3
+ *
+ */
+public class LogicalStructureCache {
+
+ /**
+ * Maps a ILogicalStructureType to the cache for that type
+ */
+ private Map fCacheForType = new HashMap();
+
+ /**
+ * Returns the logical value to replace the given value using the specified logical structure.
+ * The value will be retrieved from the cache if possible, or evaluated if not.
+ *
+ * @param type the logical structure type used to evaluate the logical value
+ * @param value the raw value to replace with a logical structure
+ * @return the logical value replacing the raw value or <code>null</code> if there is a problem
+ */
+ public IValue getLogicalStructure(ILogicalStructureType type, IValue value) throws CoreException {
+ synchronized (fCacheForType) {
+ LogicalStructureTypeCache cache = getCacheForType(type);
+ return cache.getLogicalStructure(value);
+ }
+ }
+
+ /**
+ * Clears the cache of all evaluated values.
+ */
+ public void clear(){
+ synchronized (fCacheForType) {
+ fCacheForType.clear();
+ }
+ }
+
+ /**
+ * Helper method that returns the cache associated with the given logical structure type.
+ * If there is not cache associated, one is created.
+ *
+ * @param type the logical structure type to get the cache for
+ * @return the cache associated with the logical structure type
+ */
+ protected LogicalStructureTypeCache getCacheForType(ILogicalStructureType type){
+ LogicalStructureTypeCache cache = (LogicalStructureTypeCache)fCacheForType.get(type);
+ if (cache == null){
+ cache = new LogicalStructureTypeCache(type);
+ fCacheForType.put(type, cache);
+ }
+ return cache;
+ }
+
+ /**
+ * Inner class that caches the known and pending values for a given logical
+ * structure type.
+ */
+ class LogicalStructureTypeCache{
+
+ private ILogicalStructureType fType;
+
+ /**
+ * Maps a raw IValue to its calculated logical IValue
+ */
+ private Map fKnownValues = new HashMap();
+
+ /**
+ * Set of raw IValues that logical values are currently being evaluated for.
+ */
+ private Set fPendingValues = new HashSet();
+
+ public LogicalStructureTypeCache(ILogicalStructureType type){
+ fType = type;
+ }
+
+ /**
+ * Returns the logical structure value for the given raw value. If the value has been evaluated
+ * the cached value is returned, otherwise the thread waits until the value is evaluated.
+ *
+ * @param value the raw value
+ * @return the logical value
+ * @exception CoreException if an error occurs computing the value
+ */
+ public IValue getLogicalStructure(IValue value) throws CoreException {
+ // Check if the value has already been evaluated
+ synchronized (fKnownValues) {
+ IValue logical = (IValue)fKnownValues.get(value);
+ if (logical != null){
+ return logical;
+ }
+ }
+ // Check if the logical structure is currently being evaluated
+ synchronized (fPendingValues) {
+ if (fPendingValues.contains(value)){
+ try {
+ fPendingValues.wait();
+ return getLogicalStructure(value);
+ } catch (InterruptedException e) {
+ throw new CoreException(new Status(IStatus.CANCEL, DebugUIPlugin.getUniqueIdentifier(),
+ VariablesViewMessages.LogicalStructureCache_0, e));
+ }
+ } else {
+ fPendingValues.add(value);
+ }
+ }
+ // Start the evaluation to get the logical structure
+ try {
+ IValue result = fType.getLogicalStructure(value);
+ synchronized (fKnownValues) {
+ fKnownValues.put(value, result);
+ }
+ synchronized (fPendingValues) {
+ fPendingValues.remove(value);
+ fPendingValues.notifyAll();
+ }
+ return result;
+ } catch (CoreException e) {
+ synchronized (fPendingValues) {
+ fPendingValues.remove(value);
+ fPendingValues.notifyAll();
+ }
+ throw e;
+ }
+ }
+
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.java
index 5730b4e32..897e5815b 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.java
@@ -23,6 +23,8 @@ public class VariablesViewMessages extends NLS {
public static String DetailPaneMaxLengthDialog_3;
+ public static String LogicalStructureCache_0;
+
public static String VariablesView__Copy_8;
public static String VariablesView__Paste_14;
public static String VariablesView_Co_ntent_Assist_3;
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.properties
index a33a70a24..1fcf3356d 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.properties
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesViewMessages.properties
@@ -33,3 +33,4 @@ DetailPaneMaxLengthDialog_0=Configure Details Pane
DetailPaneMaxLengthDialog_1=&Maximum characters to display in details pane (0 = unlimited):
DetailPaneMaxLengthDialog_2=Integer must be non-negative
DetailPaneMaxLengthDialog_3=Enter an integer
+LogicalStructureCache_0=Logical structure canceled

Back to the top