Skip to content

[NativeAOT] Migrate shared GC logging to printf#12210

Open
jonathanpeppers wants to merge 3 commits into
dev/simonrozsival/nativeaot-runtime-printf-loggingfrom
jonathanpeppers-native-printf-logging-next
Open

[NativeAOT] Migrate shared GC logging to printf#12210
jonathanpeppers wants to merge 3 commits into
dev/simonrozsival/nativeaot-runtime-printf-loggingfrom
jonathanpeppers-native-printf-logging-next

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Continue the printf-style native logging migration by converting the remaining formatted diagnostics in the shared GC bridge and logger setup paths compiled into the NativeAOT host.

Base/dependency: This PR depends on #12148 and targets dev/simonrozsival/nativeaot-runtime-printf-logging so the review diff remains limited to this batch. It reuses the canonical shared printf declarations established by #12155.

Part of #12139.

Scope

  • migrate temporary-peer capacity and GC cleanup summary diagnostics in bridge-processing.cc;
  • migrate debug-only missing Java method diagnostics while preserving null-safe class-name output;
  • migrate reference-log file open and invalid-path diagnostics in logger.cc;
  • return static string-segment error messages as C strings for direct %s logging;
  • remove six std::format-style logging instantiations from NativeAOT-reachable shared sources.

Behavior preservation

  • logging categories and existing debug/category gates are unchanged;
  • size_t values use %zu;
  • raw nullable class names continue through optional_string();
  • non-owning path and file-kind views use bounded %.*s output;
  • static string-segment error messages use %s without an intermediate std::string_view;
  • message text, punctuation, source locations, and control flow are unchanged;
  • warning and error diagnostics remain unconditional, while debug and info diagnostics retain helper-level category gating.

Non-goals

  • This PR does not change the logging implementation or declarations.
  • It does not migrate the nearby gref std::format strings passed to OSBridge::_monodroid_gref_log; those feed a separate file/log pipeline and require a dedicated API design.
  • It does not touch formatting outside NativeAOT-reachable shared sources.

Validation

  • dotnet-local.cmd build src\native\native-nativeaot.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a
  • dotnet-local.cmd build src\native\native-clr.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a
  • git diff --check
  • focused review of printf types, category gating, null handling, bounded string views, and control flow

Convert the remaining std::format-style GC bridge and logger diagnostics compiled into the NativeAOT host to the canonical printf logging helpers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb
Copilot AI review requested due to automatic review settings July 22, 2026 19:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the NativeAOT printf-style logging migration by converting remaining std::format-style formatted diagnostics in NativeAOT-reachable shared sources (GC bridge paths and reference-log setup) to the log_*f() printf helpers, while preserving existing category gating and null-safe string handling.

Changes:

  • Converted GC bridge diagnostics in bridge-processing.cc to log_*f() with %zu for size_t and %s via optional_string() for nullable class names.
  • Converted reference-log file open and invalid-path diagnostics in logger.cc to log_*f() using bounded %.*s formatting for std::string_view.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/native/clr/runtime-base/logger.cc Migrates reference-log file path diagnostics from {} formatting to bounded printf-style logging.
src/native/clr/host/bridge-processing.cc Migrates GC bridge temporary-peer/local-capacity and GC cleanup summary diagnostics to printf-style logging.

Return static segment error messages as C strings so printf logging can consume them directly without a string_view.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

Clean, well-scoped continuation of the printf-style native logging migration. I verified the changes independently against the full source before reading the description.

Verification highlights:

  • bridge-processing.ccmap_capacity, total, and alive are all size_t (lines 15, 580–581), so %zu is the correct specifier. optional_string(class_name) returns const char*, matching %s. Debug-only gating (#if ...) around the missing-method diagnostics is preserved.
  • logger.ccpath and file_kind are std::string_view; the %.*s + static_cast<int>(len) + .data() pattern is the correct way to print a non-null-terminated view. to_string(file_name.error()) now yields const char*, matching %s.
  • strings.hhto_string(string_segment_error) return-type change from std::string_view to const char* has exactly one caller (logger.cc:201), which is updated correctly. No other consumers depend on the old string_view return.
  • All log_*f overloads used exist in shared/log_functions.hh with __attribute__((format(printf,...))), so the compiler validates the format strings — mismatches would fail the build.
  • Message text, categories, punctuation, and control flow are unchanged, as claimed.

CI: dotnet-android completed neutral (not a failure); license/cla passed. No PR-caused failures.

Counts: 0 ❌ · 0 ⚠️ · 1 💡 (optional constexpr on to_string). Nice, mechanically-faithful migration.

Generated by Android PR Reviewer for #12210 · 65.9 AIC · ⌖ 12.8 AIC · ⊞ 6.8K
Comment /review to run again

Comment thread src/native/common/include/runtime-base/strings.hh Outdated
Express the static string-segment error mapping as a compile-time function now that it returns string literals.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb
@jonathanpeppers jonathanpeppers added the drop-libcpp Work to remove the libc++ dependency from Android NativeAOT label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drop-libcpp Work to remove the libc++ dependency from Android NativeAOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants