Skip to content

Handle Synchronized async versions#129901

Draft
jakobbotsch wants to merge 8 commits into
dotnet:mainfrom
jakobbotsch:fix-synchronized-async-versions
Draft

Handle Synchronized async versions#129901
jakobbotsch wants to merge 8 commits into
dotnet:mainfrom
jakobbotsch:fix-synchronized-async-versions

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

Non-async Task-returning methods can be Synchronized. We were missing handling for that async version scenario in the JIT and interpreter.

Non-async Task-returning methods can be Synchronized. We were missing
handling for that scenario in the JIT and interpreter.
Copilot AI review requested due to automatic review settings June 26, 2026 17:56
@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 Jun 26, 2026

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 updates CoreCLR’s runtime-async (“async version”) handling for MethodImplOptions.Synchronized methods that return Task / ValueTask without being async, ensuring the monitor is released at the correct point in both the JIT and interpreter paths, and adds a regression test for the scenario.

Changes:

  • JIT: avoid async-version “tail await” recognition for synchronized methods and emit an explicit MON_EXIT before wrapping the return value in an await.
  • JIT flowgraph: avoid injecting the usual synchronized-return MON_EXIT blocks for async versions (since they’re now emitted during import).
  • Interpreter: centralize creation of the synchronized/async return-value temp and adjust async-version return wrapping / tailcall peep behavior.
  • Tests: add a new async regression test project covering both Task and ValueTask.

Reviewed changes

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

Show a summary per file
File Description
src/tests/async/regression/synchronized-async-version.csproj Adds a new IL test project for the regression scenario.
src/tests/async/regression/synchronized-async-version.cs Adds xUnit coverage for synchronized non-async Task/ValueTask returns under runtime async.
src/coreclr/jit/importer.cpp Ensures synchronized async versions release the monitor before awaiting/wrapping return values; blocks tail-await recognition for synchronized methods.
src/coreclr/jit/flowgraph.cpp Avoids duplicating synchronized-return monitor-exit insertion for async versions; makes lvaMonAcquired allocation idempotent.
src/coreclr/interpreter/compiler.h Adds declarations/state related to synchronized async-version return handling.
src/coreclr/interpreter/compiler.cpp Adds CreateSynchronizedRetValVar helper and adjusts return/tailcall logic for synchronized async versions.

Comment thread src/tests/async/regression/synchronized-async-version.cs Outdated
Comment thread src/tests/async/regression/synchronized-async-version.cs Outdated
Comment thread src/tests/async/regression/synchronized-async-version.cs Outdated
Comment thread src/coreclr/interpreter/compiler.cpp Outdated
Comment thread src/coreclr/interpreter/compiler.h Outdated
Copilot AI review requested due to automatic review settings June 26, 2026 18:04

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

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

Comment thread src/tests/async/regression/synchronized-async-version.cs
Comment thread src/tests/async/regression/synchronized-async-version.cs
Comment thread src/coreclr/interpreter/compiler.cpp Outdated
Comment thread src/coreclr/interpreter/compiler.h Outdated
Copilot AI review requested due to automatic review settings June 26, 2026 18:10

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

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

Comment thread src/coreclr/interpreter/compiler.cpp Outdated
Comment thread src/coreclr/interpreter/compiler.h
Comment thread src/tests/async/regression/synchronized-async-version.cs
Comment thread src/tests/async/regression/synchronized-async-version.cs
Copilot AI review requested due to automatic review settings June 26, 2026 18:22

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

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

Comment thread src/coreclr/interpreter/compiler.cpp
Comment thread src/coreclr/interpreter/compiler.cpp
Comment thread src/coreclr/interpreter/compiler.cpp
Copilot AI review requested due to automatic review settings June 26, 2026 18:35

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/tests/async/regression/synchronized-async-version.csproj
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 18:45

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/tests/async/regression/synchronized-async-version.csproj
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 runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants