Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ public abstract class ContractRegistry
public virtual IBuiltInCOM BuiltInCOM => GetContract<IBuiltInCOM>();

public abstract TContract GetContract<TContract>() where TContract : IContract;

/// <summary>
/// Flush all cached data held by contracts in this registry.
/// Called when the target process state may have changed (e.g. on resume).
/// </summary>
public abstract void Flush();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ namespace Microsoft.Diagnostics.DataContractReader.Contracts;
public interface IContract
{
static virtual string Name => throw new NotImplementedException();

/// <summary>
/// Clear any cached data held by this contract.
/// Called when the target process state may have changed (e.g. on resume).
/// </summary>
void Flush() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,14 @@ public readonly record struct FieldInfo
/// A cache of the contracts for the target process
/// </summary>
public abstract ContractRegistry Contracts { get; }

/// <summary>
/// Clear all cached data held by this target, including processed data and contract caches.
/// Called when the target process state may have changed (e.g. on resume).
/// </summary>
public void Flush()
{
ProcessedData.Clear();
Contracts.Flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ internal sealed class EcmaMetadata_1(Target target) : IEcmaMetadata
{
private Dictionary<ModuleHandle, MetadataReaderProvider?> _metadata = new();

public void Flush()
{
_metadata.Clear();
}

public TargetSpan GetReadOnlyMetadataAddress(ModuleHandle handle)
{
ILoader loader = target.Contracts.Loader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public ExecutionManagerCore(Target target, Data.RangeSectionMap topRangeSectionM
_r2rJitManager = new ReadyToRunJitManager(_target);
}

public void Flush()
{
_codeInfos.Clear();
}

// Note, because of RelativeOffset, this code info is per code pointer, not per method
private sealed class CodeBlock
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ internal ExecutionManager_1(Target target, Data.RangeSectionMap topRangeSectionM
public TargetNUInt GetRelativeOffset(CodeBlockHandle codeInfoHandle) => _executionManagerCore.GetRelativeOffset(codeInfoHandle);
public List<ExceptionClauseInfo> GetExceptionClauses(CodeBlockHandle codeInfoHandle) => _executionManagerCore.GetExceptionClauses(codeInfoHandle);
public JitManagerInfo GetEEJitManagerInfo() => _executionManagerCore.GetEEJitManagerInfo();
public void Flush() => _executionManagerCore.Flush();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ internal ExecutionManager_2(Target target, Data.RangeSectionMap topRangeSectionM
public TargetNUInt GetRelativeOffset(CodeBlockHandle codeInfoHandle) => _executionManagerCore.GetRelativeOffset(codeInfoHandle);
public List<ExceptionClauseInfo> GetExceptionClauses(CodeBlockHandle codeInfoHandle) => _executionManagerCore.GetExceptionClauses(codeInfoHandle);
public JitManagerInfo GetEEJitManagerInfo() => _executionManagerCore.GetEEJitManagerInfo();
public void Flush() => _executionManagerCore.Flush();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ internal partial struct RuntimeTypeSystem_1 : IRuntimeTypeSystem
private readonly Dictionary<TypeKey, TypeHandle> _typeHandles = new();
private readonly Dictionary<TypeKeyByName, TypeHandle> _typeHandlesByName = new();

public void Flush()
{
_methodTables.Clear();
_methodDescs.Clear();
_typeHandles.Clear();
_typeHandlesByName.Clear();
}

internal struct MethodTable
{
internal MethodTableFlags_1 Flags { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ internal SignatureDecoder_1(Target target)
_target = target;
}

public void Flush()
{
_thProviders.Clear();
_mdhProviders.Clear();
}

private SignatureTypeProvider<TypeHandle> GetTypeHandleProvider(ModuleHandle moduleHandle)
{
if (_thProviders.TryGetValue(moduleHandle, out SignatureTypeProvider<TypeHandle>? thProvider))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed unsafe partial class SOSDacImpl : IXCLRDataProcess, IXCLRDataProce
{
int IXCLRDataProcess.Flush()
{
_target.ProcessedData.Clear();
_target.Flush();

// As long as any part of cDAC falls back to the legacy DAC, we need to propagate the Flush call
if (_legacyProcess is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5785,7 +5785,15 @@ int ISOSDacInterface13.GetGCBookkeepingMemoryRegions(DacComNullableByRef<ISOSMem
int ISOSDacInterface13.GetGCFreeRegions(DacComNullableByRef<ISOSMemoryEnum> ppEnum)
=> _legacyImpl13 is not null ? _legacyImpl13.GetGCFreeRegions(ppEnum) : HResults.E_NOTIMPL;
int ISOSDacInterface13.LockedFlush()
=> _legacyImpl13 is not null ? _legacyImpl13.LockedFlush() : HResults.E_NOTIMPL;
{
_target.Flush();

// As long as any part of cDAC falls back to the legacy DAC, we need to propagate the Flush call
if (_legacyImpl13 is not null)
return _legacyImpl13.LockedFlush();

return HResults.S_OK;
}
#endregion ISOSDacInterface13

#region ISOSDacInterface14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public override TContract GetContract<TContract>()
// Contract was already registered by someone else
return (TContract)_contracts[typeof(TContract)];
}

public override void Flush()
{
foreach (IContract contract in _contracts.Values)
{
contract.Flush();
}
}
}
2 changes: 2 additions & 0 deletions src/native/managed/cdac/tests/TestPlaceholderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ public override TContract GetContract<TContract>()

throw new NotImplementedException($"Contract {typeof(TContract).Name} is not registered.");
}

public override void Flush() { }
}

}