Skip to content

Conversation

jakobbotsch
Copy link
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
Copy link
Contributor

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

@SingleAccretion
Copy link
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
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 Copilot AI review requested due to automatic review settings October 1, 2025 15:01
@jakobbotsch
Copy link
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
Copy link
Contributor

@Copilot Copilot AI left a 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 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.

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

LGTM assuming CI passes

@jakobbotsch jakobbotsch merged commit 77fe5dc into dotnet:main Oct 2, 2025
117 checks passed
@jakobbotsch
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

github-actions bot commented Oct 2, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18188174550

@jakobbotsch jakobbotsch deleted the fix-120285 branch October 2, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
5 participants