[Cpu] Read import stack arguments from the thread's own stack without a region query
Every import copies six stack argument slots (twice, with the per-thread diagnostics). The per-thread readable-range cache is keyed by the host mapping generation, which every tracker protection change bumps, so on macOS nearly each slot fell through to a locked host region query: about half of the busy managed samples at Octopath Traveler II's title were in that query or waiting for its lock. Addresses inside the calling guest thread's stack, which the backend maps read-write for the thread's lifetime, are now read directly.
This commit is contained in:
parent
e99fcb9651
commit
fd8a78ad73
|
|
@ -1231,6 +1231,17 @@ public sealed partial class DirectExecutionBackend
|
|||
return TryReadHostQword(address, out value);
|
||||
}
|
||||
|
||||
// Stack arguments sit on the calling guest thread's own stack, which the backend mapped read-write
|
||||
// for the thread's lifetime and no tracker ever protects. Reading inside it needs no query: the
|
||||
// cached range below is keyed by a mapping generation that every tracker protection change bumps,
|
||||
// so falling through here cost a locked host region query per argument on nearly every import.
|
||||
if (_activeGuestThreadState is { StackSize: > 0 } thread &&
|
||||
address >= thread.StackBase && address <= thread.StackBase + thread.StackSize - sizeof(ulong))
|
||||
{
|
||||
value = *(ulong*)address;
|
||||
return true;
|
||||
}
|
||||
|
||||
var generation = HostMemory.MappingGeneration;
|
||||
if (generation == _importReadableGeneration &&
|
||||
address >= _importReadableStart && address <= _importReadableEnd - 8)
|
||||
|
|
|
|||
Loading…
Reference in New Issue