Skip to content

Followon changes from code review comments in the Monitor HMF removal change #113857

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

Conversation

davidwrighton
Copy link
Member

I missed a set of review feedback from @AaronRobinsonMSFT, this should address that feedback. As it changes the hot paths, I'm going to have to run perf measurements to make sure it doesn't negatively impact perf.

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 24, 2025
@davidwrighton
Copy link
Member Author

@EgorBot -amd -arm -windows_intel

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

public class Tests
{
    private object _lockObj = new object();
    private int _field = 0;

    [Benchmark(Baseline = true)]
    public void Lock_OnLockObj()
    {
        _field++;
        lock(_lockObj)
        {
            _field++;
        }
    }

    [Benchmark]
    public void LockOnThis_ThisKnownToBeNonNull()
    {
        _field++;
        lock(this)
        {
            _field++;
        }
    }

    [Benchmark]
    public void LockOnThis()
    {
        lock(this)
        {
            _field++;
        }
    }
}

@davidwrighton
Copy link
Member Author

/ba-g known failures

@davidwrighton davidwrighton marked this pull request as ready for review March 31, 2025 21:30
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 addresses missed feedback on the Monitor HMF removal change, including adjustments on the fast path/slow path handling and parameter validations.

  • Removed an unnecessary semicolon in the enum definition.
  • Added parameter validation in the TryEnter_Slowpath method.
  • Revised control flow in ExitIfLockTaken to call Exit_Slowpath conditionally.
Files not reviewed (1)
  • src/coreclr/classlibnative/bcltype/objectnative.cpp: Language not supported
Comments suppressed due to low confidence (2)

src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs:95

  • Consider providing a more descriptive message or parameter name instead of null to improve diagnostic clarity in the exception thrown.
ArgumentOutOfRangeException.ThrowIfLessThan(timeout, -1, null);

src/coreclr/System.Private.CoreLib/src/System/Threading/Monitor.CoreCLR.cs:175

  • Double-check the revised condition logic in ExitIfLockTaken to ensure that Exit_Slowpath is invoked only when intended, as reversing the conditional check may inadvertently alter the expected control flow.
if (exitBehavior != LeaveHelperAction.None)

@davidwrighton davidwrighton merged commit 4ec72ec into dotnet:main Mar 31, 2025
94 of 96 checks passed
thaystg pushed a commit to thaystg/runtime that referenced this pull request Apr 1, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants