Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ static int JNI_OnLoad (IntPtr vm, IntPtr reserved)
try {
AndroidLog.Print (AndroidLogLevel.Info, "JavaInteropRuntime", "JNI_OnLoad()");
XA_Host_NativeAOT_JNI_OnLoad (vm, reserved);
// This must be called before anything else, otherwise we'll see several spurious GC invocations and log messages
// similar to:
//
// 09-15 14:51:01.311 11071 11071 D monodroid-gc: 1 outstanding GREFs. Performing a full GC!
//
JNIEnvInit.NativeAotInitializeMaxGrefGet ();

LogcatTextWriter.Init ();
return (int) JniVersion.v1_6;
}
Expand Down
13 changes: 9 additions & 4 deletions src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ static Type TypeGetType (string typeName) =>
androidRuntime!.TypeManager.RegisterNativeMembers (jniType, type, methods);
}

// NOTE: should have different name than `Initialize` to avoid:
// * Assertion at /__w/1/s/src/mono/mono/metadata/icall.c:6258, condition `!only_unmanaged_callers_only' not met
internal static void InitializeJniRuntime (JniRuntime runtime)
// This must be called by NativeAOT before InitializeJniRuntime, as early as possible
internal static void NativeAotInitializeMaxGrefGet ()
{
androidRuntime = runtime;
gref_gc_threshold = RuntimeNativeMethods._monodroid_max_gref_get ();
if (gref_gc_threshold != int.MaxValue) {
gref_gc_threshold = checked((gref_gc_threshold * 9) / 10);
}
}

// NOTE: should have different name than `Initialize` to avoid:
// * Assertion at /__w/1/s/src/mono/mono/metadata/icall.c:6258, condition `!only_unmanaged_callers_only' not met
internal static void InitializeJniRuntime (JniRuntime runtime)
{
androidRuntime = runtime;
SetSynchronizationContext ();
}

Expand Down
Loading