Make EntryTable<T> expandable

* EntryTable is now expandable instead of being a fixed slab.
* Remove EntryTable<T>.TryAllocate
* Remove Counter<T>.TryCreate

Address LDj3SNuD's feedback
This commit is contained in:
FICTURE7 2021-04-16 18:20:05 +04:00
parent 5b4543e62c
commit 9c0dbb9c07
4 changed files with 155 additions and 95 deletions

View file

@ -579,12 +579,7 @@ namespace ARMeilleure.Translation.PTC
{
RelocEntry[] relocEntries = GetRelocEntries(relocsReader, infoEntry.RelocEntriesCount);
if (!PatchCode(code, relocEntries, memory.PageTablePointer, jumpTable, countTable, out callCounter))
{
SkipUnwindInfo(unwindInfosReader);
continue;
}
PatchCode(code, relocEntries, memory.PageTablePointer, jumpTable, countTable, out callCounter);
}
UnwindInfo unwindInfo = ReadUnwindInfo(unwindInfosReader);
@ -683,7 +678,7 @@ namespace ARMeilleure.Translation.PTC
return relocEntries;
}
private static bool PatchCode(
private static void PatchCode(
Span<byte> code,
RelocEntry[] relocEntries,
IntPtr pageTablePointer,
@ -711,13 +706,9 @@ namespace ARMeilleure.Translation.PTC
}
else if (relocEntry.Index == CountTableIndex)
{
// If we could not allocate an entry on the count table we dip.
if (!Counter<uint>.TryCreate(countTable, out Counter<uint> counter))
{
return false;
}
callCounter = new Counter<uint>(countTable);
unsafe { imm = (ulong)Unsafe.AsPointer(ref counter.Value); }
unsafe { imm = (ulong)Unsafe.AsPointer(ref callCounter.Value); }
}
else if (Delegates.TryGetDelegateFuncPtrByIndex(relocEntry.Index, out IntPtr funcPtr))
{
@ -730,8 +721,6 @@ namespace ARMeilleure.Translation.PTC
BinaryPrimitives.WriteUInt64LittleEndian(code.Slice(relocEntry.Position, 8), imm);
}
return true;
}
private static UnwindInfo ReadUnwindInfo(BinaryReader unwindInfosReader)