Apply suggestions from code review

Address gdkchan's feedback

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
This commit is contained in:
FICTURE7 2021-04-13 10:41:41 +04:00 committed by FICTURE7
parent 68bff558db
commit f443167da8
4 changed files with 33 additions and 16 deletions

View file

@ -16,7 +16,7 @@ namespace ARMeilleure.Common
/// Initializes a new instance of the <see cref="Counter{T}"/> class from the specified /// Initializes a new instance of the <see cref="Counter{T}"/> class from the specified
/// <see cref="EntryTable{T}"/> instance and index. /// <see cref="EntryTable{T}"/> instance and index.
/// </summary> /// </summary>
/// <param name="countTable"><see cref="EntryTable{byte}"/> instance</param> /// <param name="countTable"><see cref="EntryTable{T}"/> instance</param>
/// <param name="index">Index in the <see cref="EntryTable{T}"/></param> /// <param name="index">Index in the <see cref="EntryTable{T}"/></param>
private Counter(EntryTable<T> countTable, int index) private Counter(EntryTable<T> countTable, int index)
{ {
@ -41,9 +41,9 @@ namespace ARMeilleure.Common
} }
/// <summary> /// <summary>
/// Tries to create a <see cref="Counter"/> instance from the specified <see cref="EntryTable{byte}"/> instance. /// Tries to create a <see cref="Counter"/> instance from the specified <see cref="EntryTable{T}"/> instance.
/// </summary> /// </summary>
/// <param name="countTable"><see cref="EntryTable{TEntry}"/> from which to create the <see cref="Counter"/></param> /// <param name="countTable"><see cref="EntryTable{T}"/> from which to create the <see cref="Counter"/></param>
/// <param name="counter"><see cref="Counter"/> instance if success; otherwise <see langword="null"/></param> /// <param name="counter"><see cref="Counter"/> instance if success; otherwise <see langword="null"/></param>
/// <returns><see langword="true"/> if success; otherwise <see langword="false"/></returns> /// <returns><see langword="true"/> if success; otherwise <see langword="false"/></returns>
/// <exception cref="ArgumentNullException"><paramref name="countTable"/> is <see langword="null"/></exception> /// <exception cref="ArgumentNullException"><paramref name="countTable"/> is <see langword="null"/></exception>

View file

@ -14,7 +14,7 @@ namespace ARMeilleure.Common
private readonly BitMap _allocated; private readonly BitMap _allocated;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="EntryTable{TValue}"/> class with the specified capacity. /// Initializes a new instance of the <see cref="EntryTable{TEntry}"/> class with the specified capacity.
/// </summary> /// </summary>
/// <param name="capacity">Capacity of the table</param> /// <param name="capacity">Capacity of the table</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0</exception>
@ -31,7 +31,7 @@ namespace ARMeilleure.Common
} }
/// <summary> /// <summary>
/// Tries to allocate an entry in the <see cref="EntryTable{TValue}"/>. Returns <see langword="true"/> if /// Tries to allocate an entry in the <see cref="EntryTable{TEntry}"/>. Returns <see langword="true"/> if
/// success; otherwise returns <see langword="false"/>. /// success; otherwise returns <see langword="false"/>.
/// </summary> /// </summary>
/// <param name="index">Index of entry allocated in the table</param> /// <param name="index">Index of entry allocated in the table</param>

View file

@ -540,8 +540,11 @@ namespace ARMeilleure.Translation.PTC
} }
} }
internal static void LoadTranslations(ConcurrentDictionary<ulong, TranslatedFunction> funcs, IMemoryManager memory, internal static void LoadTranslations(
JumpTable jumpTable, EntryTable<uint> countTable) ConcurrentDictionary<ulong, TranslatedFunction> funcs,
IMemoryManager memory,
JumpTable jumpTable,
EntryTable<uint> countTable)
{ {
if (AreCarriersEmpty()) if (AreCarriersEmpty())
{ {
@ -680,8 +683,13 @@ namespace ARMeilleure.Translation.PTC
return relocEntries; return relocEntries;
} }
private static bool PatchCode(Span<byte> code, RelocEntry[] relocEntries, IntPtr pageTablePointer, private static bool PatchCode(
JumpTable jumpTable, EntryTable<uint> countTable, out Counter<uint> callCounter) Span<byte> code,
RelocEntry[] relocEntries,
IntPtr pageTablePointer,
JumpTable jumpTable,
EntryTable<uint> countTable,
out Counter<uint> callCounter)
{ {
callCounter = null; callCounter = null;
@ -747,8 +755,12 @@ namespace ARMeilleure.Translation.PTC
return new UnwindInfo(pushEntries, prologueSize); return new UnwindInfo(pushEntries, prologueSize);
} }
private static TranslatedFunction FastTranslate(byte[] code, Counter<uint> callCounter, ulong guestSize, private static TranslatedFunction FastTranslate(
UnwindInfo unwindInfo, bool highCq) byte[] code,
Counter<uint> callCounter,
ulong guestSize,
UnwindInfo unwindInfo,
bool highCq)
{ {
CompiledFunction cFunc = new CompiledFunction(code, unwindInfo); CompiledFunction cFunc = new CompiledFunction(code, unwindInfo);
@ -797,8 +809,11 @@ namespace ARMeilleure.Translation.PTC
} }
} }
internal static void MakeAndSaveTranslations(ConcurrentDictionary<ulong, TranslatedFunction> funcs, IMemoryManager memory, internal static void MakeAndSaveTranslations(
JumpTable jumpTable, EntryTable<uint> countTable) ConcurrentDictionary<ulong, TranslatedFunction> funcs,
IMemoryManager memory,
JumpTable jumpTable,
EntryTable<uint> countTable)
{ {
var profiledFuncsToTranslate = PtcProfiler.GetProfiledFuncsToTranslate(funcs); var profiledFuncsToTranslate = PtcProfiler.GetProfiledFuncsToTranslate(funcs);

View file

@ -22,6 +22,8 @@ namespace ARMeilleure.Translation
{ {
public class Translator public class Translator
{ {
private const int CountTableCapacity = 4 * 1024 * 1024;
private long _nextUpdate; private long _nextUpdate;
private long _requestAdded; private long _requestAdded;
private long _requestRemoved; private long _requestRemoved;
@ -61,7 +63,7 @@ namespace ARMeilleure.Translation
_backgroundTranslatorEvent = new AutoResetEvent(false); _backgroundTranslatorEvent = new AutoResetEvent(false);
_backgroundTranslatorLock = new ReaderWriterLock(); _backgroundTranslatorLock = new ReaderWriterLock();
CountTable = new EntryTable<uint>(capacity: 4 * 1024 * 1024); CountTable = new EntryTable<uint>(CountTableCapacity);
JitCache.Initialize(allocator); JitCache.Initialize(allocator);