You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: 16e1ecd
Context: 312fbf4
It occurs to me that it would be easier for "external" developers to
use `Java.Interop.dll` if it didn't require building and distributing
any native libraries. Furthermore, as of commit 312fbf4 (C#9
function pointer backend), it's *plausible* to make that work.
Let's do so.
Add new "pseudo" `Standalone-Debug` and `Standalone-Release`
build configurations to `Java.Interop.csproj` which set the
`FEATURE_JNIENVIRONMENT_JI_FUNCTION_POINTERS` compiler define instead
of the `FEATURE_JNIENVIRONMENT_JI_PINVOKES` define. This enables
`JniEnvironment` to use C#9 function pointers instead of P/Invokes to
invoke the `JNIEnv` function pointers. They're "pseudo"
configurations because they don't actually exist within
`Java.Interop.sln`, and thus can only be built via command line, *or*
via `<ProjectReference AdditionalProperties="…"/>` wonkery:
dotnet build src/Java.Interop/Java.Interop.csproj -c 'Standalone-Debug'
Update `Java.Interop.dll` to compile when
`FEATURE_JNIENVIRONMENT_JI_FUNCTION_POINTERS` is set.
!!ABI BREAK!! `[Obsolete]` the method
`JniRuntime.GetAvailableInvocationPointers()`. In retrospect this
never should have been exposed at this level of the stack, and its
existence was responsible for "really really bizarre" .NET Android
[app crashes][0] (due to static constructor orderings) when
*sometimes* `JniRuntime.Current` wasn't set "early enough":
D Mono : AOT: FOUND method Java.Interop.JniRuntime:GetAvailableInvocationPointers () [0x78e4da7960 - 0x78e4da7a7c 0x78e4de6840]
D Mono : AOT: FOUND method Java.Interop.JniRuntime:GetCreatedJavaVMs (intptr[],int,int&) [0x78e4ddd2b0 - 0x78e4ddd300 0x78e4de6bcd]
D Mono : AOT: NOT FOUND: Java.Interop.NativeMethods:java_interop_jvm_list (intptr[],int,int&).
F monodroid-assembly: Internal p/invoke symbol 'java-interop @ java_interop_jvm_list' (hash: 0x58c48fc8b89cb484) not found in compile-time map.
*Nobody* should be using this method, largely given that only
Xamarin.Android and .NET Android apps currently use
`Java.Interop.dll`, and neither use
`JniRuntime.GetAvailableInvocationPointers()`. Furthermore,
it *can't* work on Android, as Android doesn't provide a public
[`JNI_GetCreatedJavaVMs()`][1] symbol.
Update `build-tools/jnienv-gen` so that a `JniNativeMethods` class
is defined which contains "human usable" ways to invoke `JNIEnv`
function pointers. (Nobody wants to copy the expression
`(*((JNIEnv**)env))->ExceptionClear(env)` more than once, ever.
`JniNativeMethods.ExceptionClear(env)` is much nicer to write.)
Update `Java.Runtime.Environment.dll` so that when building for
.NET 7, [`System.Runtime.InteropServices.NativeLibrary`][2] is used
to load `JniRuntime.CreationOptions.JvmLibraryPath` and invoke
`JNI_CreateJavaVM()` and `JNI_GetCreatedJavaVMs()`. This should
remove all required P/Invokes when using CoreCLR and not MonoVM.
Update `samples/Hello-Core` so that it uses the `Standalone-`
pseudo configuration instead of the "regular" peer config.
[0]: https://discord.com/channels/732297728826277939/732297837953679412/979054761603125319
[1]: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#JNI_GetCreatedJavaVMs
[2]: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.nativelibrary?view=net-7.0
0 commit comments