Repository navigation
Closed
Closed
Copy link
Labels
area-System.Runtime.InteropServicesenhancementProduct code improvement that does NOT require public API changes/additions
Milestone
Description
Background
ObjectiveCMarshal currently has two distinct implementations:
- CoreCLR (
src/coreclr/vm/interoplibinterface_objc.cpp+src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs) — stores tagged memory on the object's InteropSyncBlockInfo (seeEnsureTaggedMemoryAllocatedinsyncblk.h) and reaches it from the GC via native code. - NativeAOT (
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs) — stores tagged memory in a managedConditionalWeakTable<object, ObjcTrackingInformation>and exposes it to the GC via RuntimeExports such asObjectiveCMarshalTryGetTaggedMemory.
Historically we could not unify on the NAOT design for CoreCLR because there was no way for native GC callbacks to look up an entry in a managed ConditionalWeakTable.
Proposal
In PR #113907 we introduced an unmanaged ConditionalWeakTable accessor used by the shared ComWrappers implementation, which removes the original blocker. We should follow up by switching CoreCLR's ObjectiveCMarshal to share the NAOT implementation, mirroring the model used for ComWrappers.
This would:
- Eliminate the duplicated CoreCLR-only tagged-memory path in
interoplibinterface_objc.cppand theInteropSyncBlockInfostorage used only by Objective-C interop. - Make the new
ObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI (added in AddObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508) trivially shared between both runtimes instead of needing parallel implementations. - Allow the cDAC
IObjectiveCMarshalcontract to be reworked on top of the sharedConditionalWeakTable, consistent with how DAC was reimplemented forComWrappers.
Context
- Suggestion: Add
ObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508 (comment) - Prior art: Share implementation of ComWrappers between CoreCLR and NativeAOT #113907 ("Share implementation of ComWrappers between CoreCLR and NativeAOT")
- Related API: [API Proposal]: Add API for getting memory for Objective-C object without creating
GCHandle#128476 / AddObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508 (GetOrCreateReferenceTrackingMemory)
Reacted by Copilot
Metadata
Metadata
Assignees
Labels
area-System.Runtime.InteropServicesenhancementProduct code improvement that does NOT require public API changes/additions
Type
Projects
- StatusShow more project fieldsNo status
Activity
AaronRobinsonMSFT commentedon Jun 3, 2026
/cc @jkotas
dotnet-policy-service commentedon Jun 3, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jun 3, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.