Skip to content

[TrimmableTypeMap] Add GetFunctionPointer(int) ordinal dispatch#10921

Closed
simonrozsival wants to merge 1 commit intodev/simonrozsival/trimmable-typemap-04-jcw-generatorfrom
dev/simonrozsival/trimmable-typemap-05-get-function-pointer
Closed

[TrimmableTypeMap] Add GetFunctionPointer(int) ordinal dispatch#10921
simonrozsival wants to merge 1 commit intodev/simonrozsival/trimmable-typemap-04-jcw-generatorfrom
dev/simonrozsival/trimmable-typemap-05-get-function-pointer

Conversation

@simonrozsival
Copy link
Member

Part of #10799
Stacked on #10917.

Summary

Adds GetFunctionPointer(int methodIndex) to ACW proxy types. This method maps ordinal indices to [UnmanagedCallersOnly] wrapper function pointers, providing an alternative dispatch mechanism to RegisterNatives.

IL emission

Emits a chain of comparisons:

public IntPtr GetFunctionPointer (int methodIndex)
{
    if (methodIndex == 0) return &wrapper_0;
    if (methodIndex == 1) return &wrapper_1;
    // ...
    return IntPtr.Zero;
}

Each case uses ldftn to load the function pointer of the corresponding [UnmanagedCallersOnly] static method, using the same wrapperHandles dictionary populated during UCO emission.

Tests

  • Verifies GetFunctionPointer method exists on generated ACW proxy types

Emit GetFunctionPointer(int methodIndex) on ACW proxy types that maps
ordinal indices to UnmanagedCallersOnly wrapper function pointers.

The method emits a chain of comparisons:
  if (methodIndex == 0) return (IntPtr)&wrapper_0;
  if (methodIndex == 1) return (IntPtr)&wrapper_1;
  ...
  return IntPtr.Zero;

This provides an alternative dispatch mechanism to RegisterNatives,
allowing the runtime to look up function pointers by ordinal index.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival
Copy link
Member Author

Closing — GetFunctionPointer is redundant since we use RegisterNatives to bind JNI native methods to UCO wrappers at class load time. The earlier spec mentioned GetFunctionPointer as an alternative to RegisterNatives (for LLVM IR trampolines), but we chose RegisterNatives instead.

@simonrozsival simonrozsival deleted the dev/simonrozsival/trimmable-typemap-05-get-function-pointer branch March 12, 2026 08:23
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.

1 participant