diff --git a/src/native/clr/host/bridge-processing.cc b/src/native/clr/host/bridge-processing.cc index 2489346b15e..ab8f43a65c7 100644 --- a/src/native/clr/host/bridge-processing.cc +++ b/src/native/clr/host/bridge-processing.cc @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -254,10 +254,10 @@ void BridgeProcessingShared::add_circular_references (const StronglyConnectedCom abort_unless (reference_added, [this, &prev, &next] { jclass prev_java_class = env->GetObjectClass (prev.handle); - const char *prev_class_name = Host::get_java_class_name_for_TypeManager (prev_java_class); + const char *prev_class_name = HostCommon::get_java_class_name_for_TypeManager (prev_java_class); jclass next_java_class = env->GetObjectClass (next.handle); - const char *next_class_name = Host::get_java_class_name_for_TypeManager (next_java_class); + const char *next_class_name = HostCommon::get_java_class_name_for_TypeManager (next_java_class); return detail::_format_message ( "Failed to add reference between objects in a strongly connected component: %s -> %s.", @@ -463,14 +463,14 @@ void CrossReferenceTarget::mark_refs_added_if_needed () noexcept [[gnu::always_inline]] void BridgeProcessingShared::log_missing_add_references_method ([[maybe_unused]] jclass java_class) noexcept { - log_error (LOG_DEFAULT, "Failed to find monodroidAddReferences method"); + log_errorf (LOG_DEFAULT, "Failed to find monodroidAddReferences method"); #if DEBUG abort_if_invalid_pointer_argument (java_class, "java_class"); if (!Logger::gc_spew_enabled ()) [[likely]] { return; } - char *class_name = Host::get_java_class_name_for_TypeManager (java_class); + char *class_name = HostCommon::get_java_class_name_for_TypeManager (java_class); log_errorf (LOG_GC, "Missing monodroidAddReferences method for object of class %s", optional_string (class_name)); free (class_name); #endif @@ -479,14 +479,14 @@ void BridgeProcessingShared::log_missing_add_references_method ([[maybe_unused]] [[gnu::always_inline]] void BridgeProcessingShared::log_missing_clear_references_method ([[maybe_unused]] jclass java_class) noexcept { - log_error (LOG_DEFAULT, "Failed to find monodroidClearReferences method"); + log_errorf (LOG_DEFAULT, "Failed to find monodroidClearReferences method"); #if DEBUG abort_if_invalid_pointer_argument (java_class, "java_class"); if (!Logger::gc_spew_enabled ()) [[likely]] { return; } - char *class_name = Host::get_java_class_name_for_TypeManager (java_class); + char *class_name = HostCommon::get_java_class_name_for_TypeManager (java_class); log_errorf (LOG_GC, "Missing monodroidClearReferences method for object of class %s", optional_string (class_name)); free (class_name); #endif diff --git a/src/native/clr/host/gc-bridge.cc b/src/native/clr/host/gc-bridge.cc index b9dc2a06184..2b1cfbfd40e 100644 --- a/src/native/clr/host/gc-bridge.cc +++ b/src/native/clr/host/gc-bridge.cc @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -85,7 +85,7 @@ void GCBridge::trigger_java_gc (JNIEnv *env) noexcept env->ExceptionDescribe (); env->ExceptionClear (); - log_error (LOG_DEFAULT, "Java GC failed"); + log_errorf (LOG_DEFAULT, "Java GC failed"); } void GCBridge::mark_cross_references (MarkCrossReferencesArgs *args) noexcept @@ -161,7 +161,7 @@ void GCBridge::log_handle_context (JNIEnv *env, HandleContext *ctx) noexcept jobject handle = ctx->control_block->handle; jclass java_class = env->GetObjectClass (handle); if (java_class != nullptr) { - char *class_name = Host::get_java_class_name_for_TypeManager (java_class); + char *class_name = HostCommon::get_java_class_name_for_TypeManager (java_class); log_infof (LOG_GC, "gref 0x%" PRIxPTR " [%s]", reinterpret_cast (handle), optional_string (class_name)); free (class_name); env->DeleteLocalRef (java_class); diff --git a/src/native/clr/host/host-shared.cc b/src/native/clr/host/host-shared.cc index 9b6da9345b6..d1702f19b9c 100644 --- a/src/native/clr/host/host-shared.cc +++ b/src/native/clr/host/host-shared.cc @@ -1,4 +1,4 @@ -#include +#include #include using namespace xamarin::android; diff --git a/src/native/clr/host/internal-pinvokes-shared.cc b/src/native/clr/host/internal-pinvokes-shared.cc index 813e6c64f90..18bffb5812e 100644 --- a/src/native/clr/host/internal-pinvokes-shared.cc +++ b/src/native/clr/host/internal-pinvokes-shared.cc @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -56,37 +56,37 @@ void monodroid_log (LogLevel level, LogCategories category, const char *message) switch (level) { case LogLevel::Verbose: case LogLevel::Debug: - log_debug_nocheck (category, std::string_view { message }); + log_debugf (category, "%s", message); break; case LogLevel::Info: - log_info_nocheck (category, std::string_view { message }); + log_infof (category, "%s", message); break; case LogLevel::Warn: case LogLevel::Silent: // warn is always printed - log_warn (category, std::string_view { message }); + log_write (category, LogLevel::Warn, message); break; case LogLevel::Error: - log_error (category, std::string_view { message }); + log_write (category, LogLevel::Error, message); break; case LogLevel::Fatal: - log_fatal (category, std::string_view { message }); + log_write (category, LogLevel::Fatal, message); break; default: case LogLevel::Unknown: case LogLevel::Default: - log_info_nocheck (category, std::string_view { message }); + log_infof (category, "%s", message); break; } } char* monodroid_TypeManager_get_java_class_name (jclass klass) noexcept { - return Host::get_java_class_name_for_TypeManager (klass); + return HostCommon::get_java_class_name_for_TypeManager (klass); } void monodroid_free (void *ptr) noexcept diff --git a/src/native/clr/host/os-bridge.cc b/src/native/clr/host/os-bridge.cc index 3a8152b37d6..797316a9f7d 100644 --- a/src/native/clr/host/os-bridge.cc +++ b/src/native/clr/host/os-bridge.cc @@ -91,13 +91,13 @@ auto OSBridge::_monodroid_weak_gref_dec () noexcept -> int void OSBridge::_write_stack_trace (FILE *to, const char *const from, LogCategories category) noexcept { if (from == nullptr) [[unlikely]] { - log_warn (category, "Unable to write stack trace, managed runtime passed a NULL string."); + log_warnf (category, "Unable to write stack trace, managed runtime passed a NULL string."); return; } std::string_view trace { from }; if (trace.empty ()) [[unlikely]] { - log_warn (category, "Empty stack trace passed by the managed runtime."); + log_warnf (category, "Empty stack trace passed by the managed runtime."); return; } @@ -164,7 +164,7 @@ void OSBridge::_monodroid_gref_logf (const char *format, ...) noexcept [[gnu::always_inline, gnu::flatten]] void OSBridge::log_it (LogCategories category, std::string_view const& line, FILE *to, const char *const from, bool logcat_enabled) noexcept { - log_write (category, LogLevel::Info, line); + log_writef (category, LogLevel::Info, "%.*s", static_cast(line.length ()), line.data ()); // We skip logcat here when logging to file is enabled because _write_stack_trace will output to logcat as well, if enabled if (to == nullptr) { diff --git a/src/native/clr/include/runtime-base/android-system.hh b/src/native/clr/include/runtime-base/android-system.hh index 3b4c0dedfb7..fe5be44035e 100644 --- a/src/native/clr/include/runtime-base/android-system.hh +++ b/src/native/clr/include/runtime-base/android-system.hh @@ -9,7 +9,7 @@ #include #include "../constants.hh" -#include "../shared/log_types.hh" +#include #include "../runtime-base/cpu-arch.hh" #include #include diff --git a/src/native/nativeaot/include/runtime-base/internal-pinvokes.hh b/src/native/nativeaot/include/runtime-base/internal-pinvokes.hh new file mode 100644 index 00000000000..60ff24596fc --- /dev/null +++ b/src/native/nativeaot/include/runtime-base/internal-pinvokes.hh @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +#include +#include +#include + +namespace xamarin::android { + struct managed_timing_sequence; +} + +extern "C" { + int _monodroid_gref_get () noexcept; + int _monodroid_gref_inc () noexcept; + int _monodroid_gref_dec () noexcept; + void _monodroid_gref_log (const char *message) noexcept; + 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; + void _monodroid_gref_log_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) noexcept; + const char* clr_typemap_managed_to_java (const char *typeName, const char *assemblyFullName, const uint8_t *mvid) noexcept; + bool clr_typemap_java_to_managed (const char *java_type_name, char const** assembly_name, uint32_t *managed_type_token_id) noexcept; + BridgeProcessingFtn clr_initialize_gc_bridge ( + BridgeProcessingStartedFtn bridge_processing_started_callback, + BridgeProcessingFinishedFtn mark_cross_references_callback) noexcept; + void monodroid_log (xamarin::android::LogLevel level, LogCategories category, const char *message) noexcept; + char* monodroid_TypeManager_get_java_class_name (jclass klass) noexcept; + void monodroid_free (void *ptr) noexcept; + const char* _monodroid_lookup_replacement_type (const char *jniSimpleReference); + const JniRemappingReplacementMethod* _monodroid_lookup_replacement_method_info (const char *jniSourceType, const char *jniMethodName, const char *jniMethodSignature); + xamarin::android::managed_timing_sequence* monodroid_timing_start (const char *message); + void monodroid_timing_stop (xamarin::android::managed_timing_sequence *sequence, const char *message); + + void _monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable) noexcept; + int _monodroid_weak_gref_get () noexcept; + int _monodroid_weak_gref_inc () noexcept; + int _monodroid_weak_gref_dec () noexcept; + int _monodroid_max_gref_get () noexcept; + void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) noexcept; + + 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_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); + void _monodroid_gc_wait_for_bridge_processing (); + void _monodroid_detect_cpu_and_architecture (unsigned short *built_for_cpu, unsigned short *running_on_cpu, unsigned char *is64bit); +} diff --git a/src/native/nativeaot/include/shared/log_types.hh b/src/native/nativeaot/include/shared/log_types.hh new file mode 100644 index 00000000000..e4b75d6ea0e --- /dev/null +++ b/src/native/nativeaot/include/shared/log_types.hh @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern unsigned int log_categories;