Skip to content

[cDAC] Changing loader heaps from string-keyed to enum-keyed dict#127474

Open
rcj1 wants to merge 1 commit intodotnet:mainfrom
rcj1:la-heap
Open

[cDAC] Changing loader heaps from string-keyed to enum-keyed dict#127474
rcj1 wants to merge 1 commit intodotnet:mainfrom
rcj1:la-heap

Conversation

@rcj1
Copy link
Copy Markdown
Contributor

@rcj1 rcj1 commented Apr 27, 2026

Follow-up to #127296 (comment)

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Comment on lines +47 to +59
public enum LoaderAllocatorHeapType : uint
{
LowFrequency = 0,
HighFrequency = 1,
Statics = 2,
Stub = 3,
Executable = 4,
FixupPrecode = 5,
NewStubPrecode = 6,
DynamicHelpers = 7,
Indcell = 8,
CacheEntry = 9,
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to explicitly define the size of this enum and values? The flags above do, but given this is a true managed enum, I don't think we need to.


public enum LoaderAllocatorHeapType : uint
{
LowFrequency = 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe reserve 0 for an Unknown type in case there is something added in the future?

{
for (int i = 0; i < loaderHeapCount; i++)
int i = 0;
foreach (LoaderAllocatorHeapType heapType in Enum.GetValues<LoaderAllocatorHeapType>())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API requires the order of the loaderallocator heaps match those provided by GetLoaderAllocatorHeapNames.

I don't want to rely on the order of the managed enum to assert that we output in the correct order.

Can we use the previous behavior and map that to the expected enum values?

Copy link
Copy Markdown
Contributor Author

@rcj1 rcj1 Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we'd have something like heaps.TryGetValue(GetEnumForFilteredEntry(filteredEntries[i].Name)?

Comment on lines +296 to +310
ClrDataAddress* heaps = stackalloc ClrDataAddress[MockHeapDictionary.Count];
int* kinds = stackalloc int[MockHeapDictionary.Count];
int hr = impl.GetLoaderAllocatorHeaps(new ClrDataAddress(0x100), MockHeapDictionary.Count, heaps, kinds, &needed);

Assert.Equal(HResults.S_OK, hr);
Assert.Equal(MockHeapDictionary.Count, needed);
for (int i = 0; i < needed; i++)
int i = 0;
foreach (LoaderAllocatorHeapType heapType in Enum.GetValues<LoaderAllocatorHeapType>())
{
string name = Marshal.PtrToStringAnsi((nint)names[i])!;
Assert.Equal((ulong)MockHeapDictionary[name], (ulong)heaps[i]);
Assert.Equal(0, kinds[i]); // LoaderHeapKindNormal
if (MockHeapDictionary.TryGetValue(heapType, out TargetPointer expected))
{
Assert.Equal((ulong)expected, (ulong)heaps[i]);
Assert.Equal(0, kinds[i]); // LoaderHeapKindNormal
i++;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this unit test. We should verify that it matches the heap names, not the enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants