[CoreCLR/NativeAOT] Migrate JNI reference logging to printf#12150
Open
simonrozsival wants to merge 3 commits into
Open
Conversation
Format gref/lref records once with C varargs, preserve logcat/file output, and remove std::format and ranges-heavy splitting from OSBridge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the NativeAOT/CoreCLR printf-style logging migration by updating OSBridge’s JNI reference logging to avoid std::format (and std::views::split) while preserving the existing dual-destination behavior (logcat + optional files).
Changes:
- Introduces a private
OSBridge::log_itf()helper that formats a single reference-log record viavasprintf()and forwards the same formatted line to logcat/file paths. - Migrates gref/weak-gref/lref create/delete reference event logging to printf formatting (
%d,%p,%c,%s) with compile-time format checking. - Replaces ranges-based stack-trace splitting with an in-place
std::string_viewnewline scan that preserves empty/trailing segments and writes non-NUL-terminated segments safely using explicit lengths.
Show a summary per file
| File | Description |
|---|---|
| src/native/clr/include/host/os-bridge.hh | Updates the private logging helper signatures to use std::string_view and adds a printf-checked log_itf() declaration. |
| src/native/clr/host/os-bridge.cc | Implements log_itf() using vasprintf(), migrates reference event logging away from std::format, and replaces ranges-based stack-trace splitting with a manual string_view scan. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
This was referenced Jul 17, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continue the printf-style logging migration introduced by #12140 by converting shared CoreCLR/NativeAOT JNI reference logging in
OSBridge.The
src/native/clr/location is shared infrastructure: the NativeAOT host explicitly compilesclr/host/os-bridge.cc, while MonoVM uses its separatemono/monodroid/osbridge.ccimplementation. This PR therefore affects CoreCLR and NativeAOT, but not MonoVM.Base/dependency: #12140 must merge first. This PR targets
dev/simonrozsival/nativeaot-printf-loggingso its diff contains only this migration.Part of #12139.
Scope
Only two files change:
src/native/clr/host/os-bridge.ccsrc/native/clr/include/host/os-bridge.hhThis does not overlap the open sibling work:
gc-bridge.cc/.hh— worker-thread and semaphore handoff;bridge-processing.cc/.hh— temporary-peer graph storage;Changes
Format reference records once
OSBridge::log_itf()helper;vasprintf()to produce one NUL-terminated reference-log line;noexceptstd::formatpath.Migrate JNI reference events
Replace six owning
std::formatconstructions:The replacements use
%d,%p,%c, and%swith compiler format checking from the private helper declaration.Remove ranges-heavy stack-trace splitting
std::views::splitwith an in-placestd::string_viewnewline scan;%.*s/%s.Responsibility boundary with #12141
GCBridge([NativeAOT] Use POSIX primitives for GC bridge processing #12141) controls when and where a bridge round runs: callback handoff, worker thread, semaphore synchronization, and Java GC triggering.OSBridge(this PR) tracks and logs JNI reference events: gref/weak-gref counters, reference creation/deletion lines, and optional stack traces.The classes call each other through existing stable helpers, but this PR changes no GC scheduling, graph processing, callback lifecycle, or synchronization state.
Behavior preserved
LOG_GREF/LOG_LREFbefore formatting;Measured impact
Android arm64 Release NativeAOT
os-bridge.ccobject, compiled with the repository-generated production NDK command:os-bridge.cc.oThe remaining C++ string symbols come from other shared header functionality; the six
std::formatreference-log instantiations are removed.Non-goals
osbridge.ccchanges;Validation
git diff --check;