Skip to content

Share ObjectiveCMarshal reference-tracking storage between CoreCLR and NativeAOT#128961

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/share-objectivecmarshal-api
Draft

Share ObjectiveCMarshal reference-tracking storage between CoreCLR and NativeAOT#128961
Copilot wants to merge 3 commits into
mainfrom
copilot/share-objectivecmarshal-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

ObjectiveCMarshal had divergent CoreCLR and NativeAOT implementations for tagged reference-tracking memory. This change moves CoreCLR to the same ConditionalWeakTable<object, ObjcTrackingInformation> model used by NativeAOT and updates diagnostics contracts accordingly.

  • Description
    • CoreCLR managed ObjectiveCMarshal now owns tagged memory
      • Added CoreCLR-side s_objects CWT and ObjcTrackingInformation lifecycle logic in ObjectiveCMarshal.CoreCLR.cs.
      • Unified CreateReferenceTrackingHandle / GetOrCreateReferenceTrackingMemory flow to use managed CWT-backed memory for both runtimes.
      • Initialize now passes the CWT instance to native for unmanaged lookup during GC callbacks.
    • CoreCLR native Objective-C interop path no longer uses syncblk tagged storage
      • Removed Objective-C-specific syncblk tagged-memory allocation/retrieval path from interoplibinterface_objc.cpp.
      • Replaced with unmanaged CWT lookup (ConditionalWeakTableObject::TryGetValue) to resolve tagged memory from managed state.
      • Split QCall responsibilities so native only allocates the ref-counted handle (ObjCMarshal_AllocateReferenceTrackingHandle).
    • Unmanaged CWT accessor usage enabled in runtime path
      • Exposed ConditionalWeakTable native lookup helpers for this suspended-runtime callback scenario and clarified constraints in comments.
    • cDAC ObjectiveCMarshal contract moved to shared model
      • Added ObjectiveCMarshal contract c2 that reads tagged memory via ObjectiveCMarshal.s_objects and CWT entries.
      • Registered c2 in CoreCLR contract registry and updated descriptor contract version.
      • Added new data mappings for ObjectiveCMarshal static table and ObjcTrackingInformation._memory.
// CoreCLR native callback path now resolves tagged memory from managed CWT state.
CONDITIONAL_WEAK_TABLE_REF trackingTable = (CONDITIONAL_WEAK_TABLE_REF)ObjectFromHandle(g_ObjectiveCTrackingInfoTable);
OBJECTREF trackingInfoObj = NULL;
if (!trackingTable->TryGetValue(object, &trackingInfoObj))
    return false;

OBJC_TRACKING_INFO_REF trackingInfo = (OBJC_TRACKING_INFO_REF)trackingInfoObj;
void* taggedLocal = (void*)trackingInfo->_memory;

Copilot AI self-assigned this Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 20:13
Copilot AI review requested due to automatic review settings June 3, 2026 20:13
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 3, 2026 20:38
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 3, 2026 20:44
Copilot AI changed the title [WIP] Share ObjectiveCMarshal API implementation between CoreCLR and NativeAOT Share ObjectiveCMarshal reference-tracking storage between CoreCLR and NativeAOT Jun 3, 2026
Copilot AI requested a review from AaronRobinsonMSFT June 3, 2026 20:45
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

registry.Register<ISignature>("c1", static t => new Signature_1(t));
registry.Register<IBuiltInCOM>("c1", static t => new BuiltInCOM_1(t));
registry.Register<IObjectiveCMarshal>("c1", static t => new ObjectiveCMarshal_1(t));
registry.Register<IObjectiveCMarshal>("c2", static t => new ObjectiveCMarshal_2(t));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren’t revving the versions yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My assumption here is the current cDAC works on .NET 10 for Objective-C. This is a break change so I assume we need to ensure .NET 10 continues to work.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not support .NET 10 with cDAC. We are making changes to the runtime throughout .NET 11 to support cDAC, for example #125243.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any individual API or contract may just happen to work, but that is not a guarantee or promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Share ObjectiveCMarshal API implementation between CoreCLR and NativeAOT

3 participants