Skip to content

[TrimmableTypeMap] Java.Interop bump and update to ValueManagers and TypeManagers#11799

Open
simonrozsival wants to merge 21 commits into
mainfrom
dev/simonrozsival/trimmable-typemap-core
Open

[TrimmableTypeMap] Java.Interop bump and update to ValueManagers and TypeManagers#11799
simonrozsival wants to merge 21 commits into
mainfrom
dev/simonrozsival/trimmable-typemap-core

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

Bumps external/Java.Interop and aligns Mono.Android's reflection-based type and value managers with the new base-class contracts. The Java.Interop bump relaxes the [DynamicallyAccessedMembers] (DAM) requirements on the virtual members of JniRuntime.ReflectionJniTypeManager / JniRuntime.ReflectionJniValueManager, so the Mono.Android overrides no longer need to repeat those annotations and instead rely on targeted trimmer/AOT suppressions.

This is a standalone slice of #11617 with no dependency on the trimmable type-map scanner/emitter or array codegen work.

Changes

  • external/Java.Interop8d544738a (from 70493645c).
  • Drop now-redundant [DynamicallyAccessedMembers] annotations from the overrides in AndroidTypeManager, ManagedTypeManager, and TrimmableTypeMapTypeManager (GetInvokerTypeCore, GetTypeForSimpleReference, RegisterNativeMembers, ActivatePeer), replacing them with [UnconditionalSuppressMessage] where the trimmer still needs reassurance.
  • JavaMarshalValueManager now extends JniRuntime.ReflectionJniValueManager directly. It is marked sealed and carries [RequiresDynamicCode] / [RequiresUnreferencedCode], uses the base EnsureNotDisposed () helper, and drops its own dispose tracking and ActivatePeer override.
  • Remove the superseded AndroidReflectionJniValueManager and SimpleValueManager (and their Mono.Android.csproj entries).
  • JNIEnvInit.CreateValueManager creates the value manager through a local helper with the appropriate trimming/AOT suppressions for both the CoreCLR and NativeAOT paths.
  • No NativeAOT default change; the trimmable type/value managers are not part of this PR.

Tests / baselines

  • Update the API-compatibility baseline: Android.Graphics.ColorValueMarshaler.CreateGenericValue's targetType parameter no longer carries a DAM attribute (inherited from the Java.Interop base-class change).
  • Refresh SimpleDotNet CoreCLR/NativeAOT apkdesc size baselines and the NativeAOT BuildHasNoWarnings count, plus BuildTest2.

Context

Carved out of #11617. JavaMarshalRegisteredPeers extraction already merged via #11750. The trimmable managers, scanner/emitter, manifest, and R8 changes ship in their own PRs (#11749/#11751/#11753/#11769/#11794/#11796/#11798).

Mono.Android compiles cleanly (0 errors).

@simonrozsival simonrozsival added copilot `copilot-cli` or other AIs were used to author this trimmable-type-map labels Jun 29, 2026
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-typemap-core branch from 45c8058 to 0d7a2a0 Compare June 29, 2026 08:50
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-typemap-core branch from 3f0d176 to 0021abf Compare June 29, 2026 09:14
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Reflection-free TrimmableTypeMapType/ValueManager (opt-in) [TrimmableTypeMap] CoreCLR JavaMarshal value-manager split + Java.Interop bump Jun 29, 2026
@simonrozsival simonrozsival marked this pull request as ready for review June 29, 2026 11:08
Copilot AI review requested due to automatic review settings June 29, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 runtime interop layer to align with the newer Java.Interop value-manager shape by splitting the CoreCLR “JavaMarshal” value-manager behavior into a dedicated CoreClrJavaMarshalValueManager and extracting shared helpers, while removing superseded value-manager implementations.

Changes:

  • Introduces CoreClrJavaMarshalValueManager (reflection-backed) and JavaMarshalValueManagerHelper for shared peer-type resolution and cast checking.
  • Removes the old JavaMarshalValueManager, SimpleValueManager, and AndroidReflectionJniValueManager implementations and updates runtime wiring (JNIEnvInit) and project compilation items accordingly.
  • Adjusts trimming/DAM annotations and api-compat acceptable breakage expectations related to removed DynamicallyAccessedMembers attributes.
Show a summary per file
File Description
tests/api-compatibility/acceptable-breakages-vReference-net11.0.txt Updates acceptable breakages for removed DAM attribute on ColorValueMarshaler.CreateGenericValue.
src/Mono.Android/Mono.Android.csproj Removes old value manager compile items; adds new helper + CoreCLR value manager compile items.
src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMapTypeManager.cs Removes DAM annotations/suppressions and keeps typemap-based type lookups.
src/Mono.Android/Microsoft.Android.Runtime/ManagedTypeManager.cs Refactors invoker lookup implementation; now directly uses Assembly.GetType/MakeGenericType.
src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManagerHelper.cs Adds shared helper for peer-type normalization and assignability/cast checking.
src/Mono.Android/Microsoft.Android.Runtime/CoreClrJavaMarshalValueManager.cs Adds new reflection-backed CoreCLR value manager implementation.
src/Mono.Android/Android.Runtime/JNIEnvInit.cs Updates value-manager selection to return CoreClrJavaMarshalValueManager for CoreCLR/NativeAOT runtime feature switches.
src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs Removes DAM annotation from CreateGenericValue parameter.
src/Mono.Android/Android.Runtime/AndroidRuntime.cs Removes now-unneeded DAM constants/annotations and adjusts trimming suppressions.
src/Mono.Android/Android.Graphics/Color.cs Removes DAM annotation from ColorValueMarshaler.CreateGenericValue and reformats signature.
src/Mono.Android/Android.App/IntentFilterAttribute.Partial.cs Switches file to #nullable enable.
src/Mono.Android/Microsoft.Android.Runtime/SimpleValueManager.cs Removes obsolete value manager implementation.
src/Mono.Android/Microsoft.Android.Runtime/JavaMarshalValueManager.cs Removes superseded value manager implementation.
src/Mono.Android/Microsoft.Android.Runtime/AndroidReflectionJniValueManager.cs Removes superseded reflection value manager base implementation.

Copilot's findings

  • Files reviewed: 15/15 changed files
  • Comments generated: 2

Comment thread src/Mono.Android/Microsoft.Android.Runtime/ManagedTypeManager.cs
Comment thread src/Mono.Android/Android.Runtime/JNIEnvInit.cs
simonrozsival and others added 10 commits June 29, 2026 15:24
Fixes CS0246: 'JavaMarshalValueManager' could not be found. The default
value manager now resolves to the internal CoreClrJavaMarshalValueManager
(accessible via InternalsVisibleTo), matching the pattern in JNIEnvInit.
Suppress the correct trimming warnings (IL2026/IL3050) instead of IL3000.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…alueManager

CreatePeerInstance only walked the Java superclass chain, so a Java object
returned through a base-interface signature (e.g. an anonymous class that
implements a derived interface) was marshalled to the base interface's
invoker instead of the most-derived interface proxy.

When targetType is an interface, also enumerate the Java class's interfaces
(recursively into super-interfaces) and select the most-derived registered
.NET type assignable to targetType, mirroring the interface-walk already used
by TrimmableTypeMap.GetProxyForJavaObject.

Fixes JavaInterfaceLookup_BaseInterfaceReturnType_UsesDerivedInterfaceProxy,
TrustManagerFactory_GetTrustManagers_ReturnsIX509TrustManager and the
dependent ServerCertificateCustomValidationCallback_* tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… managers

Extract the Class.getInterfaces() recursive walk into a shared
JavaInterfaceHierarchy.FindFirst helper and use it from both
CoreClrJavaMarshalValueManager.CreatePeerInstance and
TrimmableTypeMap.TryMatchInterfaces, removing the duplicated JNI plumbing
(getInterfaces method id + traversal) from both.

No behavior change; consolidates the interface-derived-proxy resolution
added in the previous commit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The value-manager/type-manager split reduces the IL3050 AOT-analysis
warnings a basic NativeAOT app produces from 10 to 6: three distinct
warnings (reflection-backed ManagedTypeManager ctor, JNIEnv.MakeArrayType,
JNINativeWrapper.CreateDelegate), each surfaced twice in the MSBuild summary.
Count verified from build.log of the apk and aab NativeAOT runs in CI
build 1485907.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The value-manager/type-manager split shrinks the release arm64 app:
- NativeAOT: libUnnamedProject.so -10.87%, package 2,474,779 -> 2,286,363 B
- CoreCLR: libassembly-store.so -7.19%, package 7,497,147 -> 7,312,827 B

apkdiff flags these via --descrease-is-regression, so refresh the reference
descriptions. New .apkdesc files taken from the apk/aab BuildReleaseArm64
test attachments in CI build 1485907.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mono.Android.csproj uses an explicit <Compile> item list, so the new
JavaInterfaceHierarchy.cs was not compiled, causing CS0103 'JavaInterfaceHierarchy
does not exist' in TrimmableTypeMap.cs and CoreClrJavaMarshalValueManager.cs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…mmable-typemap-core

# Conflicts:
#	src/Mono.Android/Mono.Android.csproj
#	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] CoreCLR JavaMarshal value-manager split + Java.Interop bump [TrimmableTypeMap] Java.Interop bump and update to ValueManagers nad TypeManagers Jun 30, 2026
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Java.Interop bump and update to ValueManagers nad TypeManagers [TrimmableTypeMap] Java.Interop bump and update to ValueManagers and TypeManagers Jun 30, 2026
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.

2 participants