From df63756a1edce0f5d586507df94f918b07adbe93 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 22 Jul 2026 14:21:22 -0500 Subject: [PATCH] [NativeAOT] Migrate GC bridge logging to printf Convert the remaining easy formatted GC bridge diagnostics reachable by NativeAOT to the canonical shared printf logging APIs while preserving gating, no-check behavior, formatting, and null handling. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4aed776f-8743-45ba-b96b-079253595056 --- src/native/clr/host/gc-bridge.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/native/clr/host/gc-bridge.cc b/src/native/clr/host/gc-bridge.cc index 3d8cf0942dd..b9dc2a06184 100644 --- a/src/native/clr/host/gc-bridge.cc +++ b/src/native/clr/host/gc-bridge.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -128,13 +129,13 @@ void GCBridge::log_mark_cross_references_args_if_enabled (MarkCrossReferencesArg return; } - log_info (LOG_GC, "cross references callback invoked with {} sccs and {} xrefs.", args->ComponentCount, args->CrossReferenceCount); + log_infof (LOG_GC, "cross references callback invoked with %zu sccs and %zu xrefs.", args->ComponentCount, args->CrossReferenceCount); JNIEnv *env = OSBridge::ensure_jnienv (); for (size_t i = 0; i < args->ComponentCount; ++i) { const StronglyConnectedComponent &scc = args->Components [i]; - log_info (LOG_GC, "group {} with {} objects", i, scc.Count); + log_infof (LOG_GC, "group %zu with %zu objects", i, scc.Count); for (size_t j = 0; j < scc.Count; ++j) { log_handle_context (env, scc.Contexts [j]); } @@ -147,7 +148,7 @@ void GCBridge::log_mark_cross_references_args_if_enabled (MarkCrossReferencesArg for (size_t i = 0; i < args->CrossReferenceCount; ++i) { size_t source_index = args->CrossReferences [i].SourceGroupIndex; size_t dest_index = args->CrossReferences [i].DestinationGroupIndex; - log_info_nocheck_fmt (LOG_GC, "xref [{}] {} -> {}", i, source_index, dest_index); + log_writef (LOG_GC, LogLevel::Info, "xref [%zu] %zu -> %zu", i, source_index, dest_index); } } @@ -161,10 +162,10 @@ void GCBridge::log_handle_context (JNIEnv *env, HandleContext *ctx) noexcept jclass java_class = env->GetObjectClass (handle); if (java_class != nullptr) { char *class_name = Host::get_java_class_name_for_TypeManager (java_class); - log_info (LOG_GC, "gref {:#x} [{}]", reinterpret_cast (handle), class_name); + log_infof (LOG_GC, "gref 0x%" PRIxPTR " [%s]", reinterpret_cast (handle), optional_string (class_name)); free (class_name); env->DeleteLocalRef (java_class); } else { - log_info (LOG_GC, "gref {:#x} [unknown class]", reinterpret_cast (handle)); + log_infof (LOG_GC, "gref 0x%" PRIxPTR " [unknown class]", reinterpret_cast (handle)); } }