-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Move ComWrappers AddRef to C/C++ #110762
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
Move ComWrappers AddRef to C/C++ #110762
Conversation
Xaml invokes AddRef while holding a lock that it *also* holds while a GC is in progress. Managed AddRef had to synchronize with the GC that caused intermittent deadlocks with the other thread holding Xaml's lock. This change reverts the managed AddRef implementation to match .NET Native and CoreCLR. Fixes dotnet#110747
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Sergio0694
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!! 😄
Tested with the Microsoft Store and could not repro any hangs:
- Checked out
release/9.0-staging(51fd1e2) - Cherry-pick commits from #110558
- Cherry-pick commits from this PR
- Build with
.\build.cmd clr.aot -c Release - Set
IlcSdkPathin the Store .csproj toruntime\artifacts\bin\coreclr\windows.x64.Release\aotsdk\ - Set
GenerateAppxPackageOnBuild - Switch to Release
- Deploy
I then tried to use the Store for a while, and also did the same thing that triggered the hang last time (opening and closing it in quick succession a couple dozen times). I could not repro the issue and everything seemed to be working great 🎉
| #if false // Implemented in C/C++ to avoid GC transitions | ||
| [UnmanagedCallersOnly] | ||
| internal static unsafe uint IUnknown_AddRef(IntPtr pThis) | ||
| { | ||
| ManagedObjectWrapper* wrapper = ComInterfaceDispatch.ToManagedObjectWrapper((ComInterfaceDispatch*)pThis); | ||
| return wrapper->AddRef(); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the #if false pattern. I'd rather we just include a comment on line 1160 explaining that we have it implemented in C/C++ to avoid GC transitions.
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @jkoritzinsky's comment about the #if false style. Other than that, LGTM.
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
...nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.NativeAot.cs
Outdated
Show resolved
Hide resolved
…e/InteropServices/ComWrappers.NativeAot.cs
|
/backport to release/9.0-staging |
|
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12396026201 |
* Move ComWrappers AddRef to C/C++ Xaml invokes AddRef while holding a lock that it *also* holds while a GC is in progress. Managed AddRef had to synchronize with the GC that caused intermittent deadlocks with the other thread holding Xaml's lock. This change reverts the managed AddRef implementation to match .NET Native and CoreCLR. Fixes dotnet#110747 Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Xaml invokes AddRef while holding a lock that it also holds while a GC is in progress. Managed AddRef had to synchronize with the GC that caused intermittent deadlocks with the other thread holding Xaml's lock.
This change reverts the managed AddRef implementation to match .NET Native and CoreCLR.
Fixes #110747