Woah! What a day! For those who don’t already know (due to living in a small cave in Outer Mongolia), Sun today announced that it will be releasing J2SE, J2ME and J2EE under the GNU GPL. What is especially exciting about this is that the class library, which will be released early next year, will be out under GPL+Classpath exception, the exact same license used by GNU Classpath, thus allowing a beautiful merging of codebases… (we hope).

So it follows that I’ve been somewhat distracted today, following the webcast and chat conversations on this stuff. Also, the release of javac today under the GPL was too good an opportunity to miss — we had to get this working with GNU Classpath and friends! Unfortunately, it seems Sun don’t follow their own advice, and the code has references to sun.* stuff. But a bit of mad-cap hacking soon sorted this. To build your own javac with ecj, GNU Classpath generics branch and a Free VM, follow these instructions:

0) Compile a modified version of the current generics branch by including the stubs in this zip file.
1) Download the Sun javac source tree using svn checkout https://openjdk.dev.java.net/svn/openjdk/compiler/trunk –username guest
2) Build it using your favourite technique. I found it easiest to just hack the Makefile to use my own script for running ecj:

#!/bin/bash

ecj -1.5 -bootclasspath ~/projects/java/classpath/generics-build/share/classpath/glibj.zip $@

and then used make. Make sure that ecj is using the generics branch that you compiled earlier.
3) With luck, you should get a set of classes in build/bootclasses.

Problem then is that nothing will actually run the compiled javac — well, to compile stuff anyway. jamvm can at least get the config info and the version number:

$ jamvm -cp ../trunk/build/bootclasses:../trunk/src/share/classes com.sun.tools.javac.Main -version

javac 1.7.0-opensource

It fails when it comes to compiling and the annotation stuff fails with our regular expression implementation. Someone up for some hacking? gij (gcj-eclipse branch) fails earlier with a NullPointerException in a call to EnumSet.of() — I’m guessing this is due to the FIXMEs in isEnum()…

Anyway, I think this is a good start. Next, we get the VM to run with Classpath… ;)

Update

The regex problem was simple to fix, and I’ve committed a patch to the generics branch. jamvm now fails due to a missing implementation of sun.misc.Unsafe:

java.lang.UnsatisfiedLinkError: objectFieldOffset
at sun.misc.Unsafe.objectFieldOffset(Native Method)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.(AbstractQueuedSynchronizer.java:2124)

Any VM have this yet? I think gcj-eclipse does, but lacks isEnum… (or maybe I just need a newer version???)