From 28f43f562254fd254c910c3049ca260356657fee Mon Sep 17 00:00:00 2001 From: FICTURE7 Date: Wed, 14 Apr 2021 11:56:10 +0400 Subject: [PATCH] Dispose Counters before they hit the finalizer queue --- ARMeilleure/Translation/Translator.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index ad059e715..a8635c545 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs @@ -28,7 +28,7 @@ namespace ARMeilleure.Translation private readonly IMemoryManager _memory; private readonly ConcurrentDictionary _funcs; - private readonly ConcurrentQueue> _oldFuncs; + private readonly ConcurrentQueue> _oldFuncs; private readonly ConcurrentDictionary _backgroundSet; private readonly ConcurrentStack _backgroundStack; @@ -50,7 +50,7 @@ namespace ARMeilleure.Translation _memory = memory; _funcs = new ConcurrentDictionary(); - _oldFuncs = new ConcurrentQueue>(); + _oldFuncs = new ConcurrentQueue>(); _backgroundSet = new ConcurrentDictionary(); _backgroundStack = new ConcurrentStack(); @@ -457,7 +457,7 @@ namespace ARMeilleure.Translation private void EnqueueForDeletion(ulong guestAddress, TranslatedFunction func) { - _oldFuncs.Enqueue(new KeyValuePair(guestAddress, func.FuncPtr)); + _oldFuncs.Enqueue(new(guestAddress, func)); } private void ClearJitCache() @@ -465,16 +465,20 @@ namespace ARMeilleure.Translation // Ensure no attempt will be made to compile new functions due to rejit. ClearRejitQueue(allowRequeue: false); - foreach (var kv in _funcs) + foreach (var func in _funcs.Values) { - JitCache.Unmap(kv.Value.FuncPtr); + JitCache.Unmap(func.FuncPtr); + + func.CallCounter?.Dispose(); } _funcs.Clear(); while (_oldFuncs.TryDequeue(out var kv)) { - JitCache.Unmap(kv.Value); + JitCache.Unmap(kv.Value.FuncPtr); + + kv.Value.CallCounter?.Dispose(); } }