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 @@ -26,6 +26,7 @@ public interface IAbstractHeap
bool IsValidMethodTable(ulong mt);
MemoryRange GetInternalRootArray(ulong subHeapAddress);
bool GetOOMInfo(ulong subHeapAddress, out OomInfo oomInfo);
int? GetDynamicAdaptationMode();
}

public struct GCState
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.Diagnostics.Runtime/ClrHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ internal ClrHeap(ClrRuntime runtime, IMemoryReader memoryReader, IAbstractHeap h

SubHeaps = Helpers.EnumerateSubHeaps().Select(r => new ClrSubHeap(this, r)).ToImmutableArray();
Segments = SubHeaps.SelectMany(r => r.Segments).OrderBy(r => r.FirstObjectAddress).ToImmutableArray();
DynamicAdaptationMode = Helpers.GetDynamicAdaptationMode();
}

/// <summary>
/// The DynamicAdaptationMode
/// </summary>
public int? DynamicAdaptationMode
{
get;
}

/// <summary>
Expand Down
16 changes: 15 additions & 1 deletion src/Microsoft.Diagnostics.Runtime/DacImplementation/DacHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class DacHeap : IAbstractHeap
private readonly SOSDac _sos;
private readonly SOSDac8? _sos8;
private readonly SosDac12? _sos12;
private readonly ISOSDac16? _sos16;
private readonly IMemoryReader _memoryReader;
private readonly GCState _gcState;
private HashSet<ulong>? _validMethodTables;
Expand All @@ -28,11 +29,12 @@ internal sealed class DacHeap : IAbstractHeap
private const uint SyncBlockSpinLock = 0x10000000;
private const uint SyncBlockHashOrSyncBlockIndex = 0x08000000;

public DacHeap(SOSDac sos, SOSDac8? sos8, SosDac12? sos12, IMemoryReader reader, in GCInfo gcInfo, in CommonMethodTables commonMethodTables)
public DacHeap(SOSDac sos, SOSDac8? sos8, SosDac12? sos12, ISOSDac16? sos16, IMemoryReader reader, in GCInfo gcInfo, in CommonMethodTables commonMethodTables)
{
_sos = sos;
_sos8 = sos8;
_sos12 = sos12;
_sos16 = sos16;
_memoryReader = reader;
_gcState = new()
{
Expand Down Expand Up @@ -448,5 +450,17 @@ public bool GetOOMInfo(ulong subHeapAddress, out OomInfo oomInfo)
};
return true;
}

public int? GetDynamicAdaptationMode()
{
if (_sos16 != null)
{
return _sos16.GetDynamicAdaptationMode();
}
else
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class DacServiceProvider : IServiceProvider, IDisposable, IAbstractDacC
private readonly SosDac12? _sos12;
private readonly ISOSDac13? _sos13;
private readonly SosDac14? _sos14;
private readonly ISOSDac16? _sos16;

private IAbstractClrNativeHeaps? _nativeHeaps;
private IAbstractComHelpers? _com;
Expand All @@ -47,6 +48,7 @@ public DacServiceProvider(ClrInfo clrInfo, DacLibrary library)
_sos12 = _process.CreateSOSDacInterface12();
_sos13 = _process.CreateSOSDacInterface13();
_sos14 = _process.CreateSOSDacInterface14();
_sos16 = _process.CreateSOSDacInterface16();

library.DacDataTarget.SetMagicCallback(_process.Flush);
IsThreadSafe = _sos13 is not null || RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
Expand All @@ -66,6 +68,7 @@ public void Dispose()
_sos12?.Dispose();
_sos13?.Dispose();
_sos14?.Dispose();
_sos16?.Dispose();
_dac.Dispose();
_moduleHelper?.Dispose();
}
Expand All @@ -82,7 +85,7 @@ public void Dispose()
return heap;

if (_sos.GetGCHeapData(out GCInfo data) && _sos.GetCommonMethodTables(out CommonMethodTables mts) && mts.ObjectMethodTable != 0)
return _heapHelper = new DacHeap(_sos, _sos8, _sos12, _dataReader, data, mts);
return _heapHelper = new DacHeap(_sos, _sos8, _sos12, _sos16, _dataReader, data, mts);

return null;
}
Expand Down
16 changes: 16 additions & 0 deletions src/Microsoft.Diagnostics.Runtime/DacInterface/ClrDataProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ public ClrDataProcess(DacLibrary library, CallableCOMWrapper toClone) : base(toC
}
}

public ISOSDac16? CreateSOSDacInterface16()
{
IntPtr result = QueryInterface(SOSDac16.IID_ISOSDac16);
if (result == IntPtr.Zero)
return null;

try
{
return new SOSDac16(_library, result);
}
catch (InvalidOperationException)
{
return null;
}
}

public void Flush()
{
VTable.Flush(Self);
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.Diagnostics.Runtime/DacInterface/ISOSDac16.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Diagnostics.Runtime.Utilities;

namespace Microsoft.Diagnostics.Runtime.DacInterface
{
internal interface ISOSDac16 : IDisposable
{
int? GetDynamicAdaptationMode();
}
}
42 changes: 42 additions & 0 deletions src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac16.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Diagnostics.Runtime.Utilities;
using static Microsoft.Diagnostics.Runtime.DacInterface.SOSDac;

namespace Microsoft.Diagnostics.Runtime.DacInterface
{
/// <summary>
/// This is an undocumented, untested, and unsupported interface. Do not use directly.
/// </summary>
internal sealed unsafe class SOSDac16 : CallableCOMWrapper, ISOSDac16
{
private readonly DacLibrary _library;

internal static readonly Guid IID_ISOSDac16 = new("4ba12ff8-daac-4e43-ac56-98cf8d5c595d");

public SOSDac16(DacLibrary library, IntPtr ptr)
: base(library?.OwningLibrary, IID_ISOSDac16, ptr)
{
_library = library ?? throw new ArgumentNullException(nameof(library));
}

private ref readonly ISOSDac16VTable VTable => ref Unsafe.AsRef<ISOSDac16VTable>(_vtable);

public int? GetDynamicAdaptationMode()
{
HResult hr = VTable.GetDynamicAdaptationMode(Self, out int result);
return (hr == HResult.S_OK) ? result : null;
}

[StructLayout(LayoutKind.Sequential)]
private readonly unsafe struct ISOSDac16VTable
{
public readonly delegate* unmanaged[Stdcall]<nint, out int, int> GetDynamicAdaptationMode;
}
}
}