Piecing together free java

The libre-java movement got a huge boost on November 13 2006, "Java Liberation Day". That day Sun announced their intend to distribute all the source code for their implementations of Java Standard Edition (SE, code name OpenJDK), Enterprise Edition (EE, code name Glassfish) and Micro Edition (ME, code name PhoneME) as free software. All licensed under the GPL and using the classpath exception clause for selected libraries (Glassfish was earlier available under the CDDL and became dual-licensed CDDL/GPL).

Sun went out of their way to make their commitment to the GPL and everything this implies very clear. Their very extensive FAQ stresses the point that although they delegate control over the specification, what and how things can be certified compatible to the JCP (Java Community Process) and Sun holds control over the usage of the Java(TM) trademark. But everybody is free to run, copy, distribute, study, change, share and improve the source code for any purpose as long as they following the tit-for-tat, share-alike, copyleft rules of the GPL for all the code they released.

Sun contacted not only big Free Software names like Richard Stallman and Eben Moglen before the event. They also made sure that the existing libre-java communities knew about the plans before it all hit the press. Jonathan Schwartz, the Sun CEO, himself explicitly reached out to the existing GNU Classpath, GCJ and Kaffe communities to collaborate from now on to drive freedom and opportunity for developers making libre-java on GNU/Linux a reality. The Sun OpenJDK engineers came to the Fosdem conference to have a DevJam and share their ideas with the existing libre-java communities.

Sun couldn't liberate all the code at once, but did so in stages for anything they could get all the rights to over the last year. While at the same time slowly opening up the internal development process and switching to a public repository for all the code (Kelly O'Hair keeps a blog that is a great case study for moving a large project to Mercurial). Currently all code for Glassfish and phoneME has been released. While about 96% of the OpenJDK code base is available (almost all the parts not released yet are because Sun couldn't get the rights from some third parties). Rich Sands gives a great overview of how all this looked from inside Sun in his one year retrospective on java liberation day.

Meanwhile an effort, called IcedTea was started to put OpenJDK into the GNU/Linux distros by getting it quickly towards that 100% free software line. As Andrew Haley explained during the official announcement this is an experimental build tree that tries to stay close to the OpenJDK upstream but does not contain any non-free proprietary blobs. Those "plugs" are either stubbed out or replaced with code from GNU Classpath. IcedTea can be build using only free software. In particular you can use GCJ for the first build phase to bootstrap those parts of the build that depend on a working java compiler and runtime so that it can be easily build on a modern GNU/Linux distro with a simple ./configure && make; or at least that is the theory. It build out of the box on Fedora 7 or 8. For Debian and Gentoo some additional steps are still needed.

Since OpenJDK didn't have a open bug database and (until recently) a source code repository, IcedTea also has an open public bugtracker and a public Mercurial repository. All discussions about the code are done on the public OpenJDK mailinglist dedicated to GNU/Linux distro-pkg-dev.

IcedTea is what most GNU/Linux distros ship now for x86 and x86_64 in addition to GCJ for other architectures. It also adds some things that make things easier for distribution packagers. It adds patches so that the runtime and core libraries link to system shared libraries like zlib and libjpeg which should make security updates simpler. It adds support for using things like the system wide tzdata files for the TimeZone utility classes. It supports the usage of the system installed certificates authority files for security related checks as used in the ssl network classes. Thomas Fitzsimmons, who helped with the above items, keeps a Packager's Wishlist for OpenJDK.

IcedTea also contains some bug fixes from people who submitted patches to OpenJDK upstream but which haven't been accepted yet to give them a wider testing audience. Others have offered alternative backends for existing packages that make java applications integrate better in a GNU/Linux system. Like the GConf backend for the java.util.prefs package by Mario Torre, which he ported from GNU Classpath.

Lastly IcedTea is a testbed for porting OpenJDK to other architectures, which only supports x86, x86_64 and sparc. There are two different approaches. The first is to start with the Hotspot C++ Interpreter. HotSpot is the runtime of OpenJDK and actually contains another byte code interpreter by default. The Template Interpreter that is a bit harder to port. After requests from the community Sun also released their older C++ based interpreter to help the porting effort. Gary Benson recently made a breakthrough and got it working for PowerPC (both 32 and 64 bit). He wrote a guide to porting IcedTea that will hopefully help people porting to other architectures. Of course the interpreter alone is slow, so the next step is to add support for the HotSpot JIT compilers, which is a lot of work. But the benefit is that you get a full system up and running that is similar to the existing architectures with full support for all features.

Another approach is taken by the Cacao team who have a branch in IcedTea mercurial and work on replacing the whole HotSpot runtime with a libjvm.so based on the Cacao JITs, but reusing all of the core libraries. This now works for s390 and powerpc. Cacao also supports alpha, arm and mips so this is an interesting path for getting a faster port. But you will have to replace all of the Hotspot runtime to get it and the Cacao VM is still missing some features, like annotations and full JVMTI and JDWP debugging support.

There are some other interesting developments around former GNU Classpath based projects that are now experimenting with combining their code and the new OpenJDK and/or PhoneME projects. Dalibor Topic worked on a Google Summer of Code project to make the OpenJDK javac compiler a source to bytecode frontend for the GCJ native compiler. There is the MIDPath project which combines elements of SE and ME, plus different backends (SDL, FB, AWT, X11, Gtk+ and Qt) to provide access to MIDP2 a mobile devices standard used on lots of phones for various platforms. JaLiMo provides all of the above packaged for the Maemo and OpenMoko platforms. JNode a full operating system written in java that is now build upon a hybrid of OpenJDK and GNU Classpath libraries. And there is the IKVM project that is providing a java implementation, translation and interoperability framework for .net implementations like Mono.

With all this one could safely say that The Java Trap has been dismantled. But even with some replacements from GNU Classpath, IcedTea/OpenJDK is still missing some small parts. The java.sound implementation isn't complete, but Sun released the parts they could. The JMX implementation is missing SNMP support. Applets are currently supported through gcjwebplugin, which has as benefit that there is finally a 64-bit plugin, but it is still missing LiveConnect (Java/JavaScript integration). And finally there is no support yet for JNLP (javawebstart), although there is netx, which might be added to IcedTea soon.

So when you put all the above together, what Java version do we get? Officially what the GNU/Linux distros ship now isn't Java(TM) since it isn't certified. And IcedTea comes with the following warning:

IcedTea is derived from OpenJDK, Sun's open-source implementation of the Java SE platform. At this time the build from which IcedTea was constructed corresponds to an early build (b21) of JDK 7. When JDK 7 is complete it will implement the Java SE 7 Platform Specification. Work on that specification is underway, but far from final. Any APIs in the JDK 7 implementation, whether new or old, are therefore subject to minor adjustments, major revisions, or even outright removal between now and the time that the Java SE 7 Platform Specification is finalized. Please take these facts into account before depending upon IcedTea.

Sun is working on a JDK 6 implementation based on OpenJDK and Red Hat has recently signed the OpenJDK Community TCK License Agreement which gives them access to the test suite that determines whether an implementation that is derived from the OpenJDK project complies with the Java SE 6 specification for binary releases they ship (while the source code will of course still be available under the GPL). This agreement does however contain a NDA which prevents talking about how compatible the current code is and the test compatibility kit itself is still proprietary so it will be hard to work together with the community at large on this.

One year after Java Liberation Day modern GNU/Linux distros are starting to ship with a more complete free java-like stack than ever before. There are still some small loose ends to tie up. It was a learning experience for all communities involved. Suddenly the whole free java ecosystem changed. Sun consistently kept their promises about opening up and the existing libre-java communities learned to respect and take advantage of the now free reference implementation that they worked so hard on replacing with a full free stack themselves for the last decade. But now the fruits of collaboration and reusing each others code is materializing. In less than another year it will be common to have a full free GPLed java stack, either SE, ME or EE, wherever you find GNU/Linux running.

[Disclaimer. Since 1999 I have worked on, and since 2003 I am the maintainer of, GNU Classpath and as such have been involved in related projects like kaffe, gcj, jamvm, cacao, ikvm, etc. I was also one of the people starting the Harmony effort, and then left that project a year later, I wrote an article about that for LWN last year. I recently started to work for Red Hat (although I don't currently work on anything related to libre-java for them, but I do sometimes talk to the engineers there that do work on that stuff). I setup and maintain the technical infrastructure for IcedTea together with Jim Pick and Thomas Fitzsimmons. And I was the mentor for the Google Summer of Code project to use the openjdk javac compiler as java source compiler for the gcj project.]