Add EventPipe interop instrumentation for wrapper lifecycle and GC-bridge reachability - #12258
Open
jkoritzinsky with Copilot wants to merge 6 commits into
Open
Add EventPipe interop instrumentation for wrapper lifecycle and GC-bridge reachability#12258jkoritzinsky with Copilot wants to merge 6 commits into
jkoritzinsky with Copilot wants to merge 6 commits into
Conversation
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
jkoritzinsky
July 28, 2026 21:02
View session
jkoritzinsky
marked this pull request as ready for review
July 28, 2026 21:03
jkoritzinsky
requested review from
jonathanpeppers and
simonrozsival
as code owners
July 28, 2026 21:03
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces EventPipe instrumentation across the .NET↔Java interop layer to make wrapper lifecycle and GC-bridge reachability transitions observable in production traces via a new Java.Interop EventSource provider.
Changes:
- Added a new
Java.InteropEventSource (InteropEventSource) with stable event IDs/keywords and a documented payload schema. - Instrumented wrapper creation/release in Java.Interop value managers + Mono.Android runtime, and added GC-bridge reachability transition events with correlation fields.
- Added unit tests (Java.Interop) and runtime-facing tests (Mono.Android) plus documentation for capturing with
dotnet-trace.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/InteropEventSourceRuntimeTests.cs | Runtime tests validating lifecycle events are emitted on-device/in-runtime. |
| src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapValueManager.cs | Emits wrapper creation events for trimmable typemap value manager paths. |
| src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalRegisteredPeers.cs | Emits wrapper release + GC-bridge reachability events during bridge processing. |
| src/Mono.Android/Android.Runtime/AndroidRuntime.cs | Emits wrapper creation events for AndroidValueManager.CreatePeer. |
| external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/InteropEventSourceTests.cs | Unit tests validating EventSource emission and payload shape. |
| external/Java.Interop/src/Java.Interop/PublicAPI.Unshipped.txt | Declares new public API surface for InteropEventSource. |
| external/Java.Interop/src/Java.Interop/Java.Interop/ManagedPeer.cs | Emits JavaWrapperCreated during managed-peer construction from Java. |
| external/Java.Interop/src/Java.Interop/Java.Interop/JniRuntime.ReflectionJniValueManager.cs | Emits wrapper creation events in reflection-based value manager. |
| external/Java.Interop/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs | Emits wrapper release events during peer disposal. |
| external/Java.Interop/src/Java.Interop/Java.Interop/InteropEventSource.cs | New provider implementation + event definitions/keywords. |
| external/Java.Interop/Documentation/EventPipeInteropEvents.md | Event catalog, payload schema, and dotnet-trace collection instructions. |
Comment on lines
+3
to
+16
| The .NET ↔ Java interop layer emits EventPipe events through a single provider: | ||
|
|
||
| - **Provider name:** `Java.Interop` | ||
|
|
||
| ## Event catalog | ||
|
|
||
| | Event ID | Event name | Meaning | | ||
| |---|---|---| | ||
| | 1 | `DotNetWrapperCreated` | A managed wrapper for a Java object was created. | | ||
| | 2 | `JavaWrapperCreated` | A Java wrapper for a managed object was created. | | ||
| | 3 | `DotNetWrapperReleasedJavaReference` | A managed wrapper released its Java reference. | | ||
| | 4 | `JavaWrapperReleasedDotNetReference` | A Java wrapper released its managed reference. | | ||
| | 5 | `DotNetObjectOnlyReachableFromJava` | A managed object is only reachable from Java during bridge processing. | | ||
| | 6 | `JavaObjectOnlyReachableFromDotNet` | A Java object is only reachable from .NET during bridge processing. | |
Member
There was a problem hiding this comment.
There is some existing code in here for writing gref/lref logs. It is old and text-based. Does this replace or supplement this?
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Member
|
@copilot resolve the merge conflicts in this pull request |
…ava-interop Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Contributor
Author
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.
This adds first-class EventPipe visibility into the .NET↔Java interop layer so wrapper lifecycle and cross-runtime reachability transitions can be observed in production traces. The instrumentation covers wrapper creation/release on both sides and GC-bridge reachability state transitions with correlation data.
New interop EventSource provider
Java.InteropDotNetWrapperCreatedJavaWrapperCreatedDotNetWrapperReleasedJavaReferenceJavaWrapperReleasedDotNetReferenceDotNetObjectOnlyReachableFromJavaJavaObjectOnlyReachableFromDotNetWrapper creation instrumentation
.NET wrapper for Java objectevents from:ReflectionJniValueManager.CreatePeerTrimmableTypeMapValueManager.CreatePeerAndroidRuntime.AndroidValueManager.CreatePeerJava wrapper for .NET objectevents from:ManagedPeer.ConstructConstructPeerCorepaths where Java peer references are establishedWrapper release instrumentation
.NET wrapper releases Java referencefrom disposal/finalization paths:JniValueManager.DisposePeerJavaMarshalRegisteredPeers.FinalizePeerJava wrapper releases .NET referencefrom registered-peer removal:JavaMarshalRegisteredPeers.RemovePeerGC-bridge reachability instrumentation
JavaMarshalRegisteredPeersbridge processing:.NET object only reachable from JavaJava object only reachable from .NETcomponentIndex,contextIndex,contextPointer) for trace-side reconstruction.Low-overhead event gating
InteropEventSource.IsEnabled()before payload-heavy work (e.g., Java type resolution) to avoid unnecessary overhead when no listener is attached.API, tests, and docs
InteropEventSource.dotnet-traceusage documentation.