Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Reflect PR feedback
  • Loading branch information
janvorli committed Aug 25, 2023
commit 6f699e916601bd720b686beafd7f2ef2d59dfa1f
20 changes: 10 additions & 10 deletions src/BenchmarkDotNet/Disassemblers/Arm64Disassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,28 @@ internal sealed class RuntimeSpecificData
// ldr x9, DATA_SLOT(CallCountingStub, RemainingCallCountCell)
// ldrh w10, [x9]
// subs w10, w10, #0x1
internal byte[] callCountingStubTemplate = new byte[12] { 0x09, 0x00, 0x00, 0x58, 0x2a, 0x01, 0x40, 0x79, 0x4a, 0x05, 0x00, 0x71 };
internal readonly byte[] callCountingStubTemplate = new byte[12] { 0x09, 0x00, 0x00, 0x58, 0x2a, 0x01, 0x40, 0x79, 0x4a, 0x05, 0x00, 0x71 };
// ldr x10, DATA_SLOT(StubPrecode, Target)
// ldr x12, DATA_SLOT(StubPrecode, MethodDesc)
// br x10
internal byte[] stubPrecodeTemplate = new byte[12] { 0x4a, 0x00, 0x00, 0x58, 0xec, 0x00, 0x00, 0x58, 0x40, 0x01, 0x1f, 0xd6 };
internal readonly byte[] stubPrecodeTemplate = new byte[12] { 0x4a, 0x00, 0x00, 0x58, 0xec, 0x00, 0x00, 0x58, 0x40, 0x01, 0x1f, 0xd6 };
// ldr x11, DATA_SLOT(FixupPrecode, Target)
// br x11
// ldr x12, DATA_SLOT(FixupPrecode, MethodDesc)
internal byte[] fixupPrecodeTemplate = new byte[12] { 0x0b, 0x00, 0x00, 0x58, 0x60, 0x01, 0x1f, 0xd6, 0x0c, 0x00, 0x00, 0x58 };
internal int stubPageSize;
internal readonly byte[] fixupPrecodeTemplate = new byte[12] { 0x0b, 0x00, 0x00, 0x58, 0x60, 0x01, 0x1f, 0xd6, 0x0c, 0x00, 0x00, 0x58 };
internal readonly ulong stubPageSize;

internal RuntimeSpecificData(State state)
{
stubPageSize = Environment.SystemPageSize;
stubPageSize = (ulong)Environment.SystemPageSize;
if (state.RuntimeVersion.Major >= 8)
{
// In .NET 8, the stub page size was changed to min 16kB
stubPageSize = Math.Max(Environment.SystemPageSize, 16384);
stubPageSize = Math.Max(stubPageSize, 16384);
}

// The stubs code depends on the current OS memory page size, so we need to update the templates to reflect that
int pageSizeShifted = stubPageSize / 32;
ulong pageSizeShifted = stubPageSize / 32;
// Calculate the ldr x9, #offset instruction with offset based on the page size
callCountingStubTemplate[1] = (byte)(pageSizeShifted & 0xff);
callCountingStubTemplate[2] = (byte)(pageSizeShifted >> 8);
Expand Down Expand Up @@ -231,18 +231,18 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
if (buffer.SequenceEqual(data.callCountingStubTemplate))
{
const ulong TargetMethodAddressSlotOffset = 8;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + TargetMethodAddressSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + TargetMethodAddressSlotOffset);
}
else if (buffer.SequenceEqual(data.stubPrecodeTemplate))
{
const ulong MethodDescSlotOffset = 0;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + MethodDescSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + MethodDescSlotOffset);
isPrestubMD = true;
}
else if (buffer.SequenceEqual(data.fixupPrecodeTemplate))
{
const ulong MethodDescSlotOffset = 8;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + MethodDescSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + MethodDescSlotOffset);
isPrestubMD = true;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/BenchmarkDotNet/Disassemblers/IntelDisassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ internal sealed class RuntimeSpecificData
// jmp QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForMethod)]
// LOCAL_LABEL(CountReachedZero):
// jmp QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
internal byte[] callCountingStubTemplate = new byte[10] { 0x48, 0x8b, 0x05, 0xf9, 0x0f, 0x00, 0x00, 0x66, 0xff, 0x08 };
internal readonly byte[] callCountingStubTemplate = new byte[10] { 0x48, 0x8b, 0x05, 0xf9, 0x0f, 0x00, 0x00, 0x66, 0xff, 0x08 };
// mov r10, [rip + DATA_SLOT(StubPrecode, MethodDesc)]
// jmp [rip + DATA_SLOT(StubPrecode, Target)]
internal byte[] stubPrecodeTemplate = new byte[13] { 0x4c, 0x8b, 0x15, 0xf9, 0x0f, 0x00, 0x00, 0xff, 0x25, 0xfb, 0x0f, 0x00, 0x00 };
internal readonly byte[] stubPrecodeTemplate = new byte[13] { 0x4c, 0x8b, 0x15, 0xf9, 0x0f, 0x00, 0x00, 0xff, 0x25, 0xfb, 0x0f, 0x00, 0x00 };
// jmp [rip + DATA_SLOT(FixupPrecode, Target)]
// mov r10, [rip + DATA_SLOT(FixupPrecode, MethodDesc)]
// jmp [rip + DATA_SLOT(FixupPrecode, PrecodeFixupThunk)]
internal byte[] fixupPrecodeTemplate = new byte[19] { 0xff, 0x25, 0xfa, 0x0f, 0x00, 0x00, 0x4c, 0x8b, 0x15, 0xfb, 0x0f, 0x00, 0x00, 0xff, 0x25, 0xfd, 0x0f, 0x00, 0x00 };
internal int stubPageSize;
internal readonly byte[] fixupPrecodeTemplate = new byte[19] { 0xff, 0x25, 0xfa, 0x0f, 0x00, 0x00, 0x4c, 0x8b, 0x15, 0xfb, 0x0f, 0x00, 0x00, 0xff, 0x25, 0xfd, 0x0f, 0x00, 0x00 };
internal readonly ulong stubPageSize;

internal RuntimeSpecificData(State state)
{
stubPageSize = Environment.SystemPageSize;
stubPageSize = (ulong)Environment.SystemPageSize;
if (state.RuntimeVersion.Major >= 8)
{
// In .NET 8, the stub page size was changed to 16kB
Expand Down Expand Up @@ -84,15 +84,15 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
if (state.Runtime.DataTarget.DataReader.Read(address, buffer) == buffer.Length && buffer.SequenceEqual(data.callCountingStubTemplate))
{
const ulong TargetMethodAddressSlotOffset = 8;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + TargetMethodAddressSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + TargetMethodAddressSlotOffset);
}
else
{
buffer = new byte[13];
if (state.Runtime.DataTarget.DataReader.Read(address, buffer) == buffer.Length && buffer.SequenceEqual(data.stubPrecodeTemplate))
{
const ulong MethodDescSlotOffset = 0;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + MethodDescSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + MethodDescSlotOffset);
isPrestubMD = true;
}
else
Expand All @@ -101,7 +101,7 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
if (state.Runtime.DataTarget.DataReader.Read(address, buffer) == buffer.Length && buffer.SequenceEqual(data.fixupPrecodeTemplate))
{
const ulong MethodDescSlotOffset = 8;
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + (ulong)data.stubPageSize + MethodDescSlotOffset);
address = state.Runtime.DataTarget.DataReader.ReadPointer(address + data.stubPageSize + MethodDescSlotOffset);
isPrestubMD = true;
}

Expand Down