Should Project Panama make it into Java 9?
Panama Canal flood gates via Shutterstock
Project Panama is building a bridge to non-JVM libraries like C and C++. And it could be the most exciting Java 9 feature yet.
One Oracle employee has been working on an alternative to the Java Native Interface, Project Panama – something that any Java programmer using APIs for outside libraries should be getting pretty excited about.
By natively interconnecting code managed by the JVM and APIs of outside libraries, this proposed Java feature could drastically improve the experience for developers working with C or C++ APIs.
As the project’s author John Rose explains, “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.”
A Panama canal between JVM and ‘foreign’ code
The project first started in March this year (while all eyes were still on the Java 8 release) when co-author John Rose began an OpenJDK mailing list discussion about the possibility of natively connecting code managed by the JVM with APIs for libraries outside of the JVM. The project gained much support in the community after John Rose’s official proposal in June.
As Rose explains, the “Building such tool chains will allow cheaper, faster commerce between Java applications and native APIs”, which is why they have given it the name Panama, inspired from the Panama Canal which provided a faster connection between the Atlantic and Pacific Oceans.
The official project submission outlines the following features:
- native function calling from JVM (C, C++), specifically per JEP 191 (foreign function interface)
- 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 (see below)
- 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
As set out in John Rose’s blog post, the goal of the project is this: “If non-Java programmers find some library useful and easy to access, it should be similarly accessible to Java programmers.” This will be no easy task for the project’s authors, as various bridges will need to be built between the different languages syntaxes, namings, data types, storage management and semantics.
Although Rose has set out a number of requirements to realise this project, Panama, like the many other genuinely exciting Java feature proposals, has not (yet) made it into the official list of Java 9 features.
Seven confirmed Java 9 features
In August this year, Oracle confirmed a set of three new APIs as well as three performance features for Java 9 JEPs. A lightweight JSON API and a HTTP2 client will bring JSON document compatibility, as well as HTTP 2.0 and websockets respectively. Meanwhile Oracle’s trio of performance features are said to deliver less fragmentation, improved performance when threads are competing and a smart Java compiler.
But the most interesting confirmed feature so far has been Project Jigsaw, which aims to reorganise the source code of the JDK into modules and improved scalability for smaller devices, among other features.
However the Java community’s response to Oracle’s plans has been lukewarm at best, with many developers left pining for type values and better language features.
Stephen Colebourne, who contributed to the development of Java 8’s Date and Time API, told us that Java 9’s most interesting features will be shelved until Java 10. “Modularisation of the JDK feels remarkably uninteresting, and the potentially useful, developer-facing side of it (like being able to find all subclasses of a type, or all methods specifying a given annotation) may not actually happen,” Colebourne explains. “The other features are unlikely to make a big difference to my life I suspect.”
CTO of WSO2, Paul Fremantle told JAXenter he was nonplussed at the addition of a JSON API. “It’s just that there’s loads of really good JSON APIs in open source. Does it really help to have it in Java? I don’t buy that myself.”
The missing eighth feature?
Between an uninspiring JavaOne conference that lacked excitement and the developer world’s turning its nose up at Oracle’s plans for Java’s ninth release, the Java world could certainly use an injection of excitement right now. On top of it all, Larry Ellison’s stepping down as CEO has raised questions about the future of Oracle.
Although there’s immediate prospect of Panama making it into Java 9, a project as exciting as this could be the redeeming feature that the next generation of Java needs.