Skip to content

Conversation

davidwrighton
Copy link
Member

  • The general approach is to wrap the method is a try/finally block
    • This is done by appending some IL to the method, and adding an EH clause
    • This required implementing a few abstraction boundaries so that the code/eh clauses could be rewritten within the interpreter
  • Synchronized methods also re-use the shadow this pointer logic
  • existing IL which is encoded as a RET needs to actually have the semantics of a LEAVE to to the actual return from the method
  • We also have a couple of "intrinsic" tokens which the our implementation of CALL now recognizes.

- The general approach is to wrap the method is a try/finally block
  - This is done by appending some IL to the method, and adding an EH clause
  - This required implementing a few abstraction boundaries so that the code/eh clauses could be rewritten within the interpreter
- Synchronized methods also re-use the shadow this pointer logic
- existing IL which is encoded as a RET needs to actually have the semantics of a LEAVE to to the actual return from the method
- We also have a couple of "intrinsic" tokens which the our implementation of CALL now recognizes.
@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 16:56
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 23, 2025
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 adds support for synchronized methods in the CLR interpreter by implementing a try/finally pattern to handle monitor enter/exit operations.

Key changes:

  • Wraps synchronized methods in try/finally blocks with additional IL opcodes for monitor operations
  • Implements shadow this pointer logic for synchronized instance methods
  • Converts RET instructions to LEAVE operations in synchronized methods to ensure proper cleanup

Reviewed Changes

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

Show a summary per file
File Description
src/coreclr/vm/interpexec.cpp Adds INTOP_CALL_HELPER_V_SA opcode handler and HELPER_FTN_V_PP typedef
src/coreclr/interpreter/intops.h Defines intrinsic tokens for synchronized method implementation
src/coreclr/interpreter/inc/intops.def Adds INTOP_CALL_HELPER_V_SA opcode definition
src/coreclr/interpreter/compiler.h Adds synchronized method state tracking variables and helper methods
src/coreclr/interpreter/compiler.cpp Implements synchronized method compilation logic, IL rewriting, and monitor operations

@davidwrighton davidwrighton added area-CodeGen-Interpreter-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 23, 2025
@kg
Copy link
Member

kg commented Sep 23, 2025

(Not a complaint about this implementation) Is there a reason we couldn't have the interpreter itself do the synchronization?

Copy link
Member

@kg kg left a comment

Choose a reason for hiding this comment

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

The complexity bothers me but I assume there's a good reason why it can't be simpler. Other than the comments I left it LGTM

@davidwrighton davidwrighton merged commit 12ca85b into dotnet:main Sep 24, 2025
96 of 98 checks passed
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.

3 participants