Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

[Java.Interop] Register ManagedPeer natives via blittable function pointers - #1490

Closed
simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/managedpeer-blittable-registration
Closed

simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/managedpeer-blittable-registration

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

Replaces the delegate-based JniNativeMethodRegistration registration of ManagedPeer's construct/registerNativeMembers JNI natives with the blittable RegisterNatives(ReadOnlySpan<JniNativeMethod>) overload.

Details

  • Uses [UnmanagedCallersOnly] static methods (Construct, RegisterNativeMembers) and statically-compiled delegate* unmanaged<> function pointers instead of [UnmanagedFunctionPointer] delegates.
  • Passes UTF-8 (u8) name/signature literals directly to JNI via fixed pointers.
  • Removes the runtime delegate-marshaling requirement, so the IL3050/dynamic-code suppression on the static constructor is no longer needed — making the registration path NativeAOT-friendly.
  • Drops now-unused using directives (System.Linq, System.Linq.Expressions, System.Reflection.Emit, System.Runtime.Serialization).

No behavioral change: the same two natives are registered on the same net/dot/jni/ManagedPeer type; the blittable RegisterNatives overload preserves the prior pending-exception handling.

…inters

Replace the delegate-based JniNativeMethodRegistration registration of
ManagedPeer's construct/registerNativeMembers natives with the blittable
RegisterNatives(ReadOnlySpan<JniNativeMethod>) overload, using
[UnmanagedCallersOnly] static methods and statically-compiled function
pointers. This removes the need for runtime delegate marshaling (and the
associated IL3050/dynamic-code requirement), making the registration path
NativeAOT-friendly.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings July 1, 2026 13:14

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

Updates ManagedPeer native method registration to use the blittable RegisterNatives(ReadOnlySpan<JniNativeMethod>) path with statically-compiled unmanaged function pointers, removing the prior delegate-marshaling/dynamic-code requirement and improving NativeAOT compatibility.

Changes:

  • Switches ManagedPeer’s construct/registerNativeMembers natives to [UnmanagedCallersOnly] + delegate* unmanaged<> function pointers.
  • Registers natives via UTF-8 (u8) name/signature literals passed as fixed pointers.
  • Removes now-unused using directives and the prior IL3050/dynamic-code suppression for the static constructor.
Show a summary per file
File Description
src/Java.Interop/Java.Interop/ManagedPeer.cs Replaces delegate-based native registration with blittable JniNativeMethod + unmanaged function pointers for AOT-friendly native registration.

Copilot's findings

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

Comment thread src/Java.Interop/Java.Interop/ManagedPeer.cs Outdated
Comment thread src/Java.Interop/Java.Interop/ManagedPeer.cs Outdated
Comment thread src/Java.Interop/Java.Interop/ManagedPeer.cs
@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, thanks! label Jul 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, thanks!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants