Skip to content

Simplify frozen object heap allocation - #135956

Merged
MichalStrehovsky merged 3 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-frozen-heap
Oct 20, 2026
Merged

MichalStrehovsky merged 3 commits into
dotnet:mainfrom
MichalStrehovsky:nativeaot-wasm-frozen-heap

Conversation

@MichalStrehovsky

@MichalStrehovsky MichalStrehovsky commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

The use of this is more rare than on CoreCLR VM. The implementation can be simpler.

WASM has no page protection or separate reserve/commit operations, so the
Unix mmap(PROT_NONE)/mprotect implementation fails when reflection needs
a frozen segment.

Use aligned, zeroed native allocations with matching free, and make
commit a no-op. Select the WASM partial implementation in NativeAOT
CoreLib while leaving the Unix implementation unchanged elsewhere.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a6f3a617-acae-4f4f-95d3-20b2a0bac43c
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Use ordinary zeroed native allocations across platforms and start frozen segments at 4 KB. Remove virtual-memory bookkeeping, platform partials, copied assertion comments, and the unused MProtect interop declaration. Exercise segment growth and compacting GC in the reflection smoke test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6dc84b16-c9f8-4272-be81-c459f49f6429

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.

🟡 Changes recommended

The allocator rewrite changes desktop memory policy beyond the stated WASM-only scope without desktop validation.

1 open issue
What changed in this PR

Enables NativeAOT frozen-object allocation on WASM by replacing platform-specific virtual memory operations with shared zero-initialized native allocations.

Changes:

  • Reworks segment allocation and removes reserve/commit helpers.
  • Removes obsolete project entries and managed MProtect interop.
  • Adds reflection checks for dynamically created array types across forced garbage collection.
File Description
src/​tests/​nativeaot/​SmokeTests/​Reflection/​Reflection.cs Adds runtime-type identity and rank checks.
src/​libraries/​Common/​src/​Interop/​Unix/​System.Native/​Interop.MProtect.cs Removes managed protection interop.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System.Private.CoreLib.csproj Removes platform allocator includes.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​Internal/​Runtime/​FrozenObjectHeapManager.Windows.cs Removes Windows virtual-memory helpers.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​Internal/​Runtime/​FrozenObjectHeapManager.Unix.cs Removes Unix virtual-memory helpers.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​Internal/​Runtime/​FrozenObjectHeapManager.cs Uses shared zeroed allocations with smaller initial segments.

Review effort: Balanced

@MichalStrehovsky MichalStrehovsky changed the title Support NativeAOT frozen object heap allocation on WASM Simplify frozen object heap allocation Oct 19, 2026
@MichalStrehovsky MichalStrehovsky removed the arch-wasm WebAssembly architecture label Oct 19, 2026
Let NativeMemory.AllocZeroed propagate allocation failures instead of retrying with a smaller frozen segment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6dc84b16-c9f8-4272-be81-c459f49f6429
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g timeout on wasm

@MichalStrehovsky
MichalStrehovsky merged commit 1cddd53 into dotnet:main Oct 20, 2026
128 of 131 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the nativeaot-wasm-frozen-heap branch October 20, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants