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 @@ -41,14 +41,20 @@ static void JNI_OnUnload (IntPtr vm, IntPtr reserved)
}

[DllImport("xa-internal-api")]
static extern void XA_Host_NativeAOT_OnInit (IntPtr language, IntPtr filesDir, IntPtr cacheDir);
static extern void XA_Host_NativeAOT_OnInit (IntPtr language, IntPtr filesDir, IntPtr cacheDir, ref JNIEnvInit.JnienvInitializeArgs initArgs);

// symbol name from `$(IntermediateOutputPath)obj/Release/osx-arm64/h-classes/net_dot_jni_hello_JavaInteropRuntime.h`
[UnmanagedCallersOnly (EntryPoint="Java_net_dot_jni_nativeaot_JavaInteropRuntime_init")]
static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader, IntPtr language, IntPtr filesDir, IntPtr cacheDir)
{
JniTransition transition = default;
try {
var initArgs = new JNIEnvInit.JnienvInitializeArgs ();

// This needs to be called first, since it sets up locations, environment variables, logging etc
XA_Host_NativeAOT_OnInit (language, filesDir, cacheDir, ref initArgs);
JNIEnvInit.InitializeJniRuntimeEarly (initArgs);

var settings = new DiagnosticSettings ();
settings.AddDebugDotnetLog ();

Expand All @@ -63,9 +69,8 @@ static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader, IntPtr langua
};
runtime = options.CreateJreVM ();

// Entry point into Mono.Android.dll
JNIEnvInit.InitializeJniRuntime (runtime);
XA_Host_NativeAOT_OnInit (language, filesDir, cacheDir);
// Entry point into Mono.Android.dll. Log categories are initialized in JNI_OnLoad.
JNIEnvInit.InitializeJniRuntime (runtime, initArgs);

transition = new JniTransition (jnienv);

Expand Down
10 changes: 9 additions & 1 deletion src/Mono.Android/Android.Runtime/JNIEnvInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ internal static void NativeAotInitializeMaxGrefGet ()
}
}

// This is needed to initialize e.g. logging before anything else (useful with e.g. gref
// logging where runtime creation causes several grefs to be created and logged without
// stack traces because logging categories on the managed side aren't yet set)
internal static void InitializeJniRuntimeEarly (JnienvInitializeArgs args)
{
Logger.SetLogCategories ((LogCategories)args.logCategories);
}

// 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)
internal static void InitializeJniRuntime (JniRuntime runtime, JnienvInitializeArgs args)
{
androidRuntime = runtime;
SetSynchronizationContext ();
Expand Down
12 changes: 6 additions & 6 deletions src/native/clr/host/bridge-processing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void BridgeProcessingShared::abort_unless_all_collected_or_all_alive (const Stro

abort_unless (scc.Contexts [0] != nullptr, "Context must not be null");
bool is_collected = scc.Contexts [0]->is_collected ();

for (size_t j = 1; j < scc.Count; j++) {
const HandleContext *context = scc.Contexts [j];
abort_unless (context != nullptr, "Context must not be null");
Expand Down Expand Up @@ -352,9 +352,9 @@ void BridgeProcessingShared::log_weak_to_gref (jobject weak, jobject handle) noe
OSBridge::_monodroid_gref_log_new (weak, OSBridge::get_object_ref_type (env, weak),
handle, OSBridge::get_object_ref_type (env, handle),
"finalizer", gettid (),
" at [[clr-gc:take_global_ref]]", 0);
" at [[clr-gc:take_global_ref]]");
}

if (!Logger::gref_log ()) [[likely]] {
return;
}
Expand Down Expand Up @@ -391,21 +391,21 @@ void BridgeProcessingShared::log_weak_gref_new (jobject handle, jobject weak) no
{
OSBridge::_monodroid_weak_gref_new (handle, OSBridge::get_object_ref_type (env, handle),
weak, OSBridge::get_object_ref_type (env, weak),
"finalizer", gettid (), " at [[clr-gc:take_weak_global_ref]]", 0);
"finalizer", gettid (), " at [[clr-gc:take_weak_global_ref]]");
}

[[gnu::always_inline]]
void BridgeProcessingShared::log_gref_delete (jobject handle) noexcept
{
OSBridge::_monodroid_gref_log_delete (handle, OSBridge::get_object_ref_type (env, handle),
"finalizer", gettid (), " at [[clr-gc:take_weak_global_ref]]", 0);
"finalizer", gettid (), " at [[clr-gc:take_weak_global_ref]]");
}

[[gnu::always_inline]]
void BridgeProcessingShared::log_weak_ref_delete (jobject weak) noexcept
{
OSBridge::_monodroid_weak_gref_delete (weak, OSBridge::get_object_ref_type (env, weak),
"finalizer", gettid (), " at [[clr-gc:take_global_ref]]", 0);
"finalizer", gettid (), " at [[clr-gc:take_global_ref]]");
}

[[gnu::always_inline]]
Expand Down
1 change: 1 addition & 0 deletions src/native/clr/host/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ void Host::Java_mono_android_Runtime_initInternal (
AndroidSystem::set_primary_override_dir (files_dir);
AndroidSystem::create_update_dir (AndroidSystem::get_primary_override_dir ());
AndroidSystem::setup_environment ();
Logger::init_reference_logging (AndroidSystem::get_primary_override_dir ());

jstring_array_wrapper runtimeApks (env, runtimeApksJava);
AndroidSystem::setup_app_library_directories (runtimeApks, applicationDirs, haveSplitApks);
Expand Down
24 changes: 12 additions & 12 deletions src/native/clr/host/internal-pinvokes-shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ void _monodroid_gref_log (const char *message) noexcept
OSBridge::_monodroid_gref_log (message);
}

int _monodroid_gref_log_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable) noexcept
int _monodroid_gref_log_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable) noexcept
{
return OSBridge::_monodroid_gref_log_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
return OSBridge::_monodroid_gref_log_new (curHandle, curType, newHandle, newType, threadName, threadId, from);
}

void _monodroid_gref_log_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) noexcept
void _monodroid_gref_log_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable) noexcept
{
OSBridge::_monodroid_gref_log_delete (handle, type, threadName, threadId, from, from_writable);
OSBridge::_monodroid_gref_log_delete (handle, type, threadName, threadId, from);
}

void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable)
{
OSBridge::_monodroid_weak_gref_delete (handle, type, threadName, threadId, from, from_writable);
OSBridge::_monodroid_weak_gref_delete (handle, type, threadName, threadId, from);
}

BridgeProcessingFtn clr_initialize_gc_bridge (
Expand Down Expand Up @@ -84,9 +84,9 @@ void monodroid_free (void *ptr) noexcept
free (ptr);
}

void _monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable)
void _monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable)
{
OSBridge::_monodroid_weak_gref_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
OSBridge::_monodroid_weak_gref_new (curHandle, curType, newHandle, newType, threadName, threadId, from);
}

int _monodroid_weak_gref_get ()
Expand All @@ -99,14 +99,14 @@ int _monodroid_max_gref_get ()
return static_cast<int>(AndroidSystem::get_max_gref_count ());
}

void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable)
{
OSBridge::_monodroid_lref_log_new (lrefc, handle, type, threadName, threadId, from, from_writable);
OSBridge::_monodroid_lref_log_new (lrefc, handle, type, threadName, threadId, from);
}

void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, [[maybe_unused]] int from_writable)
{
OSBridge::_monodroid_lref_log_delete (lrefc, handle, type, threadName, threadId, from, from_writable);
OSBridge::_monodroid_lref_log_delete (lrefc, handle, type, threadName, threadId, from);
}

void _monodroid_gc_wait_for_bridge_processing ()
Expand Down
Loading
Loading