Skip to content
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

Fix memory leak in SuperPMI #34523

Merged
merged 1 commit into from
Apr 5, 2020

Conversation

BruceForstall
Copy link
Member

Introduced on Windows by change to Heap APIs (#34289).

Also fixes a long-existing memory leak on Linux where we never had HeapDestroy().

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 3, 2020
@BruceForstall BruceForstall requested a review from sandreenko April 3, 2020 22:51
@BruceForstall
Copy link
Member Author

@sandreenko PTAL
cc @jkotas

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -41,6 +41,16 @@ CompileResult::~CompileResult()

if (CallTargetTypes != nullptr)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: You can delete the null checks for these - to make the style consistent.

Copy link
Contributor

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

@jkotas
Copy link
Member

jkotas commented Apr 4, 2020

superpmi test is failing

Introduced by change to Heap APIs. Also fixes a long-existing
memory leak on Linux.

Introduce a small, simple class to keep track of memory allocations
associated with the CompileResult that we need to free. In the replay
case, SuperPMI allocates these (such as for the JIT calling allocMem).
In the case of collection, the VM allocates memory for allocMem (and related),
so that memory doesn't need to be tracked.
@BruceForstall BruceForstall force-pushed the FixSuperPMIMemoryLeak branch from 51288f7 to e0f5444 Compare April 4, 2020 21:46
@BruceForstall
Copy link
Member Author

In the replay case, the previous code was correct. However, in the collection case the memory from allocMem is allocated by the VM and doesn't need to be tracked (or deleted). I introduced a new, simple memory tracking class that is doing basically what the previous use of HeapAlloc/HeapDestroy was doing. Allocations during replay go through it, and deleting a CompileResult will delete the correct, associated set of allocated memory.

void* allocate(size_t sizeInBytes)
{
BYTE* pNew = new BYTE[sizeInBytes];
m_pHead = new MemoryNode(pNew, m_pHead); // Prepend this new one to the tracked memory list.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This has memory leak if new MemoryNode throws, but I assume that we do not care about hardening like this in superpmi.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'm not too worried about hardening superpmi for OOM

@BruceForstall BruceForstall merged commit 6996928 into dotnet:master Apr 5, 2020
@BruceForstall BruceForstall deleted the FixSuperPMIMemoryLeak branch April 5, 2020 17:10
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants