Skip to content

[Native] Restore indexed GC temporary peers - #12509

Merged
jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/fix-drop-libcxx-regression
Aug 25, 2026
Merged

[Native] Restore indexed GC temporary peers#12509
jonathanpeppers merged 3 commits into
mainfrom
dev/simonrozsival/fix-drop-libcxx-regression

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

Restore the allocation-backed TemporaryPeerMap removed while unifying GC bridge processing in #12133.

This preserves the unified concrete BridgeProcessing implementation and mono.android.IGCUserPeer path from #12133 while removing the accidentally reintroduced std::unordered_map<size_t, jobject> dependency from the NativeAOT host.

Part of #12139. This ports the temporary-peer storage previously merged in #12145 into the unified bridge rather than restoring the old bridge inheritance or legacy JavaInterop1 hooks.

Changes

  • replace the temporary-peer std::unordered_map with one exact-size calloc allocation;
  • encode temporary-peer indexes in empty SCC Count fields during the scoped cross-reference pass;
  • restore every marked SCC and release every JNI local reference through RAII before weak-reference processing;
  • retain local-reference capacity reservation and the Java-exception diagnostics added by [NativeAOT] Use XAJavaInterop1 codegen target and unify GC bridge #12133;
  • keep the unified IGCUserPeer method lookup and dispatch unchanged.

Validation

  • dotnet build src/native/native-nativeaot.csproj -c Release --no-restore --nologo -p:BuildProjectReferences=false
  • dotnet build src/native/native-clr.csproj -c Release --no-restore --nologo -p:BuildProjectReferences=false
  • confirmed the rebuilt arm64 NativeAOT static archive has no unresolved unordered_map, hash_table, or __next_prime symbols.

Restore the allocation-backed temporary peer map removed while unifying GC bridge processing. This keeps the unified IGCUserPeer path while avoiding std::unordered_map in NativeAOT.

Fixes the drop-libc++ regression introduced by #12133.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 25, 2026 09:34
@simonrozsival simonrozsival added Area: NativeAOT Issues that only occur when using NativeAOT. drop-libcpp Work to remove the libc++ dependency from Android NativeAOT labels Aug 25, 2026

Copilot AI left a comment

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.

Pull request overview

This PR restores indexed temporary-peer storage in the unified GC bridge processing code by replacing the previous std::unordered_map<size_t, jobject> temporary-peer tracking with a fixed-size calloc-allocated jobject array and SCC Count field index-encoding, ensuring temporary peers and marker restoration are handled via RAII before weak-reference processing.

Changes:

  • Introduces TemporaryPeerMap to allocate exact-size temporary peer storage and encode indexes into SCC Count using a marker bit.
  • Refactors bridge preparation to scope temporary-peer lifetime to cross-reference processing and automatically clean up local refs + SCC markers.
  • Removes the std::unordered_map dependency from BridgeProcessing to avoid pulling in unwanted C++ standard library roots.
Show a summary per file
File Description
src/native/clr/include/host/bridge-processing.hh Adds TemporaryPeerMap API and updates bridge helper method signatures to use it instead of std::unordered_map.
src/native/clr/host/bridge-processing.cc Implements TemporaryPeerMap with calloc storage + SCC count marker encoding, and refactors bridge preparation to use RAII cleanup.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/native/clr/host/bridge-processing.cc Outdated
simonrozsival and others added 2 commits August 25, 2026 11:54
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 25, 2026
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12509

@github-actions github-actions Bot left a comment

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.

✅ LGTM

No blocking issues found. Findings: 0 errors, 0 warnings, 1 suggestion.

The scoped allocation preserves the prior bridge behavior while removing the std::unordered_map dependency, and the RAII cleanup restores SCC counts before weak-reference processing. All 44 reported checks are green. The inline suggestion requests focused regression coverage for the temporary marker invariant.

Generated by Android PR Reviewer for #12509 · gpt56 · 102 AIC · ⌖ 9.06 AIC · ⊞ 25.7K
Comment /review to run again

// Count is unsigned, so encode the temporary peer index as ~index. This stores the same bit
// pattern as -(index + 1), giving us a sign bit marker while preserving index 0.
// The destructor resets every marker before returning cross_refs to the runtime.
static constexpr size_t temporary_peer_index_sign_bit = ~(~size_t { 0 } >> 1);

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.

🤖 💡 Testing — This introduces a non-trivial invariant that temporarily overwrites every empty SCC count and relies on scoped cleanup to restore it, but the PR only validates native builds and symbol removal. Please consider focused coverage for index 0, multiple empty SCCs, preservation of non-empty counts, and restoration after the map leaves scope so a future refactor cannot silently corrupt the runtime-owned argument block.

Rule: Native runtime behavior requires focused regression coverage

@jonathanpeppers
jonathanpeppers merged commit fb3319b into main Aug 25, 2026
44 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/fix-drop-libcxx-regression branch August 25, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: NativeAOT Issues that only occur when using NativeAOT. drop-libcpp Work to remove the libc++ dependency from Android NativeAOT ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants