Skip to content

Split reflection-based JniTypeManager behavior#1441

Draft
simonrozsival wants to merge 15 commits into
mainfrom
dev/simonrozsival/fix-aot-warnings-jni-type-manager
Draft

Split reflection-based JniTypeManager behavior#1441
simonrozsival wants to merge 15 commits into
mainfrom
dev/simonrozsival/fix-aot-warnings-jni-type-manager

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Draft PR to let CI validate the JniTypeManager split and AOT warning work.

Summary:

  • Keep JniTypeManager as the abstract base and move reflection-backed behavior into DynamicJniTypeManager.
  • Update JRE/test managers that extend the default behavior to inherit from DynamicJniTypeManager.
  • Keep NativeAOT sample managers on the abstract base with explicit mappings instead of reflection-backed base calls.
  • Update public API baselines for the split.

Local validation:

  • dotnet build src/Java.Interop/Java.Interop.csproj -p:JavaCPath="$JAVA_HOME/bin/javac" -p:JarPath="$JAVA_HOME/bin/jar"
  • dotnet build tests/Java.Interop-Tests/Java.Interop-Tests.csproj -p:JavaCPath="$JAVA_HOME/bin/javac" -p:JarPath="$JAVA_HOME/bin/jar" -p:NativeToolchainSupported=false

Notes:

  • Full local prepare/build is still blocked in this workspace by local build setup/toolchain issues, so this is intentionally draft for CI coverage.

@simonrozsival simonrozsival force-pushed the dev/simonrozsival/fix-aot-warnings-jni-type-manager branch from 5ff4c17 to 6d72140 Compare June 4, 2026 14:24
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/fix-aot-warnings-jni-type-manager branch from 6d72140 to 58f0dbd Compare June 4, 2026 14:30
@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@simonrozsival simonrozsival marked this pull request as ready for review June 8, 2026 11:55
Copilot AI review requested due to automatic review settings June 8, 2026 11:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This draft PR refactors JniRuntime.JniTypeManager into an abstract base and moves the default reflection-based behavior into a new JniRuntime.DynamicJniTypeManager, with corresponding updates across tests, JRE runtime helpers, samples, and public API baselines.

Changes:

  • Introduces JniRuntime.DynamicJniTypeManager and makes JniRuntime.JniTypeManager abstract, shifting default/reflection-backed logic into the new derived type.
  • Updates test and JRE type managers to inherit from DynamicJniTypeManager, and adjusts tests for new behaviors (e.g., generic invoker handling, GetType array behavior).
  • Updates trimmer/AOT annotations and PublicAPI baselines to reflect the split and new abstract members.
Show a summary per file
File Description
tests/Java.Interop-Tests/Java.Interop/JniTypeManagerTests.cs Updates expectations around GetType behavior (notably array signatures and generic holder mapping).
tests/Java.Interop-Tests/Java.Interop/JniRuntimeTest.cs Switches proxy manager to DynamicJniTypeManager and adds trim suppression for test-only reflection use.
tests/Java.Interop-Tests/Java.Interop/JniRuntime.JniTypeManagerTests.cs Adds a generic invoker negative test and updates test manager base type.
tests/Java.Interop-Tests/Java.Interop/JavaVMFixture.cs Updates fixture type manager to DynamicJniTypeManager and refines type lookup with trimming annotations.
src/Java.Runtime.Environment/Java.Interop/JreTypeManager.cs Moves to DynamicJniTypeManager and adds a DAM-annotated GetTypeForSimpleReference override.
src/Java.Interop/PublicAPI.Unshipped.txt Records newly introduced/reshaped APIs (new type, newly-abstract members, overrides).
src/Java.Interop/PublicAPI.Shipped.txt Updates shipped API surface to reflect newly-abstract members and removed methods from JniTypeManager.
src/Java.Interop/Java.Interop/JniValueMarshaler.cs Simplifies expression-based marshaler instantiation and adjusts trimming annotations.
src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs Switches peer-type selection to GetReflectionConstructibleTypes() and refactors uninitialized peer creation.
src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs Makes JniTypeManager abstract and factors previously-inlined logic into abstract core methods.
src/Java.Interop/Java.Interop/JniRuntime.DynamicJniTypeManager.cs Adds the new reflection-backed type manager implementation and related registration behavior.
src/Java.Interop/Java.Interop/JniRuntime.cs Removes the default new JniTypeManager() fallback; requires an explicit type manager in creation options.
src/Java.Interop/Java.Interop/JavaPrimitiveArrays.tt Retargets primitive array helper generation to DynamicJniTypeManager.
src/Java.Interop/Java.Interop/JavaPrimitiveArrays.cs Updates the generated primitive array helper container type to DynamicJniTypeManager.
src/Java.Interop/GlobalSuppressions.cs Adds CA1034 suppression for the new nested DynamicJniTypeManager type.
samples/Hello-NativeAOTFromJNI/NativeAotTypeManager.cs Updates sample type manager implementation to new hierarchy and adds explicit native member registration.
samples/Hello-NativeAOTFromJNI/ManagedType.cs Changes the native registration hook to internal for sample-driven registration.
samples/Hello-NativeAOTFromAndroid/NativeAotTypeManager.cs Updates sample type manager implementation to new hierarchy and implements abstract members.

Copilot's findings

  • Files reviewed: 18/18 changed files
  • Comments generated: 3

Comment thread samples/Hello-NativeAOTFromJNI/NativeAotTypeManager.cs Outdated
Comment thread samples/Hello-NativeAOTFromAndroid/NativeAotTypeManager.cs Outdated
Comment thread src/Java.Interop/Java.Interop/JniRuntime.DynamicJniTypeManager.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival marked this pull request as draft June 8, 2026 14:24
simonrozsival and others added 9 commits June 8, 2026 16:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Map Java.Interop's internal proxy peer types in the base type manager so custom AOT-safe managers do not need reflection-based DynamicJniTypeManager behavior for JavaProxyThrowable/JavaProxyObject.

Register built-in proxy native members by JNI type name before asking custom managers for a managed Type, avoiding DAM-annotated lookups of internal Exception/Delegate-derived types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Let the base JniTypeManager resolve primitive JNI keyword signatures without requiring custom AOT-safe managers to duplicate the dynamic type manager's primitive mappings.

Use that base lookup as a fallback when matching Java-to-managed constructor signatures so signatures such as (I)V resolve to System.Int32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants