diff options
Diffstat (limited to 'ARMeilleure/Translation/JitCache.cs')
-rw-r--r-- | ARMeilleure/Translation/JitCache.cs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ARMeilleure/Translation/JitCache.cs b/ARMeilleure/Translation/JitCache.cs index 32d40c20..a828b4ed 100644 --- a/ARMeilleure/Translation/JitCache.cs +++ b/ARMeilleure/Translation/JitCache.cs @@ -12,11 +12,12 @@ namespace ARMeilleure.Translation private const int PageSize = 4 * 1024; private const int PageMask = PageSize - 1; - private const int CodeAlignment = 4; // Bytes + private const int CodeAlignment = 4; // Bytes. private const int CacheSize = 2047 * 1024 * 1024; private static ReservedRegion _jitRegion; private static int _offset; + private static readonly List<JitCacheEntry> _cacheEntries = new List<JitCacheEntry>(); private static readonly object _lock = new object(); @@ -25,19 +26,23 @@ namespace ARMeilleure.Translation public static void Initialize(IJitMemoryAllocator allocator) { if (_initialized) return; + lock (_lock) { if (_initialized) return; + _jitRegion = new ReservedRegion(allocator, CacheSize); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - _jitRegion.ExpandIfNeeded(PageSize); + _jitRegion.ExpandIfNeeded((ulong)PageSize); + JitUnwindWindows.InstallFunctionTableHandler(_jitRegion.Pointer, CacheSize); // The first page is used for the table based SEH structs. _offset = PageSize; } + _initialized = true; } } @@ -97,13 +102,13 @@ namespace ARMeilleure.Translation _offset += codeSize; - _jitRegion.ExpandIfNeeded((ulong)_offset); - - if ((ulong)(uint)_offset > CacheSize) + if (_offset > CacheSize) { - throw new OutOfMemoryException(); + throw new OutOfMemoryException("JIT Cache exhausted."); } + _jitRegion.ExpandIfNeeded((ulong)_offset); + return allocOffset; } |