diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2020-12-16 17:07:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-16 17:07:42 -0300 |
| commit | 61634dd415fb71b3ae85871a0873d00195b0900c (patch) | |
| tree | 233134f41a93d22d96f78b269047a1a050e87aba /ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs | |
| parent | 11222516c4b5042cd8da6fdd72f53ee736139b66 (diff) | |
Clear JIT cache on exit (#1518)
* Initial cache memory allocator implementation
* Get rid of CallFlag
* Perform cache cleanup on exit
* Basic cache invalidation
* Thats not how conditionals works in C# it seems
* Set PTC version to PR number
* Address PR feedback
* Update InstEmitFlowHelper.cs
* Flag clear on address is no longer needed
* Do not include exit block in function size calculation
* Dispose jump table
* For future use
* InternalVersion = 1519 (force retest).
Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com>
Diffstat (limited to 'ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs')
| -rw-r--r-- | ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs b/ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs new file mode 100644 index 00000000..ae2c075e --- /dev/null +++ b/ARMeilleure/Translation/Cache/JumpTableEntryAllocator.cs @@ -0,0 +1,72 @@ +using ARMeilleure.Common; +using System.Collections.Generic; +using System.Diagnostics; + +namespace ARMeilleure.Translation.Cache +{ + class JumpTableEntryAllocator + { + private readonly BitMap _bitmap; + private int _freeHint; + + public JumpTableEntryAllocator() + { + _bitmap = new BitMap(); + } + + public bool EntryIsValid(int entryIndex) + { + lock (_bitmap) + { + return _bitmap.IsSet(entryIndex); + } + } + + public void SetEntry(int entryIndex) + { + lock (_bitmap) + { + _bitmap.Set(entryIndex); + } + } + + public int AllocateEntry() + { + lock (_bitmap) + { + int entryIndex; + + if (!_bitmap.IsSet(_freeHint)) + { + entryIndex = _freeHint; + } + else + { + entryIndex = _bitmap.FindFirstUnset(); + } + + _freeHint = entryIndex + 1; + + bool wasSet = _bitmap.Set(entryIndex); + Debug.Assert(wasSet); + + return entryIndex; + } + } + + public void FreeEntry(int entryIndex) + { + lock (_bitmap) + { + _bitmap.Clear(entryIndex); + + _freeHint = entryIndex; + } + } + + public IEnumerable<int> GetEntries() + { + return _bitmap; + } + } +} |
