Repository navigation
[native] Move logging category parsing into shared host startup - #13003
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes critical native startup wiring for two runtimes without final linking or on-device validation.
Review effort: Balanced
Findings: None
What changed in this PR
Moves native logging-category initialization from the obsolete Logger wrapper into shared host startup code while preserving CoreCLR and NativeAOT behavior.
Changes:
- Relocates category parsing to
HostCommon. - Removes obsolete logger files and build entries.
- Updates direct includes and NativeAOT incremental inputs.
| File | Description |
|---|---|
src/native/nativeaot/include/runtime-base/internal-pinvokes.hh |
Uses logging type declarations directly. |
src/native/nativeaot/host/host.cc |
Initializes logging through HostCommon. |
src/native/nativeaot/host/host-jni.cc |
Removes obsolete logger dependency. |
src/native/nativeaot/host/host-environment.cc |
Removes obsolete logger dependency. |
src/native/nativeaot/host/CMakeLists.txt |
Removes deleted logger source. |
src/native/native.targets |
Tracks shared initializer inputs. |
src/native/common/include/runtime-base/system-loadlibrary-wrapper.hh |
Includes logging functions directly. |
src/native/common/include/runtime-base/mainthread-dso-loader.hh |
Includes logging functions directly. |
src/native/clr/runtime-base/logger.cc |
Deletes obsolete parser wrapper. |
src/native/clr/runtime-base/CMakeLists.txt |
Removes deleted logger source. |
src/native/clr/include/runtime-base/util.hh |
Replaces transitive logging includes. |
src/native/clr/include/runtime-base/logger.hh |
Deletes obsolete wrapper declaration. |
src/native/clr/include/runtime-base/internal-pinvokes.hh |
Uses logging type declarations directly. |
src/native/clr/include/host/typemap.hh |
Removes unused logger dependency. |
src/native/clr/include/host/pinvoke-override-impl.hh |
Includes logging functions directly. |
src/native/clr/include/host/host-environment.hh |
Includes logging functions directly. |
src/native/clr/include/host/host-common.hh |
Declares shared logging initialization. |
src/native/clr/host/typemap.cc |
Adds its direct logging dependency. |
src/native/clr/host/host.cc |
Uses shared initialization at startup. |
src/native/clr/host/host-shared.cc |
Hosts the unchanged category parser. |
7000778 to
c55ab15
Compare
The JNI reference logging migration leaves Logger as a wrapper around startup category parsing. Move the unchanged debug.dotnet.log parser to HostCommon with a file-local helper instead of keeping a separate configuration class. Keep both hosts calling it before environment setup and runtime startup so native assembly discovery and library loading retain their early diagnostics. Remove obsolete headers and CMake sources, replace direct logging dependencies, and track the shared initializer in NativeAOT incremental-build inputs. Context: #13002 Co-authored-by: Copilot App <[email protected]>
Use a C-style static helper instead of an anonymous namespace, as requested in review. Preserve internal linkage and the existing category-matching behavior. Co-authored-by: Copilot App <[email protected]>
The category helper is only used by HostCommon initialization. Inline its comparisons as requested in review and remove the helper entirely. Keep the token-length checks and zero-result comparisons so shortened or unknown tokens still leave the category mask unchanged. Co-authored-by: Copilot App <[email protected]>
Replace manual token lengths and strncmp checks with string-view splitting and direct equality comparisons, as requested in review. Preserve exact matching, empty-token handling and immutable property data without allocating or modifying the property buffer. Co-authored-by: Copilot App <[email protected]>
Keep debugger and netlink unsupported after moving category parsing to HostCommon. Their enums and log tags were already removed in main; do not reintroduce their tokens when replaying the host cleanup. Preserve the new NativeAOT system-property initialization before logging and the existing early startup ordering in both hosts. Co-authored-by: Copilot App <[email protected]>
JNI global/local/weak-global reference diagnostics still use bespoke text formatting, files, per-operation flushing, and logcat routing even though reference accounting and GC bridge processing now run in managed code. Replace those sinks with structured events from the existing `Microsoft.Android.Runtime` EventSource. Fixes #6822. - Add independently selectable verbose reference events with numeric handles, reference kinds, counter snapshots, managed thread IDs, and explicit bridge context. Distinguish releasing local-reference ownership from JNI deletion. - Preserve counting and GREF-pressure GC behavior regardless of diagnostic enablement, including the bridge guard against recursive collection. - Remove unused reference managers, legacy P/Invokes, reference-log options and initialization ABI fields, and associated dead state. Keep native parsing for remaining non-reference categories and early startup logging; relocating that parser out of the residual `Logger` wrapper is the upper layer, #13003. - Use CoreCLR EventPipe stacks. NativeAOT traces did not supply stacks in the local experiment, so expose a separately enabled managed-stack keyword without stack-string allocation during ordinary reference collection. - Cover real JNI lifecycles/event contracts, ownership transfer, disabled-path allocation, GREF initialization limits, and stack opt-in. The existing peer-cycle test also checks bridge transitions. Remove redundant keyword permutations and handle-history reconstruction; cover collected-weak-reference serialization/filtering and stack correlation within existing cases. - Update documentation and defer host-side trace interpretation to the skill tracked separately; do not add a permanent trace-reader tool or dependency. - Merge current main, preserving its removal of legacy native typemap paths and keeping the native/managed initialization layouts aligned without the retired logging fields. Validation after review and merge-conflict resolution (2026-10-05): The local preview SDK requests unavailable .NET 10 targeting packs. Repository builds used the validation-only `CustomBeforeMicrosoftCommonTargets` override stored in session artifacts; no repository override is committed. - `./dotnet-local.sh build Microsoft.Android.slnx -v:quiet` — passed; includes native and managed runtime builds. - `./dotnet-local.sh build Microsoft.Android.slnx -t:BuildExtraApiLevels -v:quiet` — passed. - `./dotnet-local.sh build -t:ConfigureLocalWorkload build-tools/create-packs/Microsoft.Android.Sdk.proj -v:quiet` — passed. - `./dotnet-local.sh build -t:Install -c Debug tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:IncludeCategories=ReferenceTracing -p:Device=emulator-5554 -v:quiet` — passed. - From `tests/Mono.Android-Tests/Mono.Android-Tests`: `../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Debug -p:IncludeCategories=ReferenceTracing --device emulator-5554 --report-trx --results-directory ../../../bin/TestDebug/TestResults` — passed, all 10 focused CoreCLR cases. - `./dotnet-local.sh publish -c Release tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:PublishAot=true -p:IncludeCategories=ReferenceTracing -p:RuntimeIdentifier=android-arm64 -v:quiet` — passed. The initial build-only attempt failed with missing NativeAOT DGML inputs (XA4319); publishing produced the required native compilation outputs. - `./dotnet-local.sh build -t:Install -c Release tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -p:PublishAot=true -p:IncludeCategories=ReferenceTracing -p:RuntimeIdentifier=android-arm64 -p:Device=emulator-5554 -v:quiet` — passed after publishing. - From the test project directory: `../../../dotnet-local.sh test Mono.Android.NET-Tests.csproj --no-build -c Release -p:PublishAot=true -p:IncludeCategories=ReferenceTracing -p:RuntimeIdentifier=android-arm64 --device emulator-5554 --report-trx --results-directory ../../../bin/TestRelease/TestResults` — passed, all 10 focused NativeAOT cases, including event 20 stack correlation. - `./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~RuntimeEventSourceFeatureSwitch'` — passed, both enabled/disabled cases; linked-assembly inspection confirms instrumentation removal when disabled. - Earlier real CoreCLR and NativeAOT emulator traces contained reference creation/deletion/release, peer diagnostics, and bridge transitions. CoreCLR yielded application frames through EventPipe. NativeAOT opt-in stack collection produced 148 correlated stack events including application frames; ordinary `0x30` collection produced no stack-string events. - `git diff --check` — passed. Full runtime test suites and hardware-device tests were not run. ---- Pull Request [title](https://github.com/dotnet/android/blob/main/Documentation/workflow/commit-messages.md#commit-summary) and [description](https://github.com/dotnet/android/blob/main/Documentation/workflow/commit-messages.md#commit-body) should follow the [`commit-messages.md` workflow documentation](https://github.com/dotnet/android/blob/main/Documentation/workflow/commit-messages.md), and in particular should include: - [x] Useful description of *why the change is necessary*. - [x] Links to issues fixed - [x] Unit tests
c55ab15 to
e045613
Compare
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
The complete current 18-file source review, separate integration/completeness pass and independent final sweep found no blocker. Shared initialization preserves exact, allocation-free category parsing and borrowed property data, existing masks and both runtimes' startup order. NativeAOT still initializes VM/JNI/properties before parsing; CoreCLR retains parsing before environment/store initialization. Deleted-wrapper references, direct declarations, shared/static CMake linkage and NativeAOT source/header incremental tracking are consistent.
The actual API main/base boundary was used, not the historical stack comparison, and the lower PR's stamp was not treated as code-validation evidence. Exact-source build 1625633 succeeds. Author object/sanitizer checks remain attributed; this review does not claim native compilation, final linking, SDK or device execution.
The JNI reference logging migration in #13002 leaves the native
Loggerclass wrapping only startup category parsing. Move that C++ parsing intoHostCommon::init_logging_categories()in the existing shared host source, inline exact token comparisons directly in initialization, and delete the obsolete wrapper header/source and category helper.Keep category selection before environment setup and early native diagnostics in both hosts. CoreCLR retains the original call position before assembly-store discovery and
coreclr_initialize. NativeAOT preserves the current bootstrap: validate the Java VM, obtain the JNI environment and initializeAppSystemPropertiesfirst, then select logging categories and initialize the host environment. String-view comparisons preserve exact matching, unknown/empty-token behavior andallwithout allocations or modifying property data. No managed parser is introduced.Replace stale header dependencies with the declarations actually used, remove obsolete CMake source entries, and update NativeAOT MSBuild incremental inputs to track the shared initializer and header while retaining the new NativeAOT runtime-base input glob.
This is the upper layer of native stack 13021, with complete ordered membership #13002, #13003, targeting
simonrozsival-jni-reference-tracing, notmain. No issue is closed. Stack metadata and the lower branch were not modified.Rebased only the upper cleanup commits from their verified historical lower fork
a125f69b6b52c9bf25128cb1c7094c029a0dbde8onto the verified new lower headdd94f74548437df80c6e2291b9b5db4a94a5dde0, based on currentmainat1089999735d3565e96cb9b443fdf04387e165350. Old lower merge history is not retained in the upper-only range. Preservemain's legacy typemap deletions and the now-merged unused debugger/netlink/bundle cleanup from #13001: the relocated parser does not reintroduce removed tokens or category declarations. The upper-only diff contains 18 native files (62 insertions, 79 deletions) and no managed/test changes relative to the updated lower layer.Validation uses temporary session-local checks rather than adding a helper-testing framework or tests for trivial assignments. Rerun after the linear rebase:
python3 /Users/simon/.copilot/session-state/7c5dfbd3-908c-4281-a0a5-482b92c4aa9b/files/check-native-logging.py native— passed: 112 NDK clang++ C++23 object builds of the surviving affected/shared sources, CoreCLR and NativeAOT, Debug and Release, arm64-v8a/armeabi-v7a/x86_64/x86, with no compiler diagnostics. CoreCLR's generated archive-stub header is derived from a freshly compiled per-ABI native stub, not another checkout's outputs.python3 /Users/simon/.copilot/session-state/7c5dfbd3-908c-4281-a0a5-482b92c4aa9b/files/check-native-logging.py parser— passed: 32,354 original/simplified behavior comparisons against the rebased lower snapshot under host ASan/UBSan. Covers supported tokens and removed categories as unknown tokens,all, duplicates, whitespace/case, repeated separators, null/empty values, existing masks, embedded NULs, long inputs, stack-buffer properties and a read-only guard-page input.python3 /Users/simon/.copilot/session-state/7c5dfbd3-908c-4281-a0a5-482b92c4aa9b/files/check-native-logging.py wiring— passed: startup bodies match the new lower after call substitution; NativeAOT VM/JNI/property initialization before the call is byte-for-byte preserved; inherited property source/header, category declarations and log-tag table unchanged; CMake/MSBuild wiring valid; no stale wrapper references or restored typemap/internal-pinvoke sources.git diff --exit-code 'dd94f74548437df80c6e2291b9b5db4a94a5dde0' HEAD -- . ':!src/native'— passed: non-native lower-layer contents preserved exactly.git diff --check 'dd94f74548437df80c6e2291b9b5db4a94a5dde0...HEAD'— passed.git rev-list --count --merges 'dd94f74548437df80c6e2291b9b5db4a94a5dde0..HEAD'— passed, returns0: upper-only history is linear.The branch was force-pushed with an explicit lease against the verified old upper tip
70007786296f678d8982ef3f711fe4b4a2bb87a7, refreshing PR validation. Full SDK builds, final host linking and on-device runtime tests were not run in this upper checkout: it has no local built SDK. No other session's SDK/source outputs were used.