[Native] Restore indexed GC temporary peers - #12509
Conversation
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>
There was a problem hiding this comment.
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
TemporaryPeerMapto allocate exact-size temporary peer storage and encode indexes into SCCCountusing 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_mapdependency fromBridgeProcessingto 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
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ 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); |
There was a problem hiding this comment.
🤖 💡 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
Summary
Restore the allocation-backed
TemporaryPeerMapremoved while unifying GC bridge processing in #12133.This preserves the unified concrete
BridgeProcessingimplementation andmono.android.IGCUserPeerpath from #12133 while removing the accidentally reintroducedstd::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
std::unordered_mapwith one exact-sizecallocallocation;Countfields during the scoped cross-reference pass;IGCUserPeermethod lookup and dispatch unchanged.Validation
dotnet build src/native/native-nativeaot.csproj -c Release --no-restore --nologo -p:BuildProjectReferences=falsedotnet build src/native/native-clr.csproj -c Release --no-restore --nologo -p:BuildProjectReferences=falseunordered_map,hash_table, or__next_primesymbols.