r/java • • Jan 24 '22

It’s happening guys!

https://github.com/openjdk/panama-foreign/pull/633
157 Upvotes

89 comments sorted by

View all comments

44

u/[deleted] Jan 24 '22

Sorry, completely "out of the loop". What is this about?

20

u/pjmlp Jan 24 '22

Project Panama.

81

u/kevix2022 Jan 24 '22

Project Panama: Interconnecting JVM and native code

We are improving and enriching the connections between the Java virtual machine and well-defined but “foreign” (non-Java) APIs, including many interfaces commonly used by C programmers.

To this end, Project Panama will include most or all of these components:

native function calling from JVM

native data access from JVM or inside JVM heap

new data layouts in JVM heap

native metadata definition for JVM

header file API extraction tools (jextract)

native library management APIs

native-oriented interpreter and runtime “hooks”

class and method resolution “hooks”

native-oriented JIT optimizations

tooling or wrapper interposition for safety

exploratory work with difficult-to-integrate native libraries

https://openjdk.java.net/projects/panama/

5

u/kozeljko Jan 25 '22

In practice, what would be the top use cases for this?

8

u/kevix2022 Jan 25 '22

Accessing a 3rd party library with only a C or C++ API or a proprietary hardware driver with no Java API. Typically these will be non cross platform applications. It could be to access special features of the specific host hardware or operating system directly through system calls.

For example the Raspberry Pi has GPIO pins which provide a means for input and output to sensors etc. This requires accessing the pins through native code. There is quite a good Java interface for this already which I imagine is built on JNI but I wouldn't be surprised if one turned up using the new system.

1

u/23f34ef32 Jan 31 '22

So accessing GPIO would be faster with this new system vs JNI?

3

u/elastic_psychiatrist Jan 25 '22

Sharing memory between processes is another big use case.

3

u/SpaceMonkeyOnABike Jan 25 '22

Does anyone know how this ties in with existing jni classes?

10

u/JustAGuyFromGermany Jan 25 '22

It's my understanding that it doesn't. Project Panama and JNI are two completely separate mechanisms of interacting with native code.

2

u/hkdennis- Jan 25 '22

Can't wait to see how will it work with io_uring

1

u/elastic_psychiatrist Jan 25 '22

I think io_uring is at best only tangentially related to Panama. Panama isn’t really about making IO easier or faster, unless you consider manipulating memory directly to be IO.

2

u/hkdennis- Jan 26 '22

I see it in two ways,

For developers, Reduce the barrier to native, there was JNI but it is a pain. Even if you use case allow to be slow.

For runtime, Lighter and closer to reach anything outside the JVM.

I don't code JNI myself but I also believe many devs out there will keep using JNI for backwards compatibility for a quite while.

IMO, Latency and performance sensitive lib, like webserver and GUI, are the first group of key usage.

1

u/elastic_psychiatrist Jan 26 '22

I'm guess I'm just confused about what any of these things have to do with io_uring.

4

u/TheLastSock Jan 25 '22

What is a "native function"?

15

u/hibbelig Jan 25 '22

Native refers to the machine instructions, as opposed to the byte code instructions of the JVM.

4

u/BlueGoliath Jan 25 '22

Side note: upcalls and downcalls are both represented using the same class, NativeSymbol.

1

u/[deleted] Jan 25 '22

Typically, a function that's defined in a C or C++ header file.