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
14 changes: 7 additions & 7 deletions src/native/clr/host/bridge-processing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <cstdlib>

#include <host/bridge-processing.hh>
#include <host/host.hh>
#include <host/host-common.hh>
#include <host/runtime-util.hh>
#include <runtime-base/logger.hh>
#include <shared/helpers.hh>
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/native/clr/host/gc-bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <host/gc-bridge.hh>
#include <host/bridge-processing.hh>
#include <host/os-bridge.hh>
#include <host/host.hh>
#include <host/host-common.hh>
#include <runtime-base/util.hh>
#include <shared/helpers.hh>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<uintptr_t> (handle), optional_string (class_name));
free (class_name);
env->DeleteLocalRef (java_class);
Expand Down
2 changes: 1 addition & 1 deletion src/native/clr/host/host-shared.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <host/host.hh>
#include <host/host-common.hh>
#include <host/os-bridge.hh>

using namespace xamarin::android;
Expand Down
16 changes: 8 additions & 8 deletions src/native/clr/host/internal-pinvokes-shared.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <host/gc-bridge.hh>
#include <host/host.hh>
#include <host/host-common.hh>
#include <host/os-bridge.hh>
#include <host/typemap.hh>
#include <runtime-base/android-system.hh>
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/native/clr/host/os-bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<int>(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) {
Expand Down
2 changes: 1 addition & 1 deletion src/native/clr/include/runtime-base/android-system.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <unordered_map>

#include "../constants.hh"
#include "../shared/log_types.hh"
#include <shared/log_types.hh>
#include "../runtime-base/cpu-arch.hh"
#include <runtime-base/jni-wrappers.hh>
#include <runtime-base/strings.hh>
Expand Down
45 changes: 45 additions & 0 deletions src/native/nativeaot/include/runtime-base/internal-pinvokes.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <jni.h>
#include <ifaddrs.h>

#include <host/gc-bridge.hh>
#include <xamarin-app.hh>
#include <runtime-base/logger.hh>

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);
}
5 changes: 5 additions & 0 deletions src/native/nativeaot/include/shared/log_types.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <shared/log_functions.hh>

extern unsigned int log_categories;
Loading