From f443167da8031c77dc0bdd0c4942c96f8e07bf54 Mon Sep 17 00:00:00 2001 From: FICTURE7 Date: Tue, 13 Apr 2021 10:41:41 +0400 Subject: [PATCH] Apply suggestions from code review Address gdkchan's feedback Co-authored-by: gdkchan --- ARMeilleure/Common/Counter.cs | 8 +++---- ARMeilleure/Common/EntryTable.cs | 4 ++-- ARMeilleure/Translation/PTC/Ptc.cs | 33 +++++++++++++++++++-------- ARMeilleure/Translation/Translator.cs | 4 +++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ARMeilleure/Common/Counter.cs b/ARMeilleure/Common/Counter.cs index 8fd73f114..4ee4e1288 100644 --- a/ARMeilleure/Common/Counter.cs +++ b/ARMeilleure/Common/Counter.cs @@ -16,7 +16,7 @@ namespace ARMeilleure.Common /// Initializes a new instance of the class from the specified /// instance and index. /// - /// instance + /// instance /// Index in the private Counter(EntryTable countTable, int index) { @@ -41,9 +41,9 @@ namespace ARMeilleure.Common } /// - /// Tries to create a instance from the specified instance. + /// Tries to create a instance from the specified instance. /// - /// from which to create the + /// from which to create the /// instance if success; otherwise /// if success; otherwise /// is @@ -90,4 +90,4 @@ namespace ARMeilleure.Common } } } -} \ No newline at end of file +} diff --git a/ARMeilleure/Common/EntryTable.cs b/ARMeilleure/Common/EntryTable.cs index 00d05c951..7da8dc24f 100644 --- a/ARMeilleure/Common/EntryTable.cs +++ b/ARMeilleure/Common/EntryTable.cs @@ -14,7 +14,7 @@ namespace ARMeilleure.Common private readonly BitMap _allocated; /// - /// Initializes a new instance of the class with the specified capacity. + /// Initializes a new instance of the class with the specified capacity. /// /// Capacity of the table /// is less than 0 @@ -31,7 +31,7 @@ namespace ARMeilleure.Common } /// - /// Tries to allocate an entry in the . Returns if + /// Tries to allocate an entry in the . Returns if /// success; otherwise returns . /// /// Index of entry allocated in the table diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index 613fc6d43..25d9dc583 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs @@ -540,8 +540,11 @@ namespace ARMeilleure.Translation.PTC } } - internal static void LoadTranslations(ConcurrentDictionary funcs, IMemoryManager memory, - JumpTable jumpTable, EntryTable countTable) + internal static void LoadTranslations( + ConcurrentDictionary funcs, + IMemoryManager memory, + JumpTable jumpTable, + EntryTable countTable) { if (AreCarriersEmpty()) { @@ -680,8 +683,13 @@ namespace ARMeilleure.Translation.PTC return relocEntries; } - private static bool PatchCode(Span code, RelocEntry[] relocEntries, IntPtr pageTablePointer, - JumpTable jumpTable, EntryTable countTable, out Counter callCounter) + private static bool PatchCode( + Span code, + RelocEntry[] relocEntries, + IntPtr pageTablePointer, + JumpTable jumpTable, + EntryTable countTable, + out Counter callCounter) { callCounter = null; @@ -747,8 +755,12 @@ namespace ARMeilleure.Translation.PTC return new UnwindInfo(pushEntries, prologueSize); } - private static TranslatedFunction FastTranslate(byte[] code, Counter callCounter, ulong guestSize, - UnwindInfo unwindInfo, bool highCq) + private static TranslatedFunction FastTranslate( + byte[] code, + Counter callCounter, + ulong guestSize, + UnwindInfo unwindInfo, + bool highCq) { CompiledFunction cFunc = new CompiledFunction(code, unwindInfo); @@ -797,8 +809,11 @@ namespace ARMeilleure.Translation.PTC } } - internal static void MakeAndSaveTranslations(ConcurrentDictionary funcs, IMemoryManager memory, - JumpTable jumpTable, EntryTable countTable) + internal static void MakeAndSaveTranslations( + ConcurrentDictionary funcs, + IMemoryManager memory, + JumpTable jumpTable, + EntryTable countTable) { var profiledFuncsToTranslate = PtcProfiler.GetProfiledFuncsToTranslate(funcs); @@ -1085,4 +1100,4 @@ namespace ARMeilleure.Translation.PTC } } } -} \ No newline at end of file +} diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index ac076c583..541aa26a1 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs @@ -22,6 +22,8 @@ namespace ARMeilleure.Translation { public class Translator { + private const int CountTableCapacity = 4 * 1024 * 1024; + private long _nextUpdate; private long _requestAdded; private long _requestRemoved; @@ -61,7 +63,7 @@ namespace ARMeilleure.Translation _backgroundTranslatorEvent = new AutoResetEvent(false); _backgroundTranslatorLock = new ReaderWriterLock(); - CountTable = new EntryTable(capacity: 4 * 1024 * 1024); + CountTable = new EntryTable(CountTableCapacity); JitCache.Initialize(allocator);