Repository navigation
[Java.Interop] Extend peer cleanup regression coverage - #13292
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the peer-cleanup regression coverage and disposal-contract documentation changes.
No open issues 🎉
What changed in this PR
Adds regression coverage for existing Java.Interop peer-cleanup fixes related to #13290 and documents their disposal contract. Production behavior and release branches are unchanged.
Changes:
- Expands peer-lifetime coverage from 30 to 49 cases, including unregistered disposal, aliases, throwing callbacks, and reconstructed references.
- Adds the
Android.Graphics.Rectreproduction and separate JNI-reference deletion checks. - Documents unregistered-peer cleanup and preservation of another registered wrapper.
| File | Description |
|---|---|
| tests/Mono.Android-Tests/Java.Interop-Tests/Java.Interop/JavaPeerControlBlockTests.cs | Extends disposal, finalization, native-block, and JNI-reference regression coverage. |
| external/Java.Interop/src/Java.Interop/Documentation/Java.Interop/IJavaPeerable.xml | Clarifies the existing unregistered-peer disposal and cleanup contract. |
Review effort: Balanced
Backport only the unregistered-disposal correction from c663cd1 (#12772), without its peer-identity and activation changes. DisposePeerUnlessReferenced() bypasses Disposed()/Dispose(true) when it calls the private reference-deletion helper. JavaObject and JavaException then retain their native control blocks after the JNI reference is cleared and finalization is suppressed. Use the public DisposePeer(value) path so managed disposal precedes normal cleanup. Add a distinct JavaVMFixture-based fixture for this branch's host JVM and Android inclusion paths. Cover valid-reference callback entry, native-block release, registered no-ops, alias winners, throwing callbacks and retry, repeated disposal, exact Rect disposal, and separate warmed global-reference deletion checks. The source-built Release SDK passes 12 host-JVM tests and 9 ordinary plus 7 dedicated GREF tests on each of CoreCLR and NativeAOT. The original helper produces exactly 6 host and 7 device failures; restore the production correction before repeating positive validation. Complement the finalization backport in #13294 without duplicating its implementation or JavaPeerControlBlockTests fixture. Refs #13290, #13292, #13294 Co-authored-by: Copilot App <[email protected]> Copilot-Session: 97270e0d-9fba-4a8b-8a04-9b7c25e1cd21
Context: #13290 Main already contains the production fixes in e5b44a4 and c663cd1. Add coverage and document the existing unregistered-disposal contract. Add 19 peer-lifetime cases for unregistered disposal and callbacks. Cover native-block release, alias ownership, exceptions, and JNI handles. Extend reconstruction checks to registered finalization callbacks. Source-built Release CoreCLR and NativeAOT each pass all 49 fixture cases. The old disposal bypass produces seven expected regression failures. Restore the correct production path and repeat positive validation. No production behavior changes or servicing backports are included. Co-authored-by: Copilot App <[email protected]> Copilot-Session: f7772f6f-f6e3-4b4a-b9f2-5abe3f7fd82f
1e0e0ab to
8b99f07
Compare
|
@dalexsoto review |
|
In response to @simonrozsival's request: I cannot yet substantiate a complete formal review of this revision: the read-only review specialist returned a no-issues recommendation but did not preserve the required changed-file and managed/native peer-lifetime integration coverage, current-target assessment, or separate final independent-blocker-pass evidence. The two-file source boundary and the specifically requested implementation dependencies are retained immutably, but one lossless handoff-recovery attempt still produced no evidence artifact or detailed handoff. A recommendation alone is not being treated as complete coverage or approval. This is a review-evidence handoff limitation, not a reported defect in the PR. I am deferring the formal review until that precise coverage evidence is available; no builds, tests, generators or devices were run. |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ LGTM — no blocking code findings
Findings: 0 errors, 0 warnings, 1 optional suggestion (inline).
Reviewed both changed files in full and traced construction, registration, managed disposal, finalization, and native control-block cleanup through the current runtime implementation. The PR adds regression coverage and documentation without changing production behavior. The valid-reference callback assertions, alias preservation checks, throwing-disposal retry, and exact Rect sequence all match the existing implementation. JNI-reference counting remains correctly isolated behind the dedicated JniReferenceLeak category; the documented 43 ordinary plus 6 dedicated peer-control-block cases matches the source.
CI: All 42 checks on reviewed head 8b99f0746b4f00db7045b59eec120195ef861b25 report success, including the aggregate Azure DevOps dotnet-android check for build 1663768. Direct Azure build/timeline verification was unavailable because az devops invoke required authentication, so this review does not independently certify Azure job/test details. The CoreCLR/NativeAOT device runs and negative-control results described in the PR were not rerun during this review.
Generated by Android PR Reviewer for #13292 · copilot · gpt61 · 30.3 AIC · ⌖ 7.53 AIC · ⊞ 19.4K
Comment /review to run again
| var peer = CreatePeer (exception, ref reference, JniObjectReferenceOptions.None, observation); | ||
| var reference = registered ? local : default; | ||
| var options = registered ? JniObjectReferenceOptions.Copy : JniObjectReferenceOptions.None; | ||
| var peer = CreatePeer (exception, ref reference, options, observation); |
There was a problem hiding this comment.
🤖 💡 Testing — Consider asserting the initial registry state before invoking FinalizePeer: PeekPeer(local) should be peer when registered is true and null otherwise. The post-callback assertions prove that reconstruction registers the peer, but do not distinguish whether the initially registered case actually exercised removal of an existing registration. An explicit setup assertion would keep these new cases from silently becoming duplicates of the unregistered path if construction/registration behavior changes.
{Rule: Test assertions must be specific; test edge cases}
Refs #13290.
mainalready contains both production corrections relevant to this issue:e5b44a4186(#13016) releases invalid native control blocks after finalization callbacks, andc663cd110f(#12772) routes unregistered disposal through the normal managed-disposal path. This PR adds regression coverage and documents that existing contract; it does not change production behavior or service the affected release branches.Extend
JavaPeerControlBlockTestsfrom 30 to 49 cases:Java.Interop.JavaObjectandJava.Interop.JavaExceptionafter unregistration, including aliases whose registered wrapper must remain usable, registered-peer no-op disposal, callback entry with a valid JNI reference, repeated disposal, and retry after a managed disposal callback throws.Android.Graphics.Rect.UnregisterFromRuntime()/DisposeUnlessReferenced()sequence from the issue, and check JNI-reference deletion separately in the dedicatedJniReferenceLeakrun.Document that unregistered peers receive normal managed disposal, release their JNI reference and native block before finalization is suppressed, and do not invalidate another registered wrapper for the same Java instance.
Local validation
Built the in-tree Release SDK and tested on an Android 15/API 35 ARM64 emulator. The source-pinned SDK is
12.0.100-alpha.1.26523.103; these tests targetnet11.0-android, using the source-built Android pack37.99.0and runtime packs11.0.0-preview.7.26381.103, not the installed RC2 Android workload.Both
make prepare CONFIGURATION=Releaseandmake leeroy CONFIGURATION=Release MSBUILD_ARGS='-v:minimal -m:4 -nr:false'passed.leeroyincludes the additional API-level bindings before local workload configuration.PeerControlBlockJniReferenceLeakPeerControlBlockJniReferenceLeakEach dedicated reference run includes six peer-control-block cases and two existing class-lookup checks. The actual TRX results contain the same 49 peer-lifetime case names on both runtimes: 102 passing results in total, including the four ancillary checks.
Negative control: Temporarily restoring only the old
DisposePeerUnlessReferenced()call to privateDisposePeer(h, value), then rebuilding the SDK and rerunningPeerControlBlock, produced exactly seven expected failures: two missing throwing callbacks, four missing managed-disposal callbacks, and the retained native-block pointer in theRectreproduction. The correct production source was restored byte-for-byte, the SDK rebuilt, and both CoreCLR categories passed again. No mutation remains in this PR.Exact successful build/install and test commands
Commands ran with isolated SDK, JDK, NDK, and NuGet directories;
AndroidNdkDirectorypoints to the prepared local NDK. All build/install commands below passed. The test outcomes are listed in the table above.SDK preparation and build:
make prepare CONFIGURATION=Release make leeroy CONFIGURATION=Release MSBUILD_ARGS='-v:minimal -m:4 -nr:false'CoreCLR lifetime cases:
CoreCLR dedicated reference cases:
NativeAOT lifetime cases:
NativeAOT dedicated reference cases:
The scoped clean passed and was needed because the first incremental NativeAOT category switch reran the ordinary category. That run was not counted as dedicated reference validation; the clean rebuild produced the verified eight-case result.
Coverage is limited to Android 15 ARM64 on the current source-built CoreCLR and NativeAOT implementations. These results do not validate .NET 10 servicing or a future .NET 11 backport.
Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include: