[flaky-ci] Isolate JavaSideActivation GREF leak check - #12716
Conversation
Warm and amplify the Java-side activation path so process-wide GREF noise does not cause exact-count flakes while per-call leaks remain strongly detectable.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ Needs Changes
Findings: 0 errors, 1 warning, 0 suggestions.
The repeated activation strategy preserves the peer-identity and constructor assertions while making a per-call leak much easier to distinguish from ambient process drift. However, the new cleanup helper introduces a final collection without a corresponding managed-finalizer wait, so the sampled GREF count can still include peers awaiting finalization; I left the required ordering fix inline.
CI build #1586961 is red because MSBuild Emulator Tests macOS > Tests > MSBuild+Emulator 7 reached the 180-minute cap. This appears unrelated to this change: Xamarin.Android.JcwGen-Tests is assigned to Package Tests, and both Package Tests APK lanes passed.
Generated by Android PR Reviewer for #12716 · gpt56 · 141.8 AIC · ⌖ 5.5 AIC · ⊞ 27.7K
Comment /review to run again
Ensure the legacy Android value manager's CollectPeers GC completes finalization before sampling the process-wide GREF count.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully! Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "azcliprod.blob.core.windows.net"See Network Configuration for more information.
|
There was a problem hiding this comment.
The revised test preserves the activation/identity coverage and now waits for finalization after CollectPeers(). I left one non-blocking suggestion to reduce redundant warm-up work.
CI is currently red: the Linux Build, macOS Build, and Windows Build & Smoke Test checks failed in Azure DevOps build 1587821. Detailed failure logs require Azure DevOps authentication that was unavailable in this review run, so those failures could not be classified as PR-related or infrastructure-related.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
azcliprod.blob.core.windows.net
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
network:
allowed:
- defaults
- "azcliprod.blob.core.windows.net"See Network Configuration for more information.
Generated by Android PR Reviewer for #12716 · gpt56 · 121.9 AIC · ⌖ 8.9 AIC · ⊞ 25.7K
Comment /review to run again
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Run the process-wide GREF assertion in a dedicated category-filtered instrumentation process, matching the isolation strategy in #12709. Require no positive net growth after amplification and retain a control that proves the helper detects live global references. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The updated leak-check helper should synchronize JNI GC bridge processing before sampling GlobalReferenceCount, and there’s also a new formatting inconsistency that should be corrected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs — CollectGarbage() only waits for managed finalizers; on CoreCLR/NativeAOT the JNI GC… |
|
tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs — ❌ error: This line uses JavaCast<ConstructorTest>() without the repo-standard space before (,… |
What changed in this PR
This PR quarantines the BindingTests.JavaSideActivation process-wide JNI global-reference (GREF) leak assertion into an explicit JniReferenceLeak category and adds a dedicated CI lane that runs only those leak checks in a fresh JcwGen instrumentation process to eliminate shared-process noise.
Changes:
- Adds
IncludeCategoriesplumbing (MSBuild → runtimeconfig →AppContext) so the JcwGen instrumentation runner can filter tests by category. - Reworks
JavaSideActivationinto an explicit, amplified (100-iteration) “no sustained positive GREF growth” leak check, plus a retained-GREF control test. - Adds a dedicated
apk-instrumentationCI invocation to run onlyJniReferenceLeak-categorized JcwGen tests.
| File | Description |
|---|---|
| tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj | Emits IncludeCategories into runtimeconfig via RuntimeHostConfigurationOption. |
| tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/TestInstrumentation.cs | Reads IncludeCategories from AppContext and exposes it to the test runner for category filtering. |
| tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs | Converts the flaky single-snapshot check into an explicit, amplified leak test with a retained-reference control. |
| build-tools/automation/yaml-templates/stage-package-tests.yaml | Adds a dedicated CI lane to run only the JcwGen JniReferenceLeak category in an isolated process. |


Summary
JavaSideActivationGREF check as an explicitJniReferenceLeaktestWhy
BindingTests.JavaSideActivationcompared the process-global JNI GREF count around one activation in a shared device-test process. It failed in builds 1577025, 1578128, 1581740, and 1583153 with deltas of +1, +6, +3, and +4; every failure ended at 101 GREFs from a different lower baseline. The affected jobs passed when rerun, which points to one-time or ambient shared-process reference creation rather than a stable per-call leak.This now follows the isolation strategy from #12709. Both PRs use the
JniReferenceLeakcategory,[Explicit]default exclusion, a fresh instrumentation process, 100 warmup and measured operations, and a retained-GREF control. This PR needs a separate JcwGen invocation because its Java-side activation fixture and generated binding types exist only in the JcwGen test application.Isolation removes the need for the previous
+10tolerance. The focused lane allows no positive net GREF growth, while 100 measured activations preserve a strong signal for the knownTypeManager.Activateregression that leaked three GREFs per activation.Validation
JniReferenceLeakcategory on API 35 emulator: 2 passed, 0 failed, 0 skippedgit diff --checkTracks #12704
Addresses #12031