Skip to content

Commit 6a4feea

Browse files
Address native logging API feedback
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b6dc990 commit 6a4feea

5 files changed

Lines changed: 20 additions & 75 deletions

File tree

src/native/clr/host/bridge-processing.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,31 +359,31 @@ void CrossReferenceTarget::mark_refs_added_if_needed () noexcept
359359
[[gnu::always_inline]]
360360
void BridgeProcessingShared::log_missing_add_references_method ([[maybe_unused]] jclass java_class) noexcept
361361
{
362-
(xamarin::android::log_error) (LOG_DEFAULT, "Failed to find monodroidAddReferences method");
362+
(log_error) (LOG_DEFAULT, "Failed to find monodroidAddReferences method");
363363
#if DEBUG
364364
abort_if_invalid_pointer_argument (java_class, "java_class");
365365
if (!Logger::gc_spew_enabled ()) [[likely]] {
366366
return;
367367
}
368368

369369
char *class_name = Host::get_java_class_name_for_TypeManager (java_class);
370-
xamarin::android::log_error_fmt (LOG_GC, "Missing monodroidAddReferences method for object of class %s", optional_string (class_name));
370+
(log_error) (LOG_GC, "Missing monodroidAddReferences method for object of class %s", optional_string (class_name));
371371
free (class_name);
372372
#endif
373373
}
374374

375375
[[gnu::always_inline]]
376376
void BridgeProcessingShared::log_missing_clear_references_method ([[maybe_unused]] jclass java_class) noexcept
377377
{
378-
(xamarin::android::log_error) (LOG_DEFAULT, "Failed to find monodroidClearReferences method");
378+
(log_error) (LOG_DEFAULT, "Failed to find monodroidClearReferences method");
379379
#if DEBUG
380380
abort_if_invalid_pointer_argument (java_class, "java_class");
381381
if (!Logger::gc_spew_enabled ()) [[likely]] {
382382
return;
383383
}
384384

385385
char *class_name = Host::get_java_class_name_for_TypeManager (java_class);
386-
xamarin::android::log_error_fmt (LOG_GC, "Missing monodroidClearReferences method for object of class %s", optional_string (class_name));
386+
(log_error) (LOG_GC, "Missing monodroidClearReferences method for object of class %s", optional_string (class_name));
387387
free (class_name);
388388
#endif
389389
}
@@ -487,5 +487,5 @@ void BridgeProcessingShared::log_gc_summary () noexcept
487487
}
488488
}
489489

490-
xamarin::android::log_info_fmt (LOG_GC, "GC cleanup summary: %zu objects tested - resurrecting %zu.", total, alive);
490+
log_info_fmt (LOG_GC, "GC cleanup summary: %zu objects tested - resurrecting %zu.", total, alive);
491491
}

src/native/clr/host/fastdev-assemblies.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ auto FastDevAssemblies::open_assembly (std::string_view const& name, int64_t &si
1818
{
1919
size = 0;
2020

21-
std::string const& override_dir_path = AndroidSystem::get_primary_override_dir ();
21+
const char *override_dir_path = AndroidSystem::get_primary_override_dir ();
2222
if (!Util::dir_exists (override_dir_path)) [[unlikely]] {
23-
log_debug (LOG_ASSEMBLY, "Override directory '{}' does not exist"sv, override_dir_path);
23+
log_debug (LOG_ASSEMBLY, "Override directory '{}' does not exist"sv, optional_string (override_dir_path));
2424
return nullptr;
2525
}
2626

@@ -29,9 +29,9 @@ auto FastDevAssemblies::open_assembly (std::string_view const& name, int64_t &si
2929
if (override_dir_fd < 0) [[unlikely]] {
3030
std::lock_guard dir_lock { override_dir_lock };
3131
if (override_dir_fd < 0) [[likely]] {
32-
override_dir = opendir (override_dir_path.c_str ());
32+
override_dir = opendir (override_dir_path);
3333
if (override_dir == nullptr) [[unlikely]] {
34-
log_warn (LOG_ASSEMBLY, "Failed to open override dir '{}'. {}"sv, override_dir_path, strerror (errno));
34+
log_warn (LOG_ASSEMBLY, "Failed to open override dir '{}'. {}"sv, optional_string (override_dir_path), strerror (errno));
3535
return nullptr;
3636
}
3737
override_dir_fd = dirfd (override_dir);
@@ -42,7 +42,7 @@ auto FastDevAssemblies::open_assembly (std::string_view const& name, int64_t &si
4242
LOG_ASSEMBLY,
4343
"Attempting to load FastDev assembly '{}' from override directory '{}'"sv,
4444
name,
45-
override_dir_path
45+
optional_string (override_dir_path)
4646
);
4747

4848
if (!Util::file_exists (override_dir_fd, name)) {

src/native/clr/host/gc-bridge.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void GCBridge::trigger_java_gc (JNIEnv *env) noexcept
4949

5050
env->ExceptionDescribe ();
5151
env->ExceptionClear ();
52-
(xamarin::android::log_error) (LOG_DEFAULT, "Java GC failed");
52+
(log_error) (LOG_DEFAULT, "Java GC failed");
5353
}
5454

5555
void GCBridge::mark_cross_references (MarkCrossReferencesArgs *args) noexcept
@@ -101,13 +101,13 @@ void GCBridge::log_mark_cross_references_args_if_enabled (MarkCrossReferencesArg
101101
return;
102102
}
103103

104-
xamarin::android::log_info_fmt (LOG_GC, "cross references callback invoked with %zu sccs and %zu xrefs.", args->ComponentCount, args->CrossReferenceCount);
104+
log_info_fmt (LOG_GC, "cross references callback invoked with %zu sccs and %zu xrefs.", args->ComponentCount, args->CrossReferenceCount);
105105

106106
JNIEnv *env = OSBridge::ensure_jnienv ();
107107

108108
for (size_t i = 0; i < args->ComponentCount; ++i) {
109109
const StronglyConnectedComponent &scc = args->Components [i];
110-
xamarin::android::log_info_fmt (LOG_GC, "group %zu with %zu objects", i, scc.Count);
110+
log_info_fmt (LOG_GC, "group %zu with %zu objects", i, scc.Count);
111111
for (size_t j = 0; j < scc.Count; ++j) {
112112
log_handle_context (env, scc.Contexts [j]);
113113
}
@@ -120,7 +120,7 @@ void GCBridge::log_mark_cross_references_args_if_enabled (MarkCrossReferencesArg
120120
for (size_t i = 0; i < args->CrossReferenceCount; ++i) {
121121
size_t source_index = args->CrossReferences [i].SourceGroupIndex;
122122
size_t dest_index = args->CrossReferences [i].DestinationGroupIndex;
123-
xamarin::android::log_info_fmt (LOG_GC, "xref [%zu] %zu -> %zu", i, source_index, dest_index);
123+
log_info_fmt (LOG_GC, "xref [%zu] %zu -> %zu", i, source_index, dest_index);
124124
}
125125
}
126126

@@ -134,9 +134,9 @@ void GCBridge::log_handle_context (JNIEnv *env, HandleContext *ctx) noexcept
134134
jclass java_class = env->GetObjectClass (handle);
135135
if (java_class != nullptr) {
136136
char *class_name = Host::get_java_class_name_for_TypeManager (java_class);
137-
xamarin::android::log_info_fmt (LOG_GC, "gref %p [%s]", reinterpret_cast<void*>(handle), optional_string (class_name));
137+
log_info_fmt (LOG_GC, "gref %p [%s]", reinterpret_cast<void*>(handle), optional_string (class_name));
138138
free (class_name);
139139
} else {
140-
xamarin::android::log_info_fmt (LOG_GC, "gref %p [unknown class]", reinterpret_cast<void*>(handle));
140+
log_info_fmt (LOG_GC, "gref %p [unknown class]", reinterpret_cast<void*>(handle));
141141
}
142142
}

src/native/clr/include/runtime-base/android-system.hh

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,14 @@ namespace xamarin::android {
6363
running_in_emulator = yesno;
6464
}
6565

66-
#if defined(XA_HOST_NATIVEAOT)
6766
static auto get_primary_override_dir () noexcept -> const char*
6867
{
6968
return primary_override_dir;
7069
}
71-
#else
72-
static auto get_primary_override_dir () noexcept -> std::string const&
73-
{
74-
return primary_override_dir;
75-
}
76-
#endif
7770

7871
static void set_primary_override_dir (jstring_wrapper& home) noexcept
7972
{
80-
#if defined(XA_HOST_NATIVEAOT)
8173
determine_primary_override_dir (home, primary_override_dir, sizeof (primary_override_dir));
82-
#else
83-
primary_override_dir = determine_primary_override_dir (home);
84-
#endif
8574
}
8675

8776
#if !defined(XA_HOST_NATIVEAOT)
@@ -90,7 +79,7 @@ namespace xamarin::android {
9079
return native_libraries_dir;
9180
}
9281

93-
static void create_update_dir (std::string const& override_dir) noexcept
82+
static void create_update_dir (const char *override_dir) noexcept
9483
{
9584
if constexpr (Constants::is_release_build) {
9685
/*
@@ -106,7 +95,7 @@ namespace xamarin::android {
10695
}
10796
}
10897

109-
log_debug (LOG_DEFAULT, "Creating public update directory: `{}`", override_dir);
98+
log_debug (LOG_DEFAULT, "Creating public update directory: `{}`", optional_string (override_dir));
11099
Util::create_public_directory (override_dir);
111100
}
112101
#endif
@@ -145,7 +134,6 @@ namespace xamarin::android {
145134
embedded_dso_mode_enabled = yesno;
146135
}
147136

148-
#if defined(XA_HOST_NATIVEAOT)
149137
static void determine_primary_override_dir (jstring_wrapper &home, char *buffer, size_t buffer_size) noexcept
150138
{
151139
dynamic_local_string<SENSIBLE_PATH_MAX> name { home.get_cstr () };
@@ -156,27 +144,13 @@ namespace xamarin::android {
156144

157145
snprintf (buffer, buffer_size, "%s", name.get ());
158146
}
159-
#else
160-
static auto determine_primary_override_dir (jstring_wrapper &home) noexcept -> std::string
161-
{
162-
dynamic_local_string<SENSIBLE_PATH_MAX> name { home.get_cstr () };
163-
name.append ("/")
164-
.append (Constants::OVERRIDE_DIRECTORY_NAME)
165-
.append ("/")
166-
.append (Constants::android_lib_abi);
167-
168-
return {name.get (), name.length ()};
169-
}
170-
#endif
171147

172148
private:
173149
static inline long max_gref_count = 0;
174150
static inline bool running_in_emulator = false;
175151
static inline bool embedded_dso_mode_enabled = false;
176-
#if defined(XA_HOST_NATIVEAOT)
177152
static inline char primary_override_dir[SENSIBLE_PATH_MAX] {};
178-
#else
179-
static inline std::string primary_override_dir;
153+
#if !defined(XA_HOST_NATIVEAOT)
180154
static inline std::string native_libraries_dir;
181155

182156
#if defined (DEBUG)

src/native/clr/include/shared/log_types.hh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdarg>
34
#include <cstdint>
45
#if !defined(XA_HOST_NATIVEAOT)
56
#include <format>
@@ -69,36 +70,6 @@ namespace xamarin::android {
6970
log_write (category, level, message.data ());
7071
}
7172

72-
[[gnu::always_inline]]
73-
static inline void (log_debug) (LogCategories category, const char *message) noexcept
74-
{
75-
log_write (category, LogLevel::Debug, message);
76-
}
77-
78-
[[gnu::always_inline]]
79-
static inline void (log_info) (LogCategories category, const char *message) noexcept
80-
{
81-
log_write (category, LogLevel::Info, message);
82-
}
83-
84-
[[gnu::always_inline]]
85-
static inline void (log_warn) (LogCategories category, const char *message) noexcept
86-
{
87-
log_write (category, LogLevel::Warn, message);
88-
}
89-
90-
[[gnu::always_inline]]
91-
static inline void (log_error) (LogCategories category, const char *message) noexcept
92-
{
93-
log_write (category, LogLevel::Error, message);
94-
}
95-
96-
[[gnu::always_inline]]
97-
static inline void (log_fatal) (LogCategories category, const char *message) noexcept
98-
{
99-
log_write (category, LogLevel::Fatal, message);
100-
}
101-
10273
void log_debug_fmt (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));
10374
void log_info_fmt (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));
10475
void log_warn_fmt (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3)));

0 commit comments

Comments
 (0)