Skip to content

Convert throw and thread helpers to UCO#126582

Open
am11 wants to merge 2 commits intodotnet:mainfrom
am11:feature/MDCS-to-UCOA-pattern2
Open

Convert throw and thread helpers to UCO#126582
am11 wants to merge 2 commits intodotnet:mainfrom
am11:feature/MDCS-to-UCOA-pattern2

Conversation

@am11
Copy link
Copy Markdown
Member

@am11 am11 commented Apr 6, 2026

Contributes to prio3 from #123864

@am11 am11 requested a review from MichalStrehovsky as a code owner April 6, 2026 17:39
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 6, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@am11 am11 changed the title Convert throw and thread helpers and to UCO Convert throw and thread helpers to UCO Apr 6, 2026
@am11 am11 force-pushed the feature/MDCS-to-UCOA-pattern2 branch from 227f207 to df453ad Compare April 6, 2026 17:50
@am11
Copy link
Copy Markdown
Member Author

am11 commented Apr 6, 2026

@EgorBot -osx_arm64

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

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

[MemoryDiagnoser]
[SimpleJob(warmupCount: 3, iterationCount: 10)]
public class ExceptionBench
{
    private static volatile int _sink;

    [Benchmark]
    public void ThrowCatch()
    {
        try
        {
            Thrower();
        }
        catch (InvalidOperationException ex)
        {
            _sink = ex.HResult;
        }
    }

    private static void Thrower()
    {
        throw new InvalidOperationException("boom");
    }

    [Benchmark]
    public void NullRefThrow()
    {
        try
        {
            object o = null!;
            _ = o.ToString(); // NullRef
        }
        catch
        {
        }
    }

    [Benchmark]
    public void Rethrow()
    {
        try
        {
            try
            {
                Thrower();
            }
            catch
            {
                throw;
            }
        }
        catch
        {
        }
    }
}

return default;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would split Start and Finalizer into a separate PR to make this easier to land.


uint32_t count;
CALL_MANAGED_METHOD(count, uint32_t, args);
UnmanagedCallersOnlyCaller runFinalizers(METHOD__GC__RUN_FINALIZERS);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This one and Thread.Start have concerns about unhandled exception post-mortem diagnostics, similar to the concerns we had with Main method. We need to make sure that the unhandled exceptions produce crash dump with the original stack preserved for good post-mortem diagnostics, on both Windows and Unix. It does not seem to be the case by just looking at the code.

(Unlike the Main method, we do not need to hide the extra frames from stacktraces in these cases.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated accordingly (without conditioning stacktrace). I am waiting for the CI run to understand if we need to further fine-tune it.

object exceptionObj = *pExceptionObj;
RhThrowEx(exceptionObj, ref *pExInfo);
}
catch (Exception ex)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These changes in the ExceptionHandling.cs are not needed. Managed exception is never propagated out of the RhThrowEx et al.

@am11 am11 force-pushed the feature/MDCS-to-UCOA-pattern2 branch from 2d3d910 to ff25723 Compare April 7, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants