Skip to content

[TrimmableTypeMap] Use trimmable Java proxy runtime sources#11271

Open
simonrozsival wants to merge 4 commits intomainfrom
trimmable-java-proxy-object
Open

[TrimmableTypeMap] Use trimmable Java proxy runtime sources#11271
simonrozsival wants to merge 4 commits intomainfrom
trimmable-java-proxy-object

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented May 3, 2026

Summary

  • add trimmable-specific runtime jars (java_runtime_trimmable_net6.jar and java_runtime_trimmable_clr.jar) that replace Java.Interop's incompatible JavaProxyObject.java / JavaProxyThrowable.java only for _AndroidTypeMapImplementation=trimmable
  • keep the existing non-trimmable runtime jars on Java.Interop's native-registration behavior; _net6 follows the existing historical non-CoreCLR runtime jar naming (java_runtime_net6.jar), not the current .NET TFM
  • include the new trimmable jar/dex outputs in installer file lists and make java-runtime incremental builds account for java-trimmable sources
  • re-enable the affected Java.Interop tests and add focused trimmable JavaProxyObject coverage

Validation

  • dotnet build src/java-runtime/java-runtime.csproj -v:minimal
  • dotnet build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj -v:minimal
  • dotnet build src/Mono.Android/Mono.Android.csproj -v:minimal
  • MSBUILDDISABLENODEREUSE=1 ./dotnet-local.sh build tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj -c Debug -p:_AndroidTypeMapImplementation=trimmable -nr:false
  • dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal
  • trimmable device instrumentation: 900 passed, 0 failed
  • verified normal runtime jars keep native JavaProxyObject registration, trimmable runtime jars have direct Java object methods and no static native registration

Related issues

@simonrozsival simonrozsival changed the base branch from main to trimmable-typemap-startup-fixes May 3, 2026 07:22
@simonrozsival simonrozsival changed the base branch from trimmable-typemap-startup-fixes to main May 3, 2026 07:22
@simonrozsival simonrozsival changed the base branch from main to trimmable-typemap-startup-fixes May 3, 2026 07:26
@simonrozsival
Copy link
Copy Markdown
Member Author

/review

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Android PR Reviewer completed successfully!

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — Clean, well-structured change

Summary: Introduces trimmable-specific Java runtime jars that replace Java.Interop's JavaProxyObject.java / JavaProxyThrowable.java with versions that don't call ManagedPeer.registerNativeMembers(). This fixes the root cause behind #11170 by providing Java identity implementations of equals/hashCode/toString instead of native methods.

What I verified

  • _AndroidTypeMapImplementation is already in _PropertyCacheItems (line 996), so incremental builds correctly invalidate when switching typemap implementations
  • ✅ The 4-way condition matrix in _CollectRuntimeJarFilenames covers all combinations exhaustively (MonoVM × CoreCLR × default × trimmable)
  • _RuntimeOutput.AddItems metadata is properly added to Inputs for incremental build tracking
  • ✅ The Delete of stale classes.dex prevents D8 output from leaking into jars during incremental builds
  • ✅ New Java files correctly mirror the original Java.Interop implementations minus the static { registerNativeMembers() } block and native method declarations
  • ✅ Installer file lists include all 4 new artifacts (trimmable jar+dex for net6 and clr)
  • ✅ Re-enabled tests (previously excluded due to registerNativeMembers failure) are now validated by 900 passing device tests
  • ✅ New test coverage validates proxy type, object array usage, and Java identity semantics

Positive callouts

  • The RemoveItems/AddItems metadata pattern on _RuntimeOutput is a clean approach to source file swapping — it keeps the build logic centralized in the target without needing separate targets
  • Good test for JavaProxyObject_ObjectMethodsUseJavaIdentitySemantics that explicitly verifies the behavioral contract of the trimmable proxy
  • Removing 27 lines of test exclusions from NUnitInstrumentation.cs is a nice cleanup

CI

The PR is in draft status. The dotnet-android check shows neutral (not yet run). CI results should be verified before merging.

3 💡 suggestions posted inline — all documentation/clarity improvements, no required changes.

Generated by Android PR Reviewer for issue #11271 · ● 6.2M

Comment thread src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Comment thread src/java-runtime/java-runtime.targets
@simonrozsival simonrozsival added copilot `copilot-cli` or other AIs were used to author this trimmable-type-map labels May 3, 2026
@simonrozsival simonrozsival changed the title Use trimmable Java proxy runtime sources [TrimmableTypeMap] Use trimmable Java proxy runtime sources May 3, 2026
Base automatically changed from trimmable-typemap-startup-fixes to main May 4, 2026 15:17
@simonrozsival simonrozsival force-pushed the trimmable-java-proxy-object branch from 1467afa to e66930e Compare May 4, 2026 18:21
simonrozsival and others added 2 commits May 4, 2026 20:31
Add trimmable-specific java_runtime jars that replace Java.Interop's JavaProxyObject and JavaProxyThrowable sources only for the trimmable typemap path. Keep the existing runtime jars on Java.Interop's native-registration behavior and select the trimmable jars when _AndroidTypeMapImplementation is trimmable.

Re-enable the affected Java.Interop runtime tests and add focused coverage for JavaProxyObject marshaling/object methods under the trimmable typemap path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add comments documenting runtime jar selection and Java proxy identity semantics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the trimmable-java-proxy-object branch from e66930e to 0644b70 Compare May 4, 2026 18:31
@simonrozsival simonrozsival marked this pull request as ready for review May 5, 2026 09:31
Copilot AI review requested due to automatic review settings May 5, 2026 09:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the trimmable typemap path to use trimmable-specific Java runtime sources for JavaProxyObject / JavaProxyThrowable, selecting new runtime jars only when _AndroidTypeMapImplementation=trimmable, and re-enables previously excluded Java.Interop tests by adding targeted validation for the new proxy behavior.

Changes:

  • Add trimmable Java runtime proxy sources (src/java-runtime/java-trimmable/...) and build new runtime jar/dex variants for both MonoVM and CoreCLR.
  • Update MSBuild runtime-jar selection logic to choose trimmable vs non-trimmable runtime jars based on _AndroidRuntime × _AndroidTypeMapImplementation.
  • Re-enable previously excluded Java.Interop tests and add focused trimmable coverage around Java proxy marshaling and object-method semantics.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.RuntimeTests/NUnitInstrumentation.cs Removes prior trimmable exclusions now that trimmable proxy classes are provided.
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/TrimmableTypeMapTypeManagerTests.cs Adds new tests validating marshaling and Java-side JavaProxyObject behavior under trimmable typemap.
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Selects trimmable vs non-trimmable runtime jar based on runtime + typemap implementation.
src/java-runtime/java-trimmable/net/dot/jni/internal/JavaProxyThrowable.java Introduces trimmable-specific Java proxy throwable implementation.
src/java-runtime/java-trimmable/net/dot/jni/internal/JavaProxyObject.java Introduces trimmable-specific Java proxy object implementation (no native registration; identity semantics).
src/java-runtime/java-runtime.targets Builds additional trimmable runtime jar/dex outputs and improves incremental inputs / stale classes.dex cleanup.
build-tools/installers/create-installers.targets Ships the new trimmable runtime jar/dex artifacts in installers.

Comment thread src/java-runtime/java-trimmable/net/dot/jni/internal/JavaProxyObject.java Outdated
Comment thread src/java-runtime/java-trimmable/net/dot/jni/internal/JavaProxyThrowable.java Outdated
Use repository Java formatting for trimmable proxy sources and strengthen the proxy hashCode test so it compares against Java identityHashCode instead of itself.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival
Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

@copilot resolve the merge conflicts in this pull request

The merge conflicts are resolved locally:

  • TrimmableTypeMapTypeManagerTests.cs: kept both our JavaProxyObject_ObjectMethodsUseJavaIdentitySemantics test and main's new TryGetArrayType_PrimitiveLeaf_DoesNotRequireRankMapEntry test from [TrimmableTypeMap] Improve array handling #11238.
  • NUnitInstrumentation.cs: kept our HEAD version (the JavaProxyObject/JavaProxyThrowable test exclusions were removed by this PR since the trimmable runtime jar fixes those issues — discarding main's re-addition of them).

However, the push is being rejected by the Xamarin.Android-PR required status check rule (the merge commit's SHA hasn't had CI run against it yet). Could you push the branch manually or trigger CI to unblock? The local merge commit is 4ed4581.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants