Skip to content

Implement GC bridge VM support in NativeAOT #117738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 25, 2025

Conversation

jkoritzinsky
Copy link
Member

Port over the CoreCLR VM implementation to NativeAOT.

Copy link
Contributor

@Copilot 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

Port CoreCLR’s Java GC bridge support into the NativeAOT runtime and enable related tests and build logic across both runtimes.

  • Remove the NativeAotIncompatible flag from the GC bridge test project to allow NativeAOT runs.
  • Add managed QCall stubs and NativeAOT implementations in JavaMarshal.NativeAot.cs, RuntimeImports.cs, and associated interop code.
  • Update CMakeLists and project files to conditionally include JavaMarshal/CoreCLR and NativeAOT sources under FEATURE_JAVAMARSHAL.

Reviewed Changes

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

Show a summary per file
File Description
src/tests/Interop/GCBridge/BridgeTest.csproj Remove <NativeAotIncompatible> so tests can run under NativeAOT
src/libraries/System.Private.CoreLib/.../JavaMarshal.Unsupported.cs Add unsupported-platform stubs throwing PlatformNotSupportedException
src/libraries/System.Private.CoreLib/...Shared.projitems Conditionally include JavaMarshal.cs when FeatureJavaMarshal is false
src/coreclr/vm/interoplibinterface_java.cpp Switch from free to delete[]/delete for GC bridge arguments
src/coreclr/nativeaot/System.Private.CoreLib/...RuntimeImports.cs Introduce new RuntimeImport QCalls for cross-reference handle APIs
src/coreclr/nativeaot/System.Private.CoreLib/...JavaMarshal.NativeAot.cs Implement JavaMarshal methods for NativeAOT with argument checks and QCalls
src/coreclr/nativeaot/System.Private.CoreLib/...GCHandle.NativeAot.cs Hook GCHandle into the GC bridge wait logic via JavaMarshal
src/coreclr/nativeaot/System.Private.CoreLib/...System.Private.CoreLib.csproj Include JavaMarshal.NativeAot.cs only when FeatureJavaMarshal is true
src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp Full NativeAOT GC bridge implementation and event coordination
src/coreclr/nativeaot/Runtime/interoplibinterface.h Declare JavaMarshalNative::TriggerClientBridgeProcessing under FEATURE_JAVAMARSHAL
src/coreclr/nativeaot/Runtime/gcenv.ee.cpp Forward GCToEEInterface::TriggerClientBridgeProcessing to the new NativeAOT code
src/coreclr/nativeaot/Runtime/HandleTableHelpers.cpp Implement RhpHandleAllocCrossReference and context lookup in the handle table
src/coreclr/nativeaot/Runtime/CMakeLists.txt Add interoplibinterface_java.cpp and gcbridge.cpp to nativeaot sources
src/coreclr/nativeaot/CMakeLists.txt Define and propagate the FEATURE_JAVAMARSHAL compile flag
src/coreclr/System.Private.CoreLib/...JavaMarshal.CoreCLR.cs Remove old NATIVEAOT/FEATURE_JAVAMARSHAL #if blocks to unify implementation
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj Conditionally include JavaMarshal.CoreCLR.cs based on FeatureJavaMarshal
Comments suppressed due to low confidence (2)

src/tests/Interop/GCBridge/BridgeTest.csproj:6

  • [nitpick] You’ve enabled the test project for NativeAOT by removing the incompatibility flag—please add or update tests in BridgeTest to cover the new JavaMarshal GC bridge behavior under NativeAOT.
    <GCStressIncompatible>true</GCStressIncompatible>

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.NativeAot.cs:19

  • [nitpick] InternalGetBridgeWait calls JavaMarshal.WaitForGCBridgeFinish without any SupportedOSPlatform annotation. Consider adding [SupportedOSPlatform("android")] (or another appropriate attribute) to this method rather than suppressing CA1416, so platform compatibility requirements are explicit.
        internal static object? InternalGetBridgeWait(IntPtr handle)

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) July 22, 2025 21:31
@jkoritzinsky jkoritzinsky disabled auto-merge July 22, 2025 23:00
@jkoritzinsky jkoritzinsky enabled auto-merge (squash) July 22, 2025 23:25
@filipnavara
Copy link
Member

The build failures are all either known issues or timeouts. Can we get this merged?

I'd like to test it but it would be significantly easier to do so once it flows through the arcade so I only need to rebuild the Android workload and not the whole stack.

@jkoritzinsky
Copy link
Member Author

/ba-g wasm timeouts

@filipnavara
Copy link
Member

🙏🏿

@jkoritzinsky jkoritzinsky merged commit 1e7433e into dotnet:main Jul 25, 2025
146 of 157 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants