Skip to content

[TrimmableTypeMap] Implement TypeManager and ValueManager and other Runtime codeΒ #10791

Description

@simonrozsival

Part of #10788

Core idea:

Type proxyType = typeMap["com/example/MainActivity"];  // Returns typeof(MainActivity_Proxy)
JavaPeerProxyAttribute proxy = proxyType.GetCustomAttribute<JavaPeerProxyAttribute>();  // Returns MainActivity_Proxy instance
IJavaPeerable instance = proxy.CreateInstance(handle, transfer);  // Returns MainActivity instance

We need to clearly separate the new typemap related code from legacy code. Ideally, we'll put the new code in a separate folder and namespace.

  1. TrimmableTypeMapTypeManager
    • Based on AndroidTypeManager (implements method replacement for InTune)
      • How can we reuse code between our type manager and this type manager?
      • We need to carefuly handle the Java type hierarchy walking when identifying the best match for JNI type name and a targetType (might involve type aliases, although there seems to be inconsistent support for that feature in the existing code)
      • Caching of type mappings needs to be done carefuly
    • No dependency on Java.Interop.TypeManager + Java.Interop.JavaTypeManager
      • These need to be trimmed away since they contain most of the trimming-unsafe code
  2. TrimmableTypeMapValueManager
    • Ideally we'd just use ManagedValueManager (CoreCLR + Native AOT bridge integration), but make sure the CreatePeer calls
  3. JavaConvert
    • We need to carefully override all the primitive and container type conversions with trimming- and AOT-safe factories through (as outlined in earlier draft [Draft][Proposal] Trimmable Type MapΒ #10757 - see "PoC Usage: TypeMapAttributeTypeMap.CreateArray" and "PoC Usage: JavaConvert Generic Collection Marshalling")
    • This might require changes to the generated proxy. I think we might want to add abstract class JavaPeerProxy<T> : JavaPeerProxy which has a GetContainerFactory() method as described in the spec draft mentioned earlier

Activity

  1. added this to the .NET 11 milestone on Feb 10, 2026
  2. simonrozsival commented on Mar 12, 2026

    @simonrozsival
    MemberAuthor

    Note: GetContainerFactory() emission on proxy types is deferred from the generator PR (#10917 / issue #10799) to this issue. The proxy type infrastructure is ready β€” this just needs a small addition to TypeMapAssemblyEmitter to emit the method body once JavaPeerContainerFactory is defined.

  3. locked and limited conversation to collaborators on Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: CoreCLRIssues that only occur when using CoreCLR.Area: NativeAOTIssues that only occur when using NativeAOT.needs-triageIssues that need to be assigned.trimmable-type-map

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions