You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[NativeAOT] Initialize GC threshold much earlier (#10488)
The threshold value is used by the global reference creation
routine to determine whether to [start GC collection][0]:
```csharp
if (gc >= JNIEnvInit.gref_gc_threshold) {
Logger.Log (LogLevel.Debug, "monodroid-gc", gc + " outstanding GREFs. Performing a full GC!");
System.GC.Collect ();
}
```
However, the threshold value was being initialized after we've already invoked some non-trivial
managed code in the managed [NativeAOT runtime][1], too late to avoid at least a handful of
`System.GC.Collect ()` calls:
09-15 14:37:25.923 10761 10761 D monodroid-gc: 1 outstanding GREFs. Performing a full GC!
09-15 14:37:25.923 10761 10761 D monodroid-gc: 2 outstanding GREFs. Performing a full GC!
09-15 14:37:25.923 10761 10761 D monodroid-gc: 3 outstanding GREFs. Performing a full GC!
09-15 14:37:25.924 10761 10761 D monodroid-gc: 3 outstanding GREFs. Performing a full GC!
Fix this by splitting the GC threshold value initialization into a separate method which is
invoked as soon as possible from the `JNI_OnLoad` function exported by the NativeAOT application.
[0]: https://github.com/dotnet/android/blob/e72bf3626024fd1e27dd9cd26d7f8439bc088e19/src/Mono.Android/Android.Runtime/AndroidRuntime.cs#L178-L195
[1]: https://github.com/dotnet/android/blob/e72bf3626024fd1e27dd9cd26d7f8439bc088e19/src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/JavaInteropRuntime.cs#L60
0 commit comments