Skip to content

Share ObjectiveCMarshal API implementation between CoreCLR and NativeAOT #128925

@AaronRobinsonMSFT

Description

@AaronRobinsonMSFT

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 (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.
  • Make the new ObjectiveCMarshal.GetOrCreateReferenceTrackingMemory API (added in Add ObjectiveCMarshal.GetOrCreateReferenceTrackingMemory API #128508) trivially shared between both runtimes instead of needing parallel implementations.
  • Allow the cDAC IObjectiveCMarshal contract to be reworked on top of the shared ConditionalWeakTable, consistent with how DAC was reimplemented for ComWrappers.

Context

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status
No status

Relationships

None yet

Development

No branches or pull requests

Issue actions