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?
Did you know...
IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?
It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page