You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 (see EnsureTaggedMemoryAllocated in syncblk.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 managed ConditionalWeakTable<object, ObjcTrackingInformation> and exposes it to the GC via RuntimeExports such as ObjectiveCMarshalTryGetTaggedMemory.
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.cpp and the InteropSyncBlockInfo storage used only by Objective-C interop.
Allow the cDAC IObjectiveCMarshal contract to be reworked on top of the shared ConditionalWeakTable, consistent with how DAC was reimplemented for ComWrappers.
Background
ObjectiveCMarshalcurrently has two distinct implementations: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.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
ConditionalWeakTableaccessor used by the sharedComWrappersimplementation, which removes the original blocker. We should follow up by switching CoreCLR'sObjectiveCMarshalto share the NAOT implementation, mirroring the model used forComWrappers.This would:
interoplibinterface_objc.cppand theInteropSyncBlockInfostorage used only by Objective-C interop.ObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI (added in AddObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508) trivially shared between both runtimes instead of needing parallel implementations.IObjectiveCMarshalcontract to be reworked on top of the sharedConditionalWeakTable, consistent with how DAC was reimplemented forComWrappers.Context
ObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508 (comment)GCHandle#128476 / AddObjectiveCMarshal.GetOrCreateReferenceTrackingMemoryAPI #128508 (GetOrCreateReferenceTrackingMemory)