May 2008

Congratulations to the IcedTea team (Lillian Angel, Gary Benson, Tom Fitzsimmons, Joshua Sumali, Andrew Haley, Mark Wielaard) on another release. The OpenJDK version is only one drop further on (b09 as opposed to b08) but there are lots of other IcedTea related changes including the import of MIDI support via Gervill and a Linux/SPARC HotSpot port, not to mention numerous fixes and jtreg-based testing. Gentoo users can already find an ebuild for this in my overlay:

Unfortunately, creating this ebuild immediately showed up a few issues with the release. The first was rather peculiar, it seems the jar executable from IcedTea 6 1.1 couldn’t handle the @ option used to build the rt.jar file:

(cd /var/tmp/portage/dev-java/icedtea6-1.2/work/icedtea6-1.2/openjdk-ecj/control/build/linux-amd64/classes
&& /bin/cat /var/tmp/portage/dev-java/icedtea6-1.2/work/icedtea6-1.2/openjdk-ecj/control/build/linux-amd64/tmp/jarfilelists/rt_jar_list
| /usr/lib/jvm/icedtea6-1.1/bin/jar c0mf@
           -J-Xmx896m -J-Xms128m -J-XX:PermSize=32m
Illegal option: @
Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point]
[-C dir] files ...

Interestingly, using gjar does work, so for the time being I’ve enforced the use of gcj-4.3 in the ebuild, and used gjar from this. Patching it so that it becomes /usr/lib/jvm/icedtea6-1.1/bin/jar c0mf should also work.

The other issue I ran into was with the plugin option. Gentoo’s econf system specifies all the configure options it uses even if the values are the defaults, due to the way it is automated. So even though the plugin is enabled by default, –enable-gcjwebplugin still gets passed to the build. However, it seems this actually disables it for IcedTea6. I patched this as:

diff -r 3fe8a0881e86
--- a/      Wed May 28 11:29:51 2008 -0400
+++ b/      Fri May 30 00:53:44 2008 +0100
@@ -101,13 +101,13 @@ AC_ARG_ENABLE([gcjwebplugin],
                              [Disable compilation of browser plugin])],
-             [ENABLE_PLUGIN="$val"], [ENABLE_PLUGIN='yes'])
+             [ENABLE_PLUGIN="${enableval}"], [ENABLE_PLUGIN='yes'])

                              [Disable generation of documentation])],
-             [ENABLE_DOCS="$val"], [ENABLE_DOCS='yes'])
+             [ENABLE_DOCS="${enableval}"], [ENABLE_DOCS='yes'])


This wouldn’t have been noticed because usually you either stick with the default (which does turn on the plugin) or, if an option is specified, you disable it (which happens). The problem is that specifying either form of the gcjwebplugin option disables it, including the one that’s meant to enable it.

With these two issues fixed, IcedTea6 1.2 can be installed on Gentoo.

One interesting issue when writing a runtime class library for Java is how to give implementation packages, whether they be in gnu.* or com.sun.*, specialised access to the core runtime classes like those in java.lang. We ran across this problem again recently with GNU Classpath when trying to write CPStringBuilder. This is a StringBuilder variant that differs in how it utilises its internal character array. StringBuffer and StringBuilder both maintain their own character array throughout their life, creating a new larger one and copying when appropriate. When toString() or substring(int,int) is called, the new String object is given a copy of the array.

CPStringBuilder instead optimises for the frequent cases where a StringBuilder is created, used to build a String and then discarded after toString() is called. It does so by handing a reference to the character array to the new String object on creation. Once this is done, it flags internally that the array has been used and creates a new one if any further writes are requested. Thus, using CPStringBuilder should always be one copy more efficient than using StringBuilder or StringBuffer (possibly even creating just a single array if the final string is within the initial capacity) and we now use it internally when the builder does not need to be thread-safe.

The problem with implementing this is that it requires passing the array to the constructor of the String object. There is no such constructor in the public API for String, although Classpath has had a package-private one for sometime (GCJ and String itself already use it). But how do we access this from the package? Our current method is to use reflection, and thus we have VMCPStringBuilder so VMs can optimise this natively.

