-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[wasm] Report on-frame GC slots as pinned #131374
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
Merged
lewing
merged 11 commits into
dotnet:main
from
lewing:lewing-wasm-spill-gcrefs-held-across-calls
Jul 27, 2026
+69
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
050fd43
[wasm] Spill GC refs held across calls even when sourced from a local
lewing 547bd81
Remove Runtime_131373 test: it does not exercise the fix
lewing 50b4906
Add Runtime_131373: verified wasm R2R GC hole regression test
lewing fc80927
Clarify why the allocation churn is required in Runtime_131373
lewing 6f87d96
[wasm] Report on-frame GC slots as pinned instead of re-spilling locals
lewing 5a647db
Scope the wasm pinned-slot change to the use site
lewing 2c5bbb4
Leave fgwasm.cpp untouched
lewing 39d6379
Elide the pinned condition on wasm rather than duplicating the body
lewing eab78be
Trim the wasm pinning comment and restore the TODO-WASM line
lewing 432119e
Cut the wasm pinning comment to why, and defer to the ABI doc
lewing 3f6f612
Cut the comments in Runtime_131373
lewing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/tests/JIT/Regression/JitBlue/Runtime_131373/Runtime_131373.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // A GC ref pushed onto the wasm operand stack is a copy the GC can't update, so it goes stale | ||
| // when a call relocates the referent. Only reproduces under crossgen wasm R2R (TargetOS=browser). | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_131373 | ||
| { | ||
| public sealed class Box | ||
| { | ||
| public object Slot; | ||
| public int Tag; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| for (int i = 0; i < 400; i++) | ||
| { | ||
| for (int j = 0; j < 32; j++) | ||
| { | ||
| byte[] garbage = new byte[8192]; | ||
| GC.KeepAlive(garbage); | ||
| } | ||
|
|
||
| Box box = new Box { Tag = i }; | ||
| StoreThroughByref(ref box.Slot, i); | ||
| Assert.NotNull(box.Slot); | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static void StoreThroughByref(ref object slot, int i) | ||
| { | ||
| slot = Allocate(i); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static object Allocate(int i) | ||
| { | ||
| for (int j = 0; j < 48; j++) | ||
| { | ||
| byte[] garbage = new byte[8192]; | ||
| GC.KeepAlive(garbage); | ||
| } | ||
|
|
||
| GC.Collect(2, GCCollectionMode.Forced, blocking: true, compacting: true); | ||
|
|
||
| return new string('x', 1 + (i & 7)); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/tests/JIT/Regression/JitBlue/Runtime_131373/Runtime_131373.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| <!-- Force crossgen on the browser leg so this actually runs as wasm R2R. --> | ||
| <AlwaysUseCrossGen2 Condition="'$(TargetOS)' == 'browser'">true</AlwaysUseCrossGen2> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.