-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix Metadata aggregator: removing cumulative sum for GUIDs heap offset #115268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata |
|
Run unit-tests on this library: === TEST EXECUTION SUMMARY === |
| stringSizes[r + 1] = stringSizes[r] + deltaReaders[r].GetHeapSize(HeapIndex.String); | ||
| blobSizes[r + 1] = blobSizes[r] + deltaReaders[r].GetHeapSize(HeapIndex.Blob); | ||
| guidSizes[r + 1] = guidSizes[r] + deltaReaders[r].GetHeapSize(HeapIndex.Guid) / guidSize; | ||
| guidSizes[r + 1] = deltaReaders[r].GetHeapSize(HeapIndex.Guid) / guidSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line https://github.com/dotnet/runtime/pull/115268/files#diff-463bcba9d713f9c49493793a38b92567be4f344112abe18ebd08a34d3a5a1659R13 should be updated
|
It'd be good to have some tests that demonstrate correctness. There are some existing tests for MetadataAggregator, so you can update them. Make sure the test fails without your change and passes with the change. |
Hello! The linked comment was updated :) The method "CalculateHeapSizes(..)" I edited is private and its result is assigned to a private field directly in the constructor of the class. What would you suggest? Should I split the mentioned method in a separate class to enhance testability? Or else making the method 'internal'? |
|
Ping @tmat |
|
ping @tmat |
|
@fabrimaz as @tmat mentions the action here is to add a test to https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs. It looks like there are already tests that call |
|
@ericstj I might be completely wrong but feels like all the existing unit-tests are building _heapSize in a simplified way through a fake internal ctor, hence not replicating our 'issue'. To unit-test our behaviour, I need to use at least a baseReader and a list of MetadataReader deltas. |
|
By chance, do you have any clue on how to create a minimal MetadataReader with an allocated GUID? Couldn't find a good option among existing unit-tests for MetadataReader |
|
@dotnet-policy-service agree |
src/libraries/System.Reflection.Metadata/System.Reflection.Metadata.sln
Outdated
Show resolved
Hide resolved
...ries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataAggregator.cs
Outdated
Show resolved
Hide resolved
...ries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataAggregator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs
Outdated
Show resolved
Hide resolved
| // to avoid minimal flag exception. | ||
| reader.TableRowCounts[(int)TableIndex.EncMap] = 1; | ||
| reader.IsMinimalDelta = true; | ||
| return reader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're returning reader that accesses memory at pointer p but the target array can move once fixed block is exited. You need to keep the array pinned while using the reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored according to your suggestions
src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs
Outdated
Show resolved
Hide resolved
|
|
||
| // GUID-heap allocation shouldn't be cumulative, since GUIDs are copied among generations. | ||
| // The delta-reader above need indeed a single GUID allocation in each gen. | ||
| AssertExtensions.Throws<ArgumentException>("handle", () => TestGenerationHandle(aggregator, MetadataTokens.GuidHandle(2), expectedHandle: MetadataTokens.GuidHandle(2), expectedGeneration: 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to read 3 guids since there is one in baseline, and one in each delta, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmat in a real case yes, not in this test though.
Our new implementation removes cumulative sum and relies on each delta-reader GUID heap size, relying on deltareaders the copying of previous GUIDs and adding of existing new ones.
With new implementation, each generation here allocates a single GUID, hence only that one at index 1 could be read.
Tried to allocate more GUIDs on manually created delta-readers but couldn't find a working example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the GUID heap offset calculation in the MetadataAggregator by removing cumulative sum aggregation for GUID heap sizes. Unlike other heaps, GUIDs are copied across generations rather than being cumulative, so their heap sizes should represent the actual number of available GUIDs in each generation, not a running total.
- Removes cumulative sum calculation for GUID heap offsets in MetadataAggregator
- Updates documentation to clarify the different treatment of GUID heap sizes vs other heap types
- Adds comprehensive test coverage for the corrected GUID heap size behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataAggregator.cs | Updates GUID heap size calculation to use direct values instead of cumulative sum and adds clarifying documentation |
| src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs | Adds new test method and helper methods to verify correct GUID heap size behavior, plus additional using statements |
src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs
Outdated
Show resolved
Hide resolved
…5/MetadataAggregatorTests.cs Copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Yeah, I asked @tmat about it and he said he'll get back to it, but it's not a top priority at the moment I believe because a workaround is in place. |
Removing cumulative sum for GUID heap offsets
Fixes #113910