When looking through OpenJDK for the VM project, I noticed that they have a rather interesting solution to this. This is encapsulated in sun.misc.SharedSecrets. This class provides access to instances of a number of public interfaces, such as sun.misc.JavaLangAccess. The actual implementations are provided as inner classes in the appropriate package e.g. java.lang, where it has access to the private and package-private variables and methods within. For instance, JavaLangAccess provides access to the constant pool for a particular class.

The only noticeable negative side effect of this is that any external class may also call these methods. For example:

import sun.misc.SharedSecrets;

public class TestSecrets
  public static void main(String[] args)

whereas the equivalent for GNU Classpath:


public class TestCPSecrets
  public static void main(String[] args)
    System.out.println(VMCPStringBuilder.toString(new char[]{'H','e','l','l','o'},0,5));

fails to compile because VMCPStringBuilder is package-private (although the equivalent is possible by using CPStringBuilder in this case). As a result, it becomes slightly more important to ensure that the possible damage from using these classes is limited.

That said, this may be an interesting and more efficient method for us to look into for GNU Classpath.


So I went to the rms talk last Thursday and throughly enjoyed it. This was the second time I’d seen him speak, and can certainly recommend it to others. As others have remarked, he is quite entertaining to listen to and the way he upholds and adheres to his values is worthy of admiration. The last time I saw him speak (maybe three or four years ago in Sheffield), it was on the subject of software patents. This time round, I was treated to a more general FOSS talk, which touched on well-known topics such as the history of GNU, the whole GNU/Linux debacle and truly Free distros along with DRM. rms also made specific mention of commercial Free Software (a common point of confusion for many) and of Free Software in education.

The latter I feel is very important and, as I currently work in a University, it’s a topic close to my heart. Access to source code is an invaluable learning aid. The few pieces of source code our students see, that they haven’t developed with their own hands, are throughly mothballed pieces of code which barely hang together by a string, having being developed by one academic long ago and then passed on like some hand-me-down. They certainly aren’t examples of good coding, but you won’t always find this in Free Software either. What you will find is code that has been used by hundreds if not thousands of users. Code which has been built on numerous platforms and maintained by GNU/Linux distributions. Code which has stood the test of time and experience, even if it still comes out dirty at the end. By contrast, the examples most students see are reused year after year with little to no change to the code. One of our lecturers is currently only distributing the code the students need as binary simply because the code itself is so ugly and hairy he doesn’t want them to use it as an example. The advent of the OpenJDK project will help, because it should mean that the software on the desktops of Free Software users more and more utilises Java. Why is this important? Because the majority of students are taught Java first and foremost. Most of our students never use C throughout their undergraduate life. So examples of big bodies of Java code are what’s needed and the OpenJDK is a great contribution in this respect, as is GNU Classpath — they both provide samples of the good, the bad and the ugly.

The other important point about Free Software in Education is the ‘get them while they’re young’ theory, which rms likened to addicting children to drugs. He seems to like harsh metaphors, but this one I feel is not too overboard. Certainly, proprietary software vendors provide school and university students with cut-down or gratis copies of their wares. The students get used to this software and start to use it. In many cases, they are effectively forced to, as part of their studies. When they then step out into the big wide world, this is all they know. And our teachers and lecturers, far from promoting sharing and education as they should, are helping this addiction process, even if it’s simply by distributing a Word document to students or using that as the format for a handin. I’ve had to repeatedly mail back our university admin staff of late to obtain the minutes to meetings in a format other than the Word document they keep dropping in my inbox. One would hope they would start to take the hint…

For the finale of the talk, we were lucky enough to be visited by St. IGNUcius of the Church of Emacs. rms then took questions from the audience for well over an hour. He has a very admirable way of doing this; he clearly takes in every word being said, and you can hear the response before it comes when someone mentions ‘open source’ rather than ‘free software’ or some other faux pax, which they really should have known better than to utter, given the preceding two hours talk. I’m really surprised rms didn’t get more exsasperated than he did at some of them. I guess he must be used to it by now. He certainly seems to have a clear well-thought out answer for everything.

For those who couldn’t make the talk, I recorded it in full (with questions) and, with the help of Tim Dobson from the Manchester Free Software group, have made this available on-line. Where possible, we’d prefer you obtain the video from the torrent to reduce bandwidth load on those kind enough to host this. You can find the appropriate links on my website. If anyone would like to provide a further HTTP mirror of this, please get in touch. You can also help the Free Software community by helping to seed this via BitTorrent — this will help others get a copy :)