mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-23 08:13:50 +02:00
[250328]Adds a map of MemoryCaches so that we have one MemoryCache for each memory context. That way, when dealing with different memory context, we don't mistakenly use the wrong cache.
[245614] Now that we have a memory cache per context, we can clear the memory cache more intelligently, as well as the command cache.
This commit is contained in:
parent
c2468b0c14
commit
43fc7fc53e
1 changed files with 56 additions and 16 deletions
|
@ -13,9 +13,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.mi.service;
|
package org.eclipse.dd.mi.service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IAddress;
|
import org.eclipse.cdt.core.IAddress;
|
||||||
import org.eclipse.cdt.utils.Addr64;
|
import org.eclipse.cdt.utils.Addr64;
|
||||||
|
@ -75,9 +77,18 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
|
|
||||||
// Back-end commands cache
|
// Back-end commands cache
|
||||||
private CommandCache fCommandCache;
|
private CommandCache fCommandCache;
|
||||||
// Local memory cache
|
// Map of memory caches
|
||||||
private MIMemoryCache fMemoryCache;
|
private Map<IMemoryDMContext, MIMemoryCache> fMemoryCaches;
|
||||||
|
|
||||||
|
private MIMemoryCache getMemoryCache(IMemoryDMContext memoryDMC) {
|
||||||
|
MIMemoryCache cache = fMemoryCaches.get(memoryDMC);
|
||||||
|
if (cache == null) {
|
||||||
|
cache = new MIMemoryCache();
|
||||||
|
fMemoryCaches.put(memoryDMC, cache);
|
||||||
|
}
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -123,7 +134,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
register(new String[] { MIMemory.class.getName(), IMemory.class.getName() }, new Hashtable<String, String>());
|
register(new String[] { MIMemory.class.getName(), IMemory.class.getName() }, new Hashtable<String, String>());
|
||||||
|
|
||||||
// Create the memory requests cache
|
// Create the memory requests cache
|
||||||
fMemoryCache = new MIMemoryCache();
|
fMemoryCaches = new HashMap<IMemoryDMContext, MIMemoryCache>();
|
||||||
|
|
||||||
// Register as service event listener
|
// Register as service event listener
|
||||||
getSession().addServiceEventListener(this, null);
|
getSession().addServiceEventListener(this, null);
|
||||||
|
@ -189,7 +200,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
}
|
}
|
||||||
|
|
||||||
// All is clear: go for it
|
// All is clear: go for it
|
||||||
fMemoryCache.getMemory(memoryDMC, address.add(offset), word_size, count, drm);
|
getMemoryCache(memoryDMC).getMemory(memoryDMC, address.add(offset), word_size, count, drm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -228,7 +239,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
}
|
}
|
||||||
|
|
||||||
// All is clear: go for it
|
// All is clear: go for it
|
||||||
fMemoryCache.setMemory(memoryDMC, address, offset, word_size, count, buffer, rm);
|
getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, word_size, count, buffer, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -274,7 +285,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
}
|
}
|
||||||
|
|
||||||
// All is clear: go for it
|
// All is clear: go for it
|
||||||
fMemoryCache.setMemory(memoryDMC, address, offset, word_size, count * length, buffer, rm);
|
getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, word_size, count * length, buffer, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
@ -372,8 +383,17 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.getReason() != StateChangeReason.STEP) {
|
if (e.getReason() != StateChangeReason.STEP) {
|
||||||
fCommandCache.reset();
|
fCommandCache.reset(e.getDMContext());
|
||||||
fMemoryCache.reset();
|
IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(e.getDMContext(), IMemoryDMContext.class);
|
||||||
|
if (fMemoryCaches.containsKey(memoryDMC)) {
|
||||||
|
// We do not want to use the call to getMemoryCache() here.
|
||||||
|
// This is because:
|
||||||
|
// 1- if there is not an entry already , we do not want to automatically
|
||||||
|
// create one, just to call reset() on it.
|
||||||
|
// 2- if memoryDMC == null, we do not want to create a cache
|
||||||
|
// entry for which the key is 'null'
|
||||||
|
fMemoryCaches.get(memoryDMC).reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,8 +406,18 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
if (e instanceof IContainerSuspendedDMEvent) {
|
if (e instanceof IContainerSuspendedDMEvent) {
|
||||||
fCommandCache.setContextAvailable(e.getDMContext(), true);
|
fCommandCache.setContextAvailable(e.getDMContext(), true);
|
||||||
}
|
}
|
||||||
fCommandCache.reset();
|
|
||||||
fMemoryCache.reset();
|
fCommandCache.reset(e.getDMContext());
|
||||||
|
IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(e.getDMContext(), IMemoryDMContext.class);
|
||||||
|
if (fMemoryCaches.containsKey(memoryDMC)) {
|
||||||
|
// We do not want to use the call to getMemoryCache() here.
|
||||||
|
// This is because:
|
||||||
|
// 1- if there is not an entry already , we do not want to automatically
|
||||||
|
// create one, just to call reset() on it.
|
||||||
|
// 2- if memoryDMC == null, we do not want to create a cache
|
||||||
|
// entry for which the key is 'null'
|
||||||
|
fMemoryCaches.get(memoryDMC).reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -418,7 +448,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
address = new Addr64(expAddress.getValue());
|
address = new Addr64(expAddress.getValue());
|
||||||
|
|
||||||
final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class);
|
final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class);
|
||||||
fMemoryCache.refreshMemory(memoryDMC, address, 0, 1, count,
|
getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, 1, count,
|
||||||
new RequestMonitor(getExecutor(), null));
|
new RequestMonitor(getExecutor(), null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -898,9 +928,9 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blocksDiffer) {
|
if (blocksDiffer) {
|
||||||
updateMemoryCache(address, count, newBlock);
|
updateMemoryCache(address, count, newBlock);
|
||||||
getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties());
|
getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties());
|
||||||
}
|
}
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -912,7 +942,17 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public void flushCache(IDMContext context) {
|
public void flushCache(IDMContext context) {
|
||||||
fCommandCache.reset();
|
fCommandCache.reset(context);
|
||||||
fMemoryCache.reset();
|
|
||||||
|
IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class);
|
||||||
|
if (fMemoryCaches.containsKey(memoryDMC)) {
|
||||||
|
// We do not want to use the call to getMemoryCache() here.
|
||||||
|
// This is because:
|
||||||
|
// 1- if there is not an entry already , we do not want to automatically
|
||||||
|
// create one, just to call reset() on it.
|
||||||
|
// 2- if memoryDMC == null, we do not want to create a cache
|
||||||
|
// entry for which the key is 'null'
|
||||||
|
fMemoryCaches.get(memoryDMC).reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue