Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jnimarshalmethod-gen] JavaInterop1 marshal methods #1164

Merged
merged 3 commits into from
Nov 20, 2023

Conversation

jonpryor
Copy link
Member

Fixes: #1159

Context: c93fea0

jnimarshalmethod-gen is intended to generate marshal methods for any type that that:

  • Has [JavaCallable] (tested in Java.Interop.Export-Tests.dll and c93fea0), or
  • Overrides a virtual method which has [JniMethodSignature], or
  • Implements an interface method which has [JniMethodSignature].

Thus, the intention was that it should generate marshal methods for Java.Base-Tests:

% dotnet bin/Debug-net7.0/jnimarshalmethod-gen.dll -v bin/TestDebug-net7.0/Java.Base-Tests.dll
Unable to read assembly 'bin/TestDebug-net7.0/Java.Base-Tests.dll' with symbols. Retrying to load it without them.
Preparing marshal method assembly 'Java.Base-Tests-JniMarshalMethods'
Processing Java.BaseTests.JavaInvoker type
Processing Java.BaseTests.MyRunnable type
Processing Java.BaseTests.MyIntConsumer type
Marshal method assembly 'Java.Base-Tests-JniMarshalMethods' created

Notably missing? No messages stating:

Adding marshal method for …

Also missing? ikdasm bin/TestDebug-net7.0/Java.Base-Tests.dll showed that there were no __RegisterNativeMembers() methods emitted.

The jnimarshalmethod-gen invocation was a no-op!

The problems were twofold:

  1. It was only looking for methods with Android.Runtime.RegisterAttribute. This was useful for Xamarin.Android (when we were trying to make it work), but doesn't work with Java.Base. We need to also look for Java.Interop.JniMethodSignature.

    Relatedly, the attempt to use registerAttribute.Constructor.Parameters to determine parameter names didn't work; the parameter name was always "".

  2. A'la c93fea0, we need to ensure that the Java native methods we register are consistent with jcw-gen output.

Fix these two problems, which allows jnimarshalmethod-gen to now emit marshal methods for types within Java.Base-Tests.dll.

Additionally, rework the jnimarshalmethod-gen -f logic to remove the existing __<$>_jni_marshal_methods nested type when present.

Fixes: #1159

Context: c93fea0

`jnimarshalmethod-gen` is intended to generate marshal methods for
any type that that:

  * Has `[JavaCallable]` (tested in `Java.Interop.Export-Tests.dll`
    and c93fea0), or
  * Overrides a `virtual` method which has `[JniMethodSignature]`, or
  * Implements an interface method which has `[JniMethodSignature]`.

Thus, the intention was that it should generate marshal methods for
`Java.Base-Tests`:

	% dotnet bin/Debug-net7.0/jnimarshalmethod-gen.dll -v bin/TestDebug-net7.0/Java.Base-Tests.dll
	Unable to read assembly 'bin/TestDebug-net7.0/Java.Base-Tests.dll' with symbols. Retrying to load it without them.
	Preparing marshal method assembly 'Java.Base-Tests-JniMarshalMethods'
	Processing Java.BaseTests.JavaInvoker type
	Processing Java.BaseTests.MyRunnable type
	Processing Java.BaseTests.MyIntConsumer type
	Marshal method assembly 'Java.Base-Tests-JniMarshalMethods' created

Notably missing? No messages stating:

	Adding marshal method for …

Also missing?  `ikdasm bin/TestDebug-net7.0/Java.Base-Tests.dll`
showed that there were no `__RegisterNativeMembers()` methods emitted.

The `jnimarshalmethod-gen` invocation was a no-op!

The problems were twofold:

 1. It was only looking for methods with
    `Android.Runtime.RegisterAttribute`.  This was useful for
    Xamarin.Android (when we were trying to make it work), but
    doesn't work with Java.Base.  We need to *also* look for
    `Java.Interop.JniMethodSignature`.

    Relatedly, the attempt to use
    `registerAttribute.Constructor.Parameters` to determine parameter
    names didn't work; the parameter name was always `""`.

 2. A'la c93fea0, we need to ensure that the Java `native` methods
    we register are consistent with `jcw-gen` output.

Fix these two problems, which allows `jnimarshalmethod-gen` to now
emit marshal methods for types within `Java.Base-Tests.dll`.

Additionally, rework the `jnimarshalmethod-gen -f` logic to *remove*
the existing `__<$>_jni_marshal_methods` nested type when present.
@jonpryor
Copy link
Member Author

This should probably also incorporate additional jnimarshalmethod-gen changes from PR #1153.

@jonpryor jonpryor merged commit 25850ba into main Nov 20, 2023
4 checks passed
@jonpryor jonpryor deleted the dev/jonp/jonp-Java.Base+jnimarshalmethod-gen branch November 20, 2023 22:11
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jnimarshalmethod-gen should be used & usable with Java.Base-Tests
2 participants