[TrimmableTypeMap] Reflection-free TrimmableTypeMapType/ValueManager#11801
[TrimmableTypeMap] Reflection-free TrimmableTypeMapType/ValueManager#11801simonrozsival wants to merge 37 commits into
Conversation
9f999e1 to
4632939
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
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>
…TypeMap value-manager branch
Adds TrimmableTypeMapValueManager + reflection-free TrimmableTypeMapTypeManager and wires opt-in selection (RuntimeFeature.TrimmableTypeMap) in JNIEnvInit. Builds on the CoreCLR JavaMarshal split. Default stays managed; depends on array-codegen (#11753) and other slices to be fully functional at runtime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Revert Color.cs/JavaProxyThrowable.cs formatting, RuntimeFeature feature-gates (suppressions cover it), and the ITypeMap array-proxy rename (deferred to array PR). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The trimmable typemap path now uses the dedicated TrimmableTypeMapValueManager (selected in JNIEnvInit.CreateValueManager), so the RuntimeFeature.TrimmableTypeMap branch in JavaMarshalValueManager.CreatePeer is unreachable. Remove it along with the now-unused ResolvePeerType/IsIncompatibleCast helpers; that logic lives in JavaMarshalValueManagerHelper used by the dedicated value manager. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The rebase auto-merge duplicated the JavaArrayProxy attribute class in JavaPeerProxy.cs (one terse copy from this branch, one documented copy from core); remove the duplicate. Also align JavaPeerProxy<T>.GetContainerFactory to use the JavaPeerContainerFactory<T>.Instance singleton (its constructor is private) instead of 'new'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
74e5d3d to
e15e6b9
Compare
This file was inadvertently reverted to #nullable disable during the rebase onto main; it carries nullable reference annotations and main (#11799) had it as #nullable enable. Restore to match. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- TrimmableTypeMapValueManager: remove no-op Dispose(bool) override (sealed class) and use ArgumentNullException.ThrowIfNull in ConstructPeerCore. - TrimmableTypeMapTypeManager: promote GetBuiltInTypeForSimpleReference to a class-level method (drops empty XML doc tags) and make GetTypeForSimpleReference resolve the first match directly instead of allocating the iterator/enumerator. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the hard-coded (JniObjectReferenceOptions)(1<<1)/(1<<2) literals for DisposeSource and DoNotRegisterTarget with constant expressions derived from the public CopyAndDispose / CopyAndDoNotRegister members, so the bits stay pinned to Java.Interop's public ABI instead of duplicating magic numbers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Concrete types that supply their own Java peer via [JniTypeSignature(GenerateJavaPeer=false)] (DoNotGenerateAcw=true) have no activation ctor or invoker, so ModelBuilder emitted no JavaPeerProxy/TypeMapAssociation for them. At runtime TryGetJniNameForManagedType failed and 'new CrossReferenceBridge()' fell back to the generic mono.android.runtime.JavaObject peer, throwing ArrayStoreException when stored in a typed Java array. This aborted the whole CoreCLRTrimmable/NativeAOT device suites (Zero tests ran). Emit a minimal proxy + association for concrete self-peer types so the managed→Java JNI name resolves. Adds a regression test.
CoreCLRTrimmable device-test crash analysis (recording so we don't lose it)Observed on the public SymptomThe step reported, after 52s: "Zero tests ran" is misleading — it doesn't mean no tests executed, it means the test host never received a results file. What actually happenedFrom the captured logcat artifact (
It crashed with a native SIGSEGV in the CoreCLR GC, mid-test: Fault addr Why it reported 0/0/0Because the process died mid-run, the on-device instrumentation's final Follow-ups
Note: this manifested on PR #11802's validation run, but the crash is in the CoreCLR GC during an HTTP/TLS test and looks unrelated to the trimmable-typemap changes (the NativeAOT config in the same job passed). |
The [Ignore] for the crashing AndroidMessageHandlerTests .ServerCertificateCustomValidationCallback_* tests (dotnet#8608) belongs with the trimmable-typemap work; move it to dotnet#11801. This PR is now scoped to the MTP streaming-results change only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AndroidMessageHandlerTests.ServerCertificateCustomValidationCallback_* crash the test process with a native SIGSEGV (#8608), which under CoreCLR/Trimmable takes down the whole instrumentation run and drops every result. Ignore them until the native crash is diagnosed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit dd86e6f.
… base ManagedTypeManager derived from the minimal JniRuntime.JniTypeManager base, whose GetType()/GetTypes()/GetTypeSignatureCore() do not dispatch to the plural GetTypesForSimpleReference/GetSimpleReferences overrides. That left the only references to ManagedTypeMapping as dead code, so the trimmer removed the type and the managed TypeMappingStep crashed with 'Unable to find Microsoft.Android.Runtime.ManagedTypeMapping type' (IL1012 / NETSDK1144), failing every NativeAOT MSBuild test. Restore the ReflectionJniTypeManager base (as on main) so the lookup dispatch works, and re-add the singular GetTypeForSimpleReference override so both the GetType and GetTypes paths consult ManagedTypeMapping.
Summary
Adds the reflection-free
TrimmableTypeMapValueManagerandTrimmableTypeMapTypeManager, plus the opt-in wiring inJNIEnvInit(RuntimeFeature.TrimmableTypeMap) that selects them. Also includes theJavaConvertcollection-factory refactor used by the trimmable path. NativeAOT default staysmanaged; trimmable is opt-in.Status
All of the earlier prerequisites have now merged into
main, and this PR has been rebased on latestmain:With those in
main, this PR is no longer stacked or blocked — it contains only the value/type manager implementations on top of them.