Skip to content

Commit 81a97d6

Browse files
[monodroid] remove monodroid_get_log_categories()
In a NativeAOT context, we don't have `libmonodroid.so` *at all*. Let's remove the `monodroid_get_log_categories()` function, as we already pass in `args->logCategories` at startup. We can use a new `Logger.SetLogCategories()` method to pass the value in. I also removed `JNIEnvInit.LogAssemblyCategory`, as we can just use the `Logger` class instead. The startup sequence in C++ seems OK, so doesn't seem like this changes any behavior: * `Java_mono_android_Runtime_initInternal()` sets up logging categories very early in startup. * `create_and_initialize_domain()` calls... * `init_android_runtime()` calls... * Calls managed code, `JNIEnvInit.Initialize()` using the correct logging categories.
1 parent b70c812 commit 81a97d6

File tree

9 files changed

+9
-25
lines changed

9 files changed

+9
-25
lines changed

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ internal static void LogTypemapTrace (StackTrace st)
515515
}
516516

517517
if (ret == IntPtr.Zero) {
518-
if (JNIEnvInit.LogAssemblyCategory) {
518+
if (Logger.LogAssembly) {
519519
RuntimeNativeMethods.monodroid_log (LogLevel.Warn, LogCategories.Default, $"typemap: failed to map managed type to Java type: {type.AssemblyQualifiedName} (Module ID: {type.Module.ModuleVersionId}; Type token: {type.MetadataToken})");
520520
LogTypemapTrace (new StackTrace (true));
521521
}

src/Mono.Android/Android.Runtime/JNIEnvInit.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ internal struct JnienvInitializeArgs {
3838
internal static AndroidValueManager? AndroidValueManager;
3939
internal static bool IsRunningOnDesktop;
4040
internal static bool jniRemappingInUse;
41-
internal static bool LogAssemblyCategory;
4241
internal static bool MarshalMethodsEnabled;
4342
internal static bool PropagateExceptions;
4443
internal static BoundExceptionType BoundExceptionType;
@@ -83,7 +82,7 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)
8382
IntPtr total_timing_sequence = IntPtr.Zero;
8483
IntPtr partial_timing_sequence = IntPtr.Zero;
8584

86-
LogAssemblyCategory = (args->logCategories & (uint)LogCategories.Assembly) != 0;
85+
Logger.SetLogCategories ((LogCategories)args->logCategories);
8786

8887
gref_gc_threshold = args->grefGcThreshold;
8988

src/Mono.Android/Android.Runtime/JNINativeWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Delegate CreateDelegate (Delegate dlg)
4040
if (result != null)
4141
return result;
4242

43-
if (JNIEnvInit.LogAssemblyCategory) {
43+
if (Logger.LogAssembly) {
4444
RuntimeNativeMethods.monodroid_log (LogLevel.Debug, LogCategories.Assembly, $"Falling back to System.Reflection.Emit for delegate type '{delegateType}': {dlg.Method}");
4545
}
4646

src/Mono.Android/Android.Runtime/Logger.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ public static void Log (LogLevel level, string appname, string? log) {
5858
}
5959
}
6060

61-
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
62-
extern static uint monodroid_get_log_categories ();
63-
64-
static Logger ()
65-
{
66-
Categories = (LogCategories) monodroid_get_log_categories ();
67-
}
61+
internal static void SetLogCategories (LogCategories categories) =>
62+
Categories = categories;
6863
}
6964
}

src/Mono.Android/Java.Interop/TypeManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static Exception CreateJavaLocationException ()
224224

225225
if (!JNIEnvInit.IsRunningOnDesktop) {
226226
// Miss message is logged in the native runtime
227-
if (JNIEnvInit.LogAssemblyCategory)
227+
if (Logger.LogAssembly)
228228
JNIEnv.LogTypemapTrace (new System.Diagnostics.StackTrace (true));
229229
return null;
230230
}

src/native/monodroid/internal-pinvokes.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
using namespace xamarin::android;
77
using namespace xamarin::android::internal;
88

9-
unsigned int
10-
monodroid_get_log_categories ()
11-
{
12-
return log_categories;
13-
}
14-
159
int
1610
monodroid_get_system_property (const char *name, char **value)
1711
{

src/native/pinvoke-override/generate-pinvoke-tables.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const std::vector<std::string> internal_pinvoke_names = {
4848
"_monodroid_get_dns_servers",
4949
"monodroid_get_dylib",
5050
"_monodroid_getifaddrs",
51-
"monodroid_get_log_categories",
5251
"monodroid_get_namespaced_system_property",
5352
"_monodroid_get_network_interface_supports_multicast",
5453
"_monodroid_get_network_interface_up_state",

src/native/pinvoke-override/pinvoke-tables.include

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
namespace {
1212
#if INTPTR_MAX == INT64_MAX
1313
//64-bit internal p/invoke table
14-
std::array<PinvokeEntry, 46> internal_pinvokes {{
15-
{0x452e23128e42f0a, "monodroid_get_log_categories", reinterpret_cast<void*>(&monodroid_get_log_categories)},
14+
std::array<PinvokeEntry, 45> internal_pinvokes {{
1615
{0xa50ce5de13bf8b5, "_monodroid_timezone_get_default_id", reinterpret_cast<void*>(&_monodroid_timezone_get_default_id)},
1716
{0x19055d65edfd668e, "_monodroid_get_network_interface_up_state", reinterpret_cast<void*>(&_monodroid_get_network_interface_up_state)},
1817
{0x2b3b0ca1d14076da, "monodroid_get_dylib", reinterpret_cast<void*>(&monodroid_get_dylib)},
@@ -550,7 +549,7 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x18
550549
constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5;
551550
#else
552551
//32-bit internal p/invoke table
553-
std::array<PinvokeEntry, 46> internal_pinvokes {{
552+
std::array<PinvokeEntry, 45> internal_pinvokes {{
554553
{0xb7a486a, "monodroid_TypeManager_get_java_class_name", reinterpret_cast<void*>(&monodroid_TypeManager_get_java_class_name)},
555554
{0xf562bd9, "monodroid_embedded_assemblies_set_assemblies_prefix", reinterpret_cast<void*>(&monodroid_embedded_assemblies_set_assemblies_prefix)},
556555
{0x227a2636, "monodroid_get_namespaced_system_property", reinterpret_cast<void*>(&monodroid_get_namespaced_system_property)},
@@ -584,7 +583,6 @@ constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5;
584583
{0xc5146c54, "_monodroid_gref_log_delete", reinterpret_cast<void*>(&_monodroid_gref_log_delete)},
585584
{0xc58eafa5, "java_interop_free", reinterpret_cast<void*>(&java_interop_free)},
586585
{0xd3b5d2c1, "_monodroid_freeifaddrs", reinterpret_cast<void*>(&_monodroid_freeifaddrs)},
587-
{0xd78c749d, "monodroid_get_log_categories", reinterpret_cast<void*>(&monodroid_get_log_categories)},
588586
{0xd91f3619, "create_public_directory", reinterpret_cast<void*>(&create_public_directory)},
589587
{0xe215a17c, "_monodroid_weak_gref_delete", reinterpret_cast<void*>(&_monodroid_weak_gref_delete)},
590588
{0xe4c3ee19, "monodroid_log_traces", reinterpret_cast<void*>(&monodroid_log_traces)},
@@ -1089,6 +1087,6 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x93
10891087
constexpr hash_t system_globalization_native_library_hash = 0xa66f1e5a;
10901088
#endif
10911089

1092-
constexpr size_t internal_pinvokes_count = 46;
1090+
constexpr size_t internal_pinvokes_count = 45;
10931091
constexpr size_t dotnet_pinvokes_count = 477;
10941092
} // end of anonymous namespace

src/native/runtime-base/internal-pinvokes.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mono_bool _monodroid_get_network_interface_up_state (const char *ifname, mono_bo
1919
mono_bool _monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast);
2020
int _monodroid_get_dns_servers (void **dns_servers_array);
2121

22-
unsigned int monodroid_get_log_categories ();
2322
int monodroid_get_system_property (const char *name, char **value);
2423
int monodroid_embedded_assemblies_set_assemblies_prefix (const char *prefix);
2524
void monodroid_log (xamarin::android::LogLevel level, LogCategories category, const char *message);

0 commit comments

Comments
 (0)