4

I have some Java-app and a customer with some UWP-app implemented in C#, distributed through the Windows Store etc., who wants to use some pieces of my app. Those pieces are pretty OS-independent, only parsing of some special binary file formats, applying some business logic configured using YAML files and stuff. No network, GUI, only some accesses to files etc.

We currently use IKVM to make the code of interest available to C# but ran into different problems already. Some were supporting .NET Core, some had to do with the native toolchain in Release etc. While right now things seem to work after applying some workarounds, I'm looking for alternatives to IKVM already a bit.

The only thing I currently use of IKVM is simply creating a DLL of my code using ikvmc, which can then be referenced in the UWP-project. The compiler is summarized like the following:

The ikvmc tool converts Java bytecode to .NET dll's and exe's.

That's where the support to create native Windows images of GraalVM came into my mind. Others seem to already build native binaries for Windows and according to the docs, GraalVM is able to create shared libs using "--shared". From my understanding, IKVM implements a JVM in .NET and maps things as needed and possible. That sounds pretty much like what "Substrate VM" does in case of a native image, doesn't it?

This executable includes the application, the libraries, the JDK and does not run on the Java VM, but includes necessary components like memory management and thread scheduling from a different virtual machine, called “Substrate VM”. Substrate VM is the name for the runtime components (like the deoptimizer, garbage collector, thread scheduling etc.).

https://www.graalvm.org/docs/reference-manual/native-image/

So, is there any chance that a native image in form of a DLL can replace the DLL created by ikvmc currently? Did anyone try that already and has any experiences? Did anyone try already to create a native DLL and consume that in some other native Windows app? From my understanding UWP "only" applies additional restrictions which one might be able to work around again. Or is this approach totally impossible for some reasons?

Thanks all for your input!

Thorsten Schöning
  • 3,501
  • 2
  • 25
  • 46

2 Answers2

2

I'm not very familiar with the IKVM project, so this answer is mostly about the generic question:

Can you create a native DLL/shared library and consume that in some other native Windows app?

It should be possible. You can compile Java code into a shared library. The entry points are marked with the @CEntrypoint annotation.

You can then use the generated shared library and the header files to consume your library from a native application.

This way for example GraalVM distributions use the GraalVM JIT compiler by default:

  1. The GraalVM JIT is written in Java
  2. Compiled as a shared library with the native-image
  3. Used in Hotspot.

Here's a page describing how to consume those from Java through the JNI: https://web.archive.org/web/20211212131233/https://www.graalvm.org/reference-manual/native-image/ImplementingNativeMethodsInJavaWithSVM/

which could be very similar to how would you use a shared library from a C# application.

adrock20
  • 175
  • 1
  • 7
Oleg Šelajev
  • 3,530
  • 1
  • 17
  • 25
-1

GraalVM native images are not very flexible, unlike IKVM.NET images. Unless you like writing wrappers and playing with P/Invoke, you should stick to IKVM.NET.

NOTE: I am behind an IKVM.NET fork

Jessie Lesbian
  • 1,273
  • 10
  • 14
  • Your comment doesn't answer the question. Please adjust it regarding to the question or at least give some more useful information. – AztecCodes May 19 '23 at 15:56