Skip to content

[Foundation] Go back to the old implementation of NSObject.GetSuper ().#25405

Closed
rolfbjarne wants to merge 6 commits into
mainfrom
dev/rolf/super-back-old-impl
Closed

[Foundation] Go back to the old implementation of NSObject.GetSuper ().#25405
rolfbjarne wants to merge 6 commits into
mainfrom
dev/rolf/super-back-old-impl

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne commented May 12, 2026

TODO:


Use the old implementation of NSObject.GetSuper ():

  • Allocate native memory for it.
  • Cache that native memory in an NSObject field.
  • Free it when the NSObject is disposed.

This is less performant, but any performance issues will be alleviated by the fact that NSObject.GetSuper () will be called much less after #25376.

The great advantage is that NSObjectData is now smaller, and fits in the tagged memory returned by ObjectiveCMarshal.CreateReferenceTrackingHandle, which will simplify memory management a lot for CoreCLR.

Contributes towards #25383.

Use the old implementation of NSObject.GetSuper ():

* Allocate native memory for it.
* Cache that native memory in an NSObject field.
* Free it when the NSObject is disposed.

This is less performant, but any performance issues will be alleviated by
the fact that NSObject.GetSuper () will be called much less after #25376.

The great advantage is that NSObjectData is now smaller, and fits in the
tagged memory returned by `ObjectiveCMarshal.CreateReferenceTrackingHandle`,
which will simplify memory management a lot for CoreCLR.

Contributes towards #25383.
Copilot AI review requested due to automatic review settings May 12, 2026 17:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reverts NSObject.GetSuper () to an allocation-based approach to reduce the size of NSObjectData, so it can fit within the tagged memory returned by ObjectiveCMarshal.CreateReferenceTrackingHandle (simplifying CoreCLR memory management).

Changes:

  • Shrinks the native/managed NSObjectData layout by removing the embedded objc_super pointer.
  • Reintroduces per-NSObject native allocation/caching of objc_super used for objc_msgSendSuper calls.
  • Updates the dynamic registrar and native runtime struct comments/signatures to match the new NSObjectData layout.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/ObjCRuntime/Registrar.cs Updates the Objective-C type encoding for xamarinGetNSObjectData to reflect the smaller NSObjectData.
src/Foundation/NSObject2.cs Removes classHandle from NSObjectData and restores an allocation-based GetSuper () implementation (with an optional CWT-backed variant).
runtime/xamarin/runtime.h Updates the native NSObjectData struct definition and associated signature comment to match managed changes.

Comment thread src/Foundation/NSObject2.cs Outdated
Comment thread src/Foundation/NSObject2.cs
Comment thread src/Foundation/NSObject2.cs
Comment thread src/Foundation/NSObject2.cs Outdated
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

1 similar comment
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 4 commits May 13, 2026 10:22
* Fix stale Handle in the CWT path: move Handle/ClassHandle assignment
  outside the GetValue factory so they're updated on every GetSuper call.
* Remove stale comment about objc_super being in NSObjectData.
* Remove extra blank line after #endif.
* Use full URL for issue reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Reword the USE_CWT_FOR_SUPER_MEMORY comment to clarify intent.
* The FreeData/Dispose pattern matches the old release/8.0.1xx behavior
  (FreeData only called when handle is zero), so no change needed there.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rolfbjarne
Copy link
Copy Markdown
Member Author

Re: Dispose/FreeData behavior — I verified against the release/8.0.1xx branch. The old code has the exact same pattern: FreeData() is only called in the else branch when handle == IntPtr.Zero. The current code matches the old implementation.

The copilot reviewer's concern about ReleaseManagedRef() clearing the handle and causing a leak is not new — the old code had the same pattern and worked well for many years.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #2278dac] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 2278dac992ab055cba64cafe9c8e44308e99bf41 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #2278dac] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 2278dac992ab055cba64cafe9c8e44308e99bf41 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 2278dac992ab055cba64cafe9c8e44308e99bf41 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #2278dac] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 2278dac992ab055cba64cafe9c8e44308e99bf41 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🔥 [CI Build #2278dac] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

1 tests crashed, 0 tests failed, 172 tests passed.

Failures

❌ windows tests

🔥 Failed catastrophically on VSTS: test results - windows (no summary found).

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 16 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 16 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 2278dac992ab055cba64cafe9c8e44308e99bf41 [PR build]

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants