-
Notifications
You must be signed in to change notification settings - Fork 5k
[NativeAOT] Objective-C Marshal: object tracker support #78280
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
Conversation
It would likely be possible to limit the overhead only to types that are marked with the |
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 added some comments on things I'm not sure about.
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Show resolved
Hide resolved
I updated the PR to change the way callbacks work. There are a couple of outstanding items (listed in the PR description) that I need to address before this can be merged. |
I addressed known issues with this PR (making it compatible with multiple class libs). This PR is now ready for further review. |
e0ece75
to
2abfe8d
Compare
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.
The compiler side looks good to me, the CoreLib interaction too, but I can't speak to the GC interaction details or objc interop in general. Cc @VSadov as well
src/coreclr/tools/Common/Internal/Runtime/EETypeBuilderHelpers.cs
Outdated
Show resolved
Hide resolved
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsWith these changes the The native part ( interoplibinterface.h and interoplibinterface_objc.cpp ) are based off the corresponding files from CoreCLR. Potentially parts could be shared between both runtimes, but it's not a lot of code. Compared CoreCLR version, every Objective-C object takes 3x the GC handles. In addition the ref-counted GC handle, there is a dependent handle in the conditional weak table and a long weak handle to extend the lifetime Related issue: #77472
|
FYI @rolfbjarne |
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.
Does the NativeAOT GC run collections on multiple threads (like the server GC), or only on a single thread (like the workstation GC)?
According to this comment from the Xamarin repository, the Server GC is not supported: https://github.com/xamarin/xamarin-macios/blob/main/runtime/coreclr-bridge.m#L203-L210 |
Native AOT respects the same build configuration settings as standard CoreCLR. It uses workstation GC by default and server GC can be enabled by setting
What happens if somebody enables server GC in a project that uses Xamarin interop? Does it just crash silently, or does it produce descriptive error somewhere? |
That's exactly why I'm asking 😄
I intended to make it an error, but it seems I never did that. I've filed an issue so I don't forget again: dotnet/macios#16853 |
0965547
to
d764a05
Compare
This reverts commit 2abfe8d394b899810e955d79af0b9303f82c448d.
Specifically: * Remove support for registering multiple begin/end callbacks, since the API was not designed with multiple managed worlds in mind. * Use more asserts where it should not be possible for there to be no callback. * Add more comments. * Add missing GC-trigger disable when calling managed callouts.
d764a05
to
6a06e1b
Compare
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Show resolved
Hide resolved
* Add comments to CoreCLR and NativeAOT about constants that should have the same size. * Remove superfluous use of C++ templates. * Use the C# unmanaged function pointer types in more places, improving type safety
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.
From the interop side of things, I am fine with this. I'd like to make sure @MichalStrehovsky is okay from the NativeAOT side and @rolfbjarne is aware and okay with support from the Xamarin side.
Thanks!
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Show resolved
Hide resolved
Co-authored-by: Aaron Robinson <[email protected]>
This reverts commit 7cbf935.
@AaronRobinsonMSFT Regarding your suggestions to change the type parameters on the unmanned function pointers from
So I'm going to stick to using |
Ah. Okay. I missed that. We try to use |
...aot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
Outdated
Show resolved
Hide resolved
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.
Compiler side still looks good. I can't judge GC interactions or objc semantics - not reviewing that.
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.
LGTM
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!
With these changes the
src/tests/Interop/ObjectiveC/ObjectiveCMarshalAPI/
test passes everything except_Validate_ExceptionPropagation
.The native part ( interoplibinterface.h and interoplibinterface_objc.cpp ) are based off the corresponding files from CoreCLR. Potentially parts could be shared between both runtimes, but it's not a lot of code.
Compared CoreCLR version, every Objective-C object takes 3x the GC handles. In addition the ref-counted GC handle, there is a dependent handle in the conditional weak table and a long weak handle to extend the lifetime
ObjcTrackingInformation
. If that is not acceptable, the tracking information could be moved into the SyncBlock like CoreCLR does. With the current implementation of NativeAOT sync blocks, that would reduce handle overhead to 2x that of CoreCLR, at the cost of making every macOS sync block bigger.Related issue: #77472