diff --git a/docs/design/datacontracts/ExecutionManager.md b/docs/design/datacontracts/ExecutionManager.md index c868e976238884..a30d874e0ae023 100644 --- a/docs/design/datacontracts/ExecutionManager.md +++ b/docs/design/datacontracts/ExecutionManager.md @@ -7,10 +7,10 @@ managed method corresponding to that address. ## APIs of contract ```csharp -internal struct EECodeInfoHandle +struct EECodeInfoHandle { - // no public constructor public readonly TargetPointer Address; + // no public constructor internal EECodeInfoHandle(TargetPointer address) => Address = address; } ``` @@ -75,13 +75,18 @@ The bulk of the work is donee by the `GetEECodeInfoHandle` API that maps a code } EECodeInfoHandle? IExecutionManager.GetEECodeInfoHandle(TargetCodePointer ip) { + TargetPointer key = ip.AsTargetPointer; + if (/*cache*/.ContainsKey(key)) + { + return new EECodeInfoHandle(key); + } EECodeInfo? info = GetEECodeInfo(ip); if (info == null || !info.Valid) { return null; } - TargetPointer key = info.CodeHeaderAddress; - AddToCache(key, info);/* add a mapping from key to info to a chache */ + /*cache*/.TryAdd(key, info); + return new EECodeInfoHandle(key); return new EECodeInfoHandle(key); } ``` diff --git a/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager_1.cs b/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager_1.cs index d9e7efead9fa51..7abd1efd680794 100644 --- a/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager_1.cs +++ b/src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/ExecutionManager_1.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Microsoft.Diagnostics.DataContractReader.ExecutionManagerHelpers; namespace Microsoft.Diagnostics.DataContractReader.Contracts; @@ -29,6 +28,8 @@ public ExecutionManager_1(Target target, Data.RangeSectionMap topRangeSectionMap _r2rJitManager = new ReadyToRunJitManager(_target); } + // Note, because of RelativeOffset, this code info is per code pointer, not per method + // TODO: rethink whether this makes sense. We don't need to copy the runtime's notion of EECodeInfo verbatim private class EECodeInfo { private readonly int _codeHeaderOffset; @@ -165,14 +166,16 @@ private JitManager GetJitManager(Data.RangeSection rangeSectionData) } EECodeInfoHandle? IExecutionManager.GetEECodeInfoHandle(TargetCodePointer ip) { - // TODO: some kind of cache based on ip, too? - // we don't know if the ip is the start of the code. + TargetPointer key = ip.AsTargetPointer; // FIXME: thumb bit. It's harmless (we potentialy have 2 cache entries per IP), but we should fix it + if (_codeInfos.ContainsKey(key)) + { + return new EECodeInfoHandle(key); + } EECodeInfo? info = GetEECodeInfo(ip); if (info == null || !info.Valid) { return null; } - TargetPointer key = info.CodeHeaderAddress; _codeInfos.TryAdd(key, info); return new EECodeInfoHandle(key); }