use dictionary for jit cache, cleanup old functions in single passes
This commit is contained in:
parent
68cee9db6d
commit
3b68e7b459
2 changed files with 22 additions and 24 deletions
|
@ -19,7 +19,7 @@ namespace ARMeilleure.Translation
|
|||
|
||||
private static JitCacheMemoryAllocator _allocator;
|
||||
|
||||
private static List<JitCacheEntry> _cacheEntries;
|
||||
private static Dictionary<int, JitCacheEntry> _cacheEntries;
|
||||
|
||||
private static object _lock;
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace ARMeilleure.Translation
|
|||
|
||||
_allocator = new JitCacheMemoryAllocator(CacheSize, startOffset);
|
||||
|
||||
_cacheEntries = new List<JitCacheEntry>();
|
||||
_cacheEntries = new Dictionary<int, JitCacheEntry>();
|
||||
|
||||
_lock = new object();
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace ARMeilleure.Translation
|
|||
{
|
||||
if (TryFind((int)offset, out JitCacheEntry entry))
|
||||
{
|
||||
_cacheEntries.Remove(entry);
|
||||
_cacheEntries.Remove((int)offset, out entry);
|
||||
|
||||
int size = checked(entry.Size + (CodeAlignment - 1)) & ~(CodeAlignment - 1);
|
||||
|
||||
|
@ -112,23 +112,16 @@ namespace ARMeilleure.Translation
|
|||
|
||||
private static void Add(JitCacheEntry entry)
|
||||
{
|
||||
_cacheEntries.Add(entry);
|
||||
_cacheEntries.Add(entry.Offset, entry);
|
||||
}
|
||||
|
||||
public static bool TryFind(int offset, out JitCacheEntry entry)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (JitCacheEntry cacheEntry in _cacheEntries)
|
||||
if(_cacheEntries.TryGetValue(offset, out entry))
|
||||
{
|
||||
int endOffset = cacheEntry.Offset + cacheEntry.Size;
|
||||
|
||||
if (offset >= cacheEntry.Offset && offset < endOffset)
|
||||
{
|
||||
entry = cacheEntry;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,19 +57,24 @@ namespace ARMeilleure.Translation
|
|||
return func;
|
||||
});
|
||||
}
|
||||
else if (_oldFunctions.TryDequeue(out TranslatedFunction function))
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref function.EntryCount, -1, 0) != 0)
|
||||
{
|
||||
_oldFunctions.Enqueue(function);
|
||||
}
|
||||
else
|
||||
{
|
||||
JitCache.Free(function.Pointer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Queue<TranslatedFunction> skippedFunctions = new Queue<TranslatedFunction>();
|
||||
|
||||
while (_oldFunctions.TryDequeue(out TranslatedFunction function))
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref function.EntryCount, -1, 0) != 0)
|
||||
{
|
||||
skippedFunctions.Enqueue(function);
|
||||
}
|
||||
else
|
||||
{
|
||||
JitCache.Free(function.Pointer);
|
||||
}
|
||||
}
|
||||
|
||||
_oldFunctions = skippedFunctions;
|
||||
|
||||
_backgroundTranslatorEvent.WaitOne();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue