-
Notifications
You must be signed in to change notification settings - Fork 576
[NativeAOT] Migrate GC bridge logging to printf #12211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: jonathanpeppers-native-printf-logging-next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #include <cerrno> | ||
| #include <cinttypes> | ||
| #include <pthread.h> | ||
| #include <semaphore.h> | ||
|
|
||
|
|
@@ -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<intptr_t> (handle), class_name); | ||
| log_infof (LOG_GC, "gref 0x%" PRIxPTR " [%s]", reinterpret_cast<uintptr_t> (handle), optional_string (class_name)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 💡 Native C++ — Nice correctness improvement: switching the handle from Rule: Use unsigned width-matched types for pointer hex formatting |
||
| free (class_name); | ||
| env->DeleteLocalRef (java_class); | ||
| } else { | ||
| log_info (LOG_GC, "gref {:#x} [unknown class]", reinterpret_cast<intptr_t> (handle)); | ||
| log_infof (LOG_GC, "gref 0x%" PRIxPTR " [unknown class]", reinterpret_cast<uintptr_t> (handle)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 Native memory — Good, necessary change: wrapping
class_nameinoptional_string()guards the%sconversion.Host::get_java_class_name_for_TypeManager()genuinely returnsnullptron several paths (null/failedClass.getName, OOM on UTF8 conversion — seehost-shared.cc), and passing a rawnullptrto a printf%sis undefined behavior (crash on most C libraries), whereas the oldstd::format{}on achar*silently formatted it. This migration is more robust than the code it replaces, not just equivalent.Rule: Guard printf
%sagainst nullptr (repooptional_stringconvention)