Repository navigation
Prevent inlining of the helper in the FileStream strategy finalization tests - #136726
JulieLeeMSFT merged 1 commit into
Conversation
…n tests VerifyStrategyFinalization relies on EnsureFileStreamIsNotRooted running in its own frame so that nothing in the frame of GC.Collect() can reference the FileStream or its strategy. Without NoInlining the JIT is free to inline the helper (async inlining stress picks it under JitStress=2), and then dead references can stay reachable from the caller's frame, for example in GC spill temps, which are reported to the GC as live for the entire method. That makes the weak reference survive GC.Collect() and fails the tests on the x86, arm and arm64 jitstress2 legs that also stress the register allocator. Mark the helper NoInlining. Related to dotnet#133121 and dotnet#136604. Co-authored-by: Copilot <[email protected]> Copilot-Session: ea5600e2-9176-4e98-9306-8487dd7cbb5f
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-io |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the test-only change that preserves a separate helper stack frame during finalization checks.
No open issues 🎉
What changed in this PR
This PR stabilizes FileStream strategy finalization tests by preventing helper inlining from keeping objects reachable during garbage collection. It targets stress-test failures associated with #133121 and #136604 without changing production behavior.
Changes:
- Adds
MethodImplOptions.NoInliningtoEnsureFileStreamIsNotRootedand imports its namespace. - Expands the comment to explain why the helper must retain a separate stack frame.
| File | Description |
|---|---|
src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/Dispose.cs |
Prevents helper inlining and documents the object-lifetime constraint in finalization tests. |
Review effort: Balanced
|
/azp run runtime-coreclr libraries-jitstress, runtime-coreclr libraries-jitstress2-jitstressregs Note This comment was posted with the help of GitHub Copilot (AI-generated content). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run runtime-coreclr libraries-jitstress2-jitstressregs Note This comment was posted with the help of GitHub Copilot (AI-generated content). |
|
No pipelines are associated with this pull request. |
|
/azp list Note This comment was posted with the help of GitHub Copilot (AI-generated content). |
Command 'list
Supported commands
See additional documentation. |
|
/azp run runtime-coreclr libraries-jitstress2-jitstressregs |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Note The |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, thank you for providing the fix @JulieLeeMSFT !
Mark
EnsureFileStreamIsNotRootedinFileStream_Dispose.VerifyStrategyFinalizationasNoInlining.VerifyStrategyFinalizationrelies on the helper running in its own frame, so that nothing in the frame that callsGC.Collect()can reference theFileStreamor its strategy. WithoutNoInliningthe JIT is free to inline the helper, and dead references can then stay reachable from the caller's frame:JitStress=2selects (by method hash) the async rootVerifyStrategyFinalizationfor the async inlining stress, which inlinesEnsureFileStreamIsNotRootedinto it.JitStressRegs), the inlined value is spilled into a GC spill temp. The JIT reports GC spill temps as untracked stack slots, which are live for the whole method, so the object is still reachable atGC.Collect()and the weak reference survives. Object lifetimes are not guaranteed, so this is not a JIT bug.This is the failure in #133121 and #136604 (
Assert.False() FailureatFileStream/Dispose.cs:487) on the x86, arm and arm64jitstress2_jitstressregs*legs.Evidence, on x86 (Checked CoreCLR, Release libraries):
JitStress=2alone,JitStressRegsalone andJitStress=1withJitStressRegs=0x80pass.JitStress=2withJitStressRegs=0x80or2fails. AddingDOTNET_JitStressModeNamesNot=STRESS_ASYNC_INLINEmakes it pass again.JitDisasmshows[INLINED: random accept ASYNC] ...EnsureFileStreamIsNotRooted. The GC info at theGC.Collect()call has an extra untrackedTEMP_nn refslot in the failing builds and none in the passing build.Validation, all with
/p:TargetArchitecture=x86and the x86 testhost, running-class System.IO.Tests.FileStream_Dispose(30 tests):DOTNET_TieredCompilation=0 DOTNET_JitStress=2 DOTNET_JitStressRegs=0x80DOTNET_TieredCompilation=0 DOTNET_JitStress=2 DOTNET_JitStressRegs=2DOTNET_TieredCompilation=0 DOTNET_JitStressRegs=0x80 DOTNET_JitStressAsyncInlining=1 DOTNET_JitStressAsyncInliningPct=100DOTNET_TieredCompilation=0 DOTNET_JitStressRegs=2 DOTNET_JitStressAsyncInlining=1 DOTNET_JitStressAsyncInliningPct=100JitStressRegs= 1, 2, 3, 4, 8, 0x10, 0x80, 0x1000, 0x2000, each withJitStress=2and with theJitStressAsyncInliningknobs (18 runs)DOTNET_TieredCompilation=1 DOTNET_JitStress=2Build and test commands:
build.cmd clr+libs -a x86 -rc checked -lc release,build.cmd -subset libs.pretest -a x86 -rc checked -lc release, thendotnet.cmd build src\libraries\System.Runtime\tests\System.IO.FileSystem.Tests\System.IO.FileSystem.Tests.csproj -c Release /p:TargetArchitecture=x86 /t:Test "/p:XUnitOptions=-class System.IO.Tests.FileStream_Dispose"(30 passed), and the fullSystem.IO.FileSystem.Testsassembly with default settings (9,877 tests; the 25 failures are privilege-related Junction, mount volume and console input tests and none are in FileStream).Not verified:
jitstress2_tieredleg, which is the most frequent hit in Test Failure: System.IO.Tests.FileStream_Dispose.DisposeSuppressesStrategyFinalization #133121, did not reproduce locally (40 runs of the class and a full-assembly run on 4 cores all passed), so I can't claim this change covers it. Test Failure: System.IO.Tests.FileStream_Dispose.DisposeSuppressesStrategyFinalization #133121 and Test Failure: System.IO.Tests.FileStream_Dispose.DerivedFileStreamDisposeSuppressesStrategyFinalization* #136604 are intentionally not auto-closed; please re-check them after the next stress runs.Contributes to #133121 and #136604.
Note
This pull request was created with the help of GitHub Copilot (AI-generated content). Please review it carefully.