Share ObjectiveCMarshal reference-tracking logic between CoreCLR and NativeAOT#128961
Merged
Conversation
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
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
rcj1
reviewed
Jun 3, 2026
noahfalk
reviewed
Jun 4, 2026
Member
|
@copilot Please fold the cDAC changes into version 1. There is no backwards compat concerns here. We can change version 1 without issue. |
Contributor
Author
Addressed in 0edf747. I folded the ObjectiveCMarshal cDAC changes into version c1, removed the c2 registration/implementation, and updated the CoreCLR data descriptor contract entry back to c1. |
Copilot
AI
changed the title
Share ObjectiveCMarshal reference-tracking storage between CoreCLR and NativeAOT
Share ObjectiveCMarshal reference-tracking storage between CoreCLR and NativeAOT (cDAC contract stays at v1)
Jun 4, 2026
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
- Use sizeof(TADDR) instead of sizeof(void*) in DAC for target size - Mark s_objects as readonly; use local copy for ObjectHandleOnStack - Guard gcinterface.dac.h include with DACCESS_COMPILE Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jkotas
reviewed
Jun 8, 2026
Add tests exercising the ConditionalWeakTable-based GetTaggedMemory path: - ObjectNotInTable: CWT exists but object not tracked - NullMemory: object tracked but memory pointer is null - HasMemory: object tracked with valid tagged memory Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…bjC stubs - Use m_Array directly instead of GetGCSafeDataPtr() per review feedback - Update Mono ObjectiveCMarshal stubs to match shared API changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jkotas
approved these changes
Jun 9, 2026
…al methods Extract the unsafe MethodTable check into a partial method on each runtime (CoreCLR, NativeAOT, Mono stub) so the shared ObjectiveCMarshal.cs no longer requires an unsafe context for the validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AaronRobinsonMSFT
approved these changes
Jun 9, 2026
tommcdon
added a commit
that referenced
this pull request
Jun 12, 2026
In DAC mode, m_Array yields a host address, but PTR_KIND requires a target address. GetDataPtr() computes the correct target address via dac_cast<PTR_BYTE>(this) + offset. This was broken by PR #128961 which changed from GetDataPtr() to m_Array, breaking debugger inspection of exception stack traces, ConditionalWeakTable lookups, and stack frame helper arrays in DAC mode. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
leculver
added a commit
that referenced
this pull request
Jun 16, 2026
Fixes failing OSX cDac test. I think this is a regression from #128961. This pull request updates the handling of pointer types in managed code to better align with how .NET expresses raw pointers. The main change is to allow fields typed as `IntPtr`/`UIntPtr` (reported as `"nint"`/`"nuint"`) to be treated as pointers by the contract reader, improving compatibility and correctness when reading pointer-sized fields. Improvements to pointer type handling: * Updated `AssertPointerType` in `TargetFieldExtensions.cs` to accept `"nint"` and `"nuint"` as valid pointer type names, in addition to `"pointer"`, enabling proper handling of managed fields typed as `IntPtr`/`UIntPtr`. Test and contract descriptor alignment: * Modified the test contract for the `_memory` field in `ObjectiveCMarshalTests.cs` to explicitly set its type as `"nint"`, ensuring that the pointer read path is validated against the real managed contract descriptor. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ObjectiveCMarshalhad divergent CoreCLR and NativeAOT implementations for tagged reference-tracking memory. This change moves CoreCLR to the sameConditionalWeakTable<object, ObjcTrackingInformation>model used by NativeAOT and updates diagnostics contracts accordingly.s_objectsCWT andObjcTrackingInformationlifecycle logic inObjectiveCMarshal.CoreCLR.cs.CreateReferenceTrackingHandle/GetOrCreateReferenceTrackingMemoryflow to use managed CWT-backed memory for both runtimes.Initializenow passes the CWT instance to native for unmanaged lookup during GC callbacks.interoplibinterface_objc.cpp.ConditionalWeakTableObject::TryGetValue) to resolve tagged memory from managed state.ObjCMarshal_AllocateReferenceTrackingHandle).ConditionalWeakTablenative lookup helpers for this suspended-runtime callback scenario and clarified constraints in comments.c1ObjectiveCMarshal_1implementation to read tagged memory viaObjectiveCMarshal.s_objectsand CWT entries.