My understanding of this project was greatly helped by Maurizio Cimadamore’s talk at Devoxx Belgium, you can watch the whole talk here.
What is Project Panama?
Project Panama is the OpenJDK project which is focused on improving Java’s support for accessing native code. Java currently provides us with Java Native Interface (JNI), however this implementation:
- Is complicated to learn
- Has multiple possible points of failure
- Has little room for JIT optimization
- Requires you to also be able to program in C.
With this in mind, Oracle set up Project Panama. The aims are to:
- Provide a foreign interface at the Java level similar to JNA and JNR
- Optimize these calls at the JVM level
- Expand the supported model to include C++ functionality
- Make it easier for Java developers to run native code
Why is Panama important?
Being able to use native code can provide different benefits but normally it can be cut down to 3 reaasons:
- To access functionality outside of the JDK (Libraries like OpenGL for example)
- To gain better performance
- To interact with legacy code/systems
It is worth noting that if you want better performance: even if there is a good performance boost by using native code, you should take the performance cost of the interface into consideration, as it could negate any gains.
With Panama, all of the above are possible and more accessible to all Java developers. In the right circumstances, you can develop a better application for your users. You may very well find it is something you want to experiment with.
How will it do it?
Although there is the potential for the direction to change, Panama will make a more accessible method native code interface by:
- Using annotated interfaces to model the primitive types/objects in Java
- Generating the implementations on the fly with binding
- Providing us with an automated tool (JExtract) to generate the interfaces
- Getting the compiler to produce the library directly, rather than a header file that you then have to code with
Panama has a Java 12 early-access build which you can experiment with (now available for Mac, Linux and Windows on the latest release). The JExtract tool shows a lot of potential, I would recommend giving it a test.
If you want to follow the development of the project, you can always subscribe to the mailing list.
Have you used native code for your projects before? Are you looking forward to what Panama might bring?
IDRsolutions develop a Java PDF library, a PDF forms to HTML5 converter, a PDF to HTML5 or SVG converter and a Java Image Library that doubles as an ImageIO replacement. On the blog our team post about anything interesting they learn about.