<<

:FM

DXb`e^j\ej\f]AXmXfe`elo :F==<< 9I<8B

We introduce some tools and projects of the landscape. BY DAVID HULL

inux is a free . run Java on a completely free, TCK-com- a burst of JVM development. Literally Java is one of the most popular pliant system. dozens of projects sprang up. Most of Cplatforms for . Run- Because the open source community these projects had petered out by 2003 ning free Java software on should still supports several other completely or so, but a few stuck around and be easy; yet, until fairly recently, anyone free choices that aren’t officially blessed, gained wider acceptance. who wanted to run Java on Linux faced the situation is still a bit complex. To run Sun’s HotSpot JVM comes in client a dilemma. On one hand, you could use Java, you need some way of executing and server versions. Both versions are Sun’s own Java environment, and you’d Java , typically but not neces- free. The client version is tuned for be guaranteed compatibility (at least sarily, with a Java shorter running applications, whereas with other Sun-based deployments), but (JVM), and you need an implementation the server version is tuned for long-run- you would be using non-free software. of whatever libraries you are using (to- ning servers. The main difference is that On the other hand, you could go with gether, this is more or less what Sun the server version puts more effort into any of literally dozens of free offerings, calls a Java Runtime Environment optimizations that have a greater effect ranging from someone’s PhD thesis to [JRE]). In this article, I will walk you with longer times. An applica- major projects with release schedules through the major choices for JREs. tion running on the client JVM will typi- and full-time staff, but these alternatives cally start faster but might run slower would lead to questions of compatibility N_`Z_AMD6 over time. HotSpot is the JVM shipped under Sun’s Technology Compatibility The JVM is the component that actually with OpenJDK [4] (Figure 2). At this Kit (TCK) test suite. runs your Java application. Because Java writing, the latest point release is dated This situation improved considerably programs are represented as a sequence February 11, 2009. in late 2006 and early 2007 when Sun of bytecodes, the simple way to run a JamVM [5], an alternative virtual ma- began releasing its Java application is to interpret each byte- chine developed by Robert Lougher and (JDK) under a free license. Because Sun code and do what it says. This simple first released in 2003, is optimized for relied on other vendors for some parts of method is much too slow to be practical, small size and fast startup time. The exe- the JDK, it couldn’t release them as free so modern JVMs typically include a Just software. The IcedTea project [1] has In Time (JIT) that translates Work in Progress filled in these missing pieces, both for Java bytecodes to native . The components discussed in this article JDK 5 and JDK 6, by bringing in appro- When Java was introduced, the idea are under active development. State- priate parts of the GNU [2] of a new object-oriented language with ments about which versions are avail- (Figure 1). Because Sun has also re- a published specification and a major able, or packaged, or compatible with leased its HotSpot JVM [3] under an vendor behind it was catnip to program- various other components reflect my open source license, it is now possible to ming language researchers, resulting in best understanding as of this writing.

32 ISSUE 102 MAY 2009 Java on Linux :FM

called “Ahead Of Time” (AOT) compila- tion to distinguish it from “just in time.” Many of the earlier open source JVM projects are still around, and some of them might even work with modern Java systems. To use them, you’ll have to build the code yourself and, quite pos- sibly, get your hands dirty in the code. In addition, you will find a number of more specialized JVMs aimed at embed- ded applications or other niches. They aren’t included here, but if you’re curi- ous, the site has an extensive list [11]. A virtual machine called IKVM [12] is even available for running Java on .NET, and it works with Linux. Tools like IKVM might be useful if you’re develop- ing for .NET, but for running ordinary =`^li\(1K_\>EL:cXjjgXk_c`YiXip`jXe`dgfikXekZfdgfe\ekf]k_\fg\ejfliZ\AXmX Java applications on Linux, it’s probably \em`ifed\ek% better just to run them in a standard en- vironment. cutable for the i486 and later Intel chips at portability and small size. Kaffe has is around 180KB. JamVM is developed been ported to a large variety of plat- N_`Z_C`YiXi`\j6 mainly on PowerPC, but it has been built forms, ranging from small embedded de- Mercifully, the task of choosing libraries and tested on ix86, ARM, AMD64, and vices to Linux, Mac, and Windows. The is much simpler than choosing JVMs be- MIPS chips. JamVM requires GNU Class- developers do not claim full Sun compat- cause the open source user has fewer path for support; according to the ibility. In fact, the website goes so far as options. After all, writing a complete set JamVM website, it is incompatible with to explicitly disclaim Sun support. In par- of libraries is a much bigger task than OpenJDK. The latest release is 1.5.2, ticular, Kaffe does not support security writing a JVM. For example, the GNU dated February 4, 2009. features such as verification. Classpath project has 20 active develop- Cacao [6] was originally developed in The SableVM project [9] aims to pro- ers, whereas a VM tool like JamVM has 1997 at the Vienna Institute of Technol- vide a highly portable and understand- just one. And let’s face it: Writing a new ogy as a faster alternative to Sun’s JVM, able JVM implementation. SableVM uses JVM with a cutting-edge optimizing JIT which was a pure . Cacao in- a sophisticated interpreter to achieve is a lot more fun than writing 18 differ- stead compiles everything as it runs it. performance “near” that of a JIT. Ac- ent versions of Arrays.fill(). In this, it is more like the server version cording to the website, the Sable project Most Java libraries can be written in of HotSpot than the client. Cacao be- “has met its research goals and is not ac- Java and will run on any compliant JVM, came an open source project in 2004. tively maintained anymore”; indeed, the leaving only a small set of packages that The latest release is 0.99.3, dated August last release was 1.13, dated December must be customized for the JVM imple- 12, 2008. 2005. Nonetheless, SableVM is available mentation. In practice, all of the JVMs I Jikes RVM [7] (not to be confused in package form for major distributions. listed, except HotSpot, integrate with with the RVM “recoverable ” li- Another option is to compile with the GNU Classpath. Several also integrate brary) is the JVM produced as part of GNU Compiler for Java (GCJ) [10]. Did I with OpenJDK. Even OpenJDK itself IBM’s Jalapeño project. The Jikes VM is say the JVM is what actually runs Java used GNU Classpath code to replace the “meta-circular,” meaning it is written in programs? Usually it is, but you don’t proprietary sections that Sun couldn’t Java. The in the name is for research, have to take the usual route of compiling open source. and RVM is aimed at demonstrating and Java to bytecodes and then feeding them Although Sun has opened its library trying out new and wonderful ideas in to a JVM that will most likely compile code, it still tightly controls the process virtual machine technology. The project them even more. Instead, you can feed and compatibility tests (in particular, its is very much alive – with a book just re- the bytecodes to the GCJ and produce TCK) that allow an implementation to leased about its architecture – but unlike native code directly. Also, you can use claim full Java compliance. Because of the Jikes compiler, it does not appear to the GCJ to compile Java Archive (JAR) this, it is generally not practical for open be actively packaged for distribution. files to native code. The finished product source projects to claim full Java compli- Kaffe [8] was originally developed in will run like any other native , ance, with the special exception of Open- 1996 and was, for a time, the flagship and a libgcj shared library even provides JDK. Naturally, an open source project, product of Transvirtual Technologies. the environment. This Mauve [13], was started that is aimed at Transvirtual released Kaffe under the process is what used to be called “compi- addressing this by providing a free test GPL in 1998, and it continues as an open lation,” but in the context of a bytecode- suite for Java class libraries. source project. The Kaffe project is aimed based system like Java or .NET, it is GNU Classpath was practically the

MAY 2009 ISSUE 102 33 :FM

only game in town for a long time if you 2.0. The requirement of Apache compli- OpenJDK 6 with HotSpot, Kaffe, and wanted to run Java in a completely free ance precludes GNU Classpath, which Cacao. Fedora 9 ships with OpenJDK 6, environment. Classpath began as the li- carries the GPL “linking exception.” Ex- and other distributions should be follow- brary for the Japhar virtual machine, but actly why and when this might matter is ing suit if they haven’t already. as the various JVM projects figured out a bit subtle, but in some cases of interest that writing an independent standard li- to Apache, it does make a difference. N_XkKf;f6 brary cuts into actual JVM development, OpenJDK/ OpenJDK 6 is free, but it The good is that there is now an the various efforts began to merge. As a depends on Sun, both because its main easy option for free Java on Linux: Use result, GNU Classpath has been inte- code base comes from Sun and because OpenJDK with HotSpot. This option is grated with all of the free JVMs de- Sun’s license requires any modified ver- free as in speech and free as in beer, and scribed in this article except for HotSpot, sion to be “substantially derived” from it it is certified compatible with Sun’s which uses OpenJDK. in order to be able to use the TCK to en- usual offering. (For most purposes, it is Although GNU Classpath can’t use sure compatibility. For example, if you Sun’s usual offering. If you have a recent Sun’s TCK, it can be tested with Mauve. wanted to use OpenJDK as a base, but major distribution, chances are you’re Unfortunately, because both Mauve and replace half of the packages, you prob- already running it.) GNU Classpath are moving targets, I ably couldn't claim TCK compatibility. On the other hand, if you want to ex- can’t say whether Classpath is even Finally, Sun had not yet open sourced periment with different Java environ- Mauve compliant, although it seems safe its environment when Harmony was ini- ments, that shouldn’t be too hard either. to assume GNU Classpath is substan- tiated. Harmony is not a complete re- Stable packages are available for several tially Mauve compliant at any given mo- write of all the Java libraries, in that of the JVMs described in this article. ment. Mauve is becoming a better and many of the standard Java components If you want to experiment with a better proxy for TCK over time, so (e.g., Apache’s own XML libraries) are lesser-known JVM, particularly if it is there’s a good chance that GNU Class- already Apache-compatible open source one of the versions dating to the early path will “just work” for your purposes. implementations. The Harmony team 2000s or late 1990s and it was not de- But if you really care, you’ll have to seeks to integrate existing packages scribed in this article, you probably need check for yourself. when possible and write from scratch to roll up your sleeves. Most likely, you OpenJDK, or something substantially when necessary. won’t have OpenJDK available, and you derived from OpenJDK, is the only Harmony is currently still under devel- might not have GNU Classpath. If the choice if you want full Java TCK compli- opment with no official stable release in project doesn’t support Classpath or ance in a completely free environment. sight, although the site assures you the OpenJDK, you might have to settle for a OpenJDK is compatible with Sun’s JDK team is “making steady progress.” The less than complete set of libraries. The 5, and OpenJDK 6 (not too surprisingly) latest stable build is 5.08M, dated No- good news is, you don’t have to play is compatible with JDK 6. When cou- vember 13, 2008. To date, Harmony has around with these partial solutions un- pled with HotSpot, OpenJDK provides been integrated with SableVM, Jikes less you really want to – if you do, you the official, Sun-blessed open source RVM, Harmony’s own VM interpreter, probably won’t mind wrangling a few Java environment. and other VM implementations. It is a Makefiles. p [14] is an Apache bit unclear whether Harmony will end top-level project (as of 2006) aimed at up TCK compliant. The Harmony FAQ INFO providing an independent, free Java envi- states that it will, but Sun has not yet [1] IcedTea: http:// iced-tea. org/ ronment compatible with officially allowed access. [2] GNU Classpath: http://www. . org/ N_Xk software/ classpath/ GXZbX^\j6 [3] HotSpot JVM: http://openjdk. java. net/ groups/ hotspot/ has stable [4] OpenJDK: http:// . java. net/ packages for GNU [5] JamVM: Classpath, OpenJDK, http:// . sourceforge. net/ and OpenJDK 6. [6] Cacao: http:// www. cacaovm. org/ OpenJDK 6 with [7] Jikes RVM: http:// jikesrvm. org/ HotSpot is the default [8] Kaffe: http:// www. kaffe. org/ Java package for [9] SableVM: http:// www. . org/ . Kaffe, Cacao, and SableVM are also [10] GNU Compiler for Java: http:// gcc. gnu. org/ java/ available. Kaffe re- [11] JVM list: http:// www. kaffe. org/ links quires GNU Classpath. [12] IKVM: http:// www. ikvm. net/ The others can use ei- ther GNU or OpenJDK [13] Mauve: http:// sources. redhat. com/ mauve/ 6. RPMs are [14] Apache Harmony: =`^li\)1K_\Fg\eA;Bgifa\Zk`jYXj\[feJleËjfneAXmX available for GNU http:// harmony. apache. org/ ;\m\cfgd\ekB`k% Classpath, OpenJDK/

34 ISSUE 102 MAY 2009