Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #936.
Here are a few key changes in the heap data structure:
To get our terminologies straight, while we still have the
heap_segmentobjects, we call themregionobjects under the context ofUSE_REGIONS.Under
USE_REGIONS, theheap_segmentobject itself is stored somewhere other than the address it manages (it is part of theseg_mapping_tableto be precise), therefore we cannot use the address of theheap_segmentobject itself to determine the base address of the region.With
USE_REGIONS, gen0 and gen1 are no longer restricted onephemeral_heap_segment, we could have a linked list of regions for gen0 and gen1. This explains the extra calls toAddSegmentsonProcessHeap.The field
allocation_startis no longer defined ingeneration. For backward compatibility reasons, the field is still defined on theDacpGenerationDatastructure, but it will always be 0 in .NET 6 whenUSE_REGIONSis turned on. There isn't a single start and end pointer for gen0 and gen1 anymore. Instead, each region belongs to a generation, therefore theGen0StartandGen0Lengthare simply set to theStartandEnd-Startof the region if it is indeed a gen0 region, otherwise it is set toEndand0respectively.Beyond the obvious changes, here are some not so obvious changes that might break things:
Status of the PR:
Right now this fix is sufficient to get the DumpGen command in SOS to work with dotnet/diagnostics#2501. With some hacks, all the unit tests passed. I might have missed other scenarios that are not covered by the tests.
Future work:
As the change on SOS side and unit test changes indicate, even when the fix is in, it is still possible for callers to be broken by
USE_REGIONS. While there is nothing we can do in the code to prevent that, we might be able to communicate upfront to get it fixed earlier.Eventually, we need to publish a new version with region support enabled so that SOS (and other tools) can consume the new functionalities.