Skip to content

[CoreCLR] Implement GC bridge #10198

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 36 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5e92071
Implement GC bridge for CoreCLR
simonrozsival Jun 13, 2025
4e7c284
Address review
simonrozsival Jun 16, 2025
1205f46
Split GCBridge into two classes
simonrozsival Jun 17, 2025
369dd18
Refactor HandleContext and ReferenceTrackingHandle
simonrozsival Jun 17, 2025
960945d
Update GC Bridge API to respect changes to cross_refs lifetime changes
simonrozsival Jun 18, 2025
212c1cc
Remove unnecessary util methods
simonrozsival Jun 18, 2025
72ba81b
Move logging to separate methods to reduce noise
simonrozsival Jun 18, 2025
c798a7f
Reduce nesting in gc-bridge.cc
simonrozsival Jun 18, 2025
333b131
Reduce nesting and other code cleanups
simonrozsival Jun 18, 2025
be2ed77
Address feedback
simonrozsival Jun 18, 2025
f54d580
Thanks copilot
simonrozsival Jun 18, 2025
4adf4cc
Merge branch 'main' into dev/srozsival/gcbridge-clr
simonrozsival Jun 19, 2025
74f843d
Fix deadlocks
simonrozsival Jun 19, 2025
058d6b2
Cleanup
simonrozsival Jun 19, 2025
59da00b
Apply suggestions from code review
simonrozsival Jun 23, 2025
bd99453
Address feedback
simonrozsival Jun 23, 2025
76041d1
Fix bug when adding circular references
simonrozsival Jul 3, 2025
45d2460
Adjust code formatting
simonrozsival Jul 4, 2025
a95e247
Add validation of context pointers before we start iterating on them …
simonrozsival Jul 4, 2025
233bcad
Improve code readability
simonrozsival Jul 4, 2025
7d95454
Merge branch 'main' into dev/srozsival/gcbridge-clr
jonathanpeppers Jul 14, 2025
61b6d8a
Fix renaming issue
simonrozsival Jul 14, 2025
9fed582
Update BuildReleaseArm64SimpleDotNet.apkdesc
jonathanpeppers Jul 14, 2025
3a54084
Clean up registered reference tracking handles dictionary
simonrozsival Jul 15, 2025
07283b8
Avoid using Trace.Assert
simonrozsival Jul 15, 2025
98e0b0d
Add debug assert for CollectedContexts invariant
simonrozsival Jul 15, 2025
1721e7f
Reduce nesting
simonrozsival Jul 15, 2025
93f1afd
Fix input validation
simonrozsival Jul 15, 2025
dd2b862
Merge branch 'dev/srozsival/gcbridge-clr' of github.com:dotnet/androi…
simonrozsival Jul 15, 2025
0ea139e
Revert "Update BuildReleaseArm64SimpleDotNet.apkdesc"
jonathanpeppers Jul 15, 2025
ffa44b3
Fix gref and gwref accounting
simonrozsival Jul 15, 2025
66cc35b
Merge branch 'dev/srozsival/gcbridge-clr' of github.com:dotnet/androi…
simonrozsival Jul 15, 2025
cc9df5d
Update apkdesc
simonrozsival Jul 15, 2025
f453805
Remove unnecessary script file
simonrozsival Jul 16, 2025
e2e203a
Fix formatting
simonrozsival Jul 16, 2025
6a7782f
Align naming of initialize_on_onload
simonrozsival Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Mono.Android/Android.Runtime/AndroidRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,9 @@ class AndroidValueManager : JniRuntime.JniValueManager {

public override void WaitForGCBridgeProcessing ()
{
AndroidRuntimeInternal.WaitForBridgeProcessing ();
if (!AndroidRuntimeInternal.BridgeProcessing)
return;
RuntimeNativeMethods._monodroid_gc_wait_for_bridge_processing ();
}

public override IJavaPeerable? CreatePeer (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ static void MonoUnhandledException (Exception ex)

public static void WaitForBridgeProcessing ()
{
if (!BridgeProcessing)
return;
RuntimeNativeMethods._monodroid_gc_wait_for_bridge_processing ();
Java.Interop.JniEnvironment.Runtime.ValueManager.WaitForGCBridgeProcessing ();
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Java;
using System.Text;

namespace Android.Runtime
Expand All @@ -18,7 +19,7 @@ enum TraceKind : uint
All = Java | Managed | Native | Signals,
}

internal static class RuntimeNativeMethods
internal unsafe static class RuntimeNativeMethods
{
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal extern static void monodroid_log (LogLevel level, LogCategories category, string message);
Expand Down Expand Up @@ -92,6 +93,11 @@ internal static class RuntimeNativeMethods
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern bool clr_typemap_java_to_managed (string java_type_name, out IntPtr managed_assembly_name, out uint managed_type_token_id);

[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern delegate* unmanaged<MarkCrossReferencesArgs*, void> clr_initialize_gc_bridge (
delegate* unmanaged<MarkCrossReferencesArgs*, void> bridge_processing_started_callback,
delegate* unmanaged<MarkCrossReferencesArgs*, void> bridge_processing_finished_callback);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void monodroid_unhandled_exception (Exception javaException);

Expand Down
Loading
Loading