Split up loader heap implementations#114246
Conversation
…_heap_implementations
…, the free block handling is NOT a part of the interleaved heap as it didn't work, and wasn't actually hooked up.
…ared anymore Add support for a free list that actually works in the stub heaps
|
Tagging subscribers to this area: @mangod9 |
…_heap_implementations
| "\nset the following registry DWORD value:" | ||
| "\n" | ||
| "\n HKLM\\Software\\Microsoft\\.NETFramework\\LoaderHeapCallTracing = 1" |
There was a problem hiding this comment.
| "\nset the following registry DWORD value:" | |
| "\n" | |
| "\n HKLM\\Software\\Microsoft\\.NETFramework\\LoaderHeapCallTracing = 1" | |
| "\nset the following environment variable:" | |
| "\n" | |
| "\n DOTNET_LoaderHeapCallTracing=1" |
|
/ba-g the failing test is unrelated to this change and was fixed by Michal earlier today. |
|
Copilot spotted a typo #114246 (comment). |
Co-authored-by: Copilot <[email protected]>
| // and notify the user to provide more reserved mem. | ||
| _ASSERTE((dwSizeToCommit <= dwSizeToReserve) && "Loaderheap tried to commit more memory than reserved by user"); | ||
|
|
||
| if (!fReleaseMemory) |
There was a problem hiding this comment.
The fReleaseMemory is always set to TRUE at this point.
There was a problem hiding this comment.
I'll fix that. Thanks.
|
|
||
| INDEBUG(m_dwDebugWastedBytes += unusedRemainder;) | ||
|
|
||
| // For interleaved heaps, further allocations will start from the newly committed page as they cannot |
There was a problem hiding this comment.
A nit - maybe remove the "For interleaved heap, " from multiple comments here, that was only usefull originally when the code for interleaved heaps stuff was intertwined with the other code.
There was a problem hiding this comment.
I'll need to revisit these comments with the page remapping logic in my next PR. I'll address this then.
| // | ||
| // Caller is responsible for synchronization. ExplicitControlLoaderHeap is | ||
| // not multithread safe. | ||
| // The LoaderHeap is the black-box heap and has a Backout() method but none |
There was a problem hiding this comment.
This comment does not match InterleavedLoaderHeap
|
|
||
| protected: | ||
| void *UnlockedAllocMemForCode_NoThrow(size_t dwHeaderSize, size_t dwCodeSize, DWORD dwCodeAlignment, size_t dwReserveForJumpStubs); | ||
| // This frees memory allocated by UnlockAllocMem. It's given this horrible name to emphasize |
There was a problem hiding this comment.
| // This frees memory allocated by UnlockAllocMem. It's given this horrible name to emphasize | |
| // This frees memory allocated by UnlockedAllocStub. It's given this horrible name to emphasize |
| void SetReservedRegion(BYTE* dwReservedRegionAddress, SIZE_T dwReservedRegionSize, BOOL fReleaseMemory) | ||
|
|
||
| public: | ||
| // This frees memory allocated by AllocMem. It's given this horrible name to emphasize |
There was a problem hiding this comment.
| // This frees memory allocated by AllocMem. It's given this horrible name to emphasize | |
| // This frees memory allocated by AllocStub. It's given this horrible name to emphasize |
| #define DONOT_DEFINE_ETW_CALLBACK | ||
| #include "eventtracebase.h" | ||
|
|
||
| #ifndef DACCESS_COMPILE |
There was a problem hiding this comment.
Move the file to (non-DAC) UTILCODE_SOURCES in CMakeLists.txt instead of end-to-end ifdef
| m_codePageGenerator = codePageGenerator; | ||
| } | ||
|
|
||
| // ~LoaderHeap is not synchronised (obviously) |
There was a problem hiding this comment.
| // ~LoaderHeap is not synchronised (obviously) |
|
|
||
| size_t dwSize = dwRequestedSize; | ||
|
|
||
| // Interleaved heap cannot ad any extra to the requested size |
There was a problem hiding this comment.
| // Interleaved heap cannot ad any extra to the requested size |
We have long had 3 rather different heaps embedded in one structure called a
LoaderHeap. They have shared ... some infrastructure, but there is a mess of confusing flags and code paths which only work for one or the other type of heap.This PR changes that to supporting the 3 different types of heaps with separate codebases, and keeps as much of the shared infrastructure as I could manage. Its, not what I would call a pretty separation, as there is a bit of a mess around the way the DAC apis can access the heaps, but I think this is an improvement. Notably, in a followon PR I'm intending to provide a new mechanism for the interleaved heap to work off of contents of a file instead of creating unique pages per stub block. (This should slighly improve the cache locality of .NET programs, and is a prerequisite for running on some heavily locked down platforms.) This PR prepares for that by making the Interleaved heap its own thing, so adding new behavior variants is a reviewable piece of work.
The only functional change that happens with this PR is the newly added capability of the interleaved heaps to support freeing memory. (It was always possible to free, but for some reason the re-allocation behavior was not actually supported.)