Skip to content

JIT: Fix heap allocations - #120290

Merged
jakobbotsch merged 6 commits into
dotnet:mainfrom
jakobbotsch:fix-120285
Oct 2, 2025
Merged

jakobbotsch merged 6 commits into
dotnet:mainfrom
jakobbotsch:fix-120285

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

Also override the global new operators to assert unconditionally, to catch this common pitfall proactively.
Ideally that would be a compile time diagnostic, but I could not figure out how to make that happen.

Fix #120285

Also override the global new operators to assert unconditionally, to
catch this common pitfall proactively.
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 1, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Comment thread src/coreclr/jit/alloc.cpp Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved
@SingleAccretion

Copy link
Copy Markdown
Contributor

In the single-file host, the Jit is going to be linked statically with the rest of the native code. Is the fact this override is not causing problems in that case by construction or accidental?

@jakobbotsch

Copy link
Copy Markdown
Member Author

In the single-file host, the Jit is going to be linked statically with the rest of the native code. Is the fact this override is not causing problems in that case by construction or accidental?

Accidental. Let me hide it under a define set for the standalone jits.

@jakobbotsch
jakobbotsch marked this pull request as ready for review October 1, 2025 15:01
Copilot AI review requested due to automatic review settings October 1, 2025 15:01
@jakobbotsch

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib. I want to backport this to GA, but might not backport the "diagnostic" new override.

@jakobbotsch
jakobbotsch requested a review from a team October 1, 2025 15:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to eliminate unintended heap allocations in the JIT by routing allocations through the JIT's custom allocators and by asserting on any accidental use of the global operator new in standalone builds.

  • Replaces raw global new usages with allocator-aware placement new for LSRA structures.
  • Introduces overridden global operator new/delete (guarded by JIT_STANDALONE_BUILD) that assert to catch unintended allocations.
  • Adds a build define to enable the new checks.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/coreclr/jit/lsra.cpp Switches allocations to use compiler memory kinds via placement new.
src/coreclr/jit/alloc.cpp Adds global operator new/delete overrides to assert on unintended allocations.
src/coreclr/jit/CMakeLists.txt Defines JIT_STANDALONE_BUILD to enable the new allocation assertions.

Comment thread src/coreclr/jit/CMakeLists.txt Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved
Comment thread src/coreclr/jit/alloc.cpp Resolved

@EgorBo EgorBo left a comment

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.

LGTM assuming CI passes

Comment thread src/coreclr/jit/alloc.cpp Resolved
@jakobbotsch
jakobbotsch merged commit 77fe5dc into dotnet:main Oct 2, 2025
@jakobbotsch

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot mentioned this pull request Oct 2, 2025
2 of 4 tasks
@jakobbotsch
jakobbotsch deleted the fix-120285 branch October 2, 2025 08:54
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 2, 2025
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.

Unmanaged memory leak in clrjit (amd64) in .NET 10 RC1

6 participants