November 27th, 2013

by Ivan St. Ivanov

Today we had the first Adopt OpenJDK workshop in the Bulgarian Java User Group. It had one simple goal: to teach the attendees what contributing to OpenJDK means. The hackathon was driven by three of us: I, Martin Toshev and Dmitriy Alexandrov.

Set it up

We started by showing the other developers how they can set up their environment. Before the meeting everyone was invited to download the VM that Martin prepared beforehand. Those of the attendees that had not done that received it by copying it from our flash drives. We taught them of the three most important commands when working with OpenJDK:
bash configure
make clean images

The first one downloads and merges all the new sources from the OpenJDK repository, the second one prepared the build environment and the third one cleans the old build results, compiles, links and creates JDK and JRE images.

Well, unfortunately it did not run flawlessly. The command seemed to not delete some files that were removed in the repository. So these files had compilation errors. But before we found that, we decided to fix those errors in the OpenJDK code. For example there was a class (which we later found that was removed centrally) that used the following method:

ListBuffer<Attribute.Compound> compounds =;

However, the ListBuffer class lacked that static method. So we decided to add it (check out the diamond operator syntax ;)):

public static <T> ListBuffer<T> lb() {
    return new ListBuffer<>();

Then we ran make again. This was a good starter for us: our first change in the OpenJDK code. However, we gave up when we hit an error in the hotspot C++ code. As a fallback we returned to our initial state of the VM, where we did not run anymore.

Fun with StringBuilder

The next part of the session was devoted to hacking. We picked up the StringBuilder class. First we went through it in order to see how it is represented internally, what is its initial capacity, what happens when a string is appended to it (which is what goes on when you write String a = “Hello” + “ world”;) and what is its expansion strategy.

StringBuilder stores its underlying data in a character array (called value). Initially it is created with a default capacity of 16, or as big as the user specifies if they call the explicit constructor. The class has also an integer field called count, which keeps track of how long the actual string is, i.e. how many elements of the char array contain real data. If the underlying array does not have enough unoccupied elements when appending a String or other object, it is extended by the factor of 2.

After looking at these and some other details we added a very valuable method: isEmpty() (thanks to Hildeberto Mendonca for giving this idea to me!), which simply checks whether the count field is equal to 0:

public boolean isEmpty() {
    return count == 0;



Then Dmitriy gave a short presentation on the JTReg test harness, which is used to test the JDK classes. He then wrote one such test, ran it from the command line and showed the resulting report files. He then intentionally broke the test, ran it again and showed an error report file. Modern OpenJDK tests are written using the TestNG test framework, so at the end we rewrote the test using that.

What’s next

Our first Adopt OpenJDK hackathon session concluded with an overview of our future plans. Next week we are going to hold some hands-on labs at the Java2Days conference. There we plan to make real (though small) patches and contributions to the official project. We also plan to do some Java 8 Lambdas hacking. We are very happy to announce that will be joined by LJC’s Mani Sarkar for the event.

After the conference we will keep meeting at least once per month, when we can do some more small changes to JDK 8 (as bigger ones will hardly be accepted). We would also like to contribute to Java 9 projects like jigsaw, penrose or probably a new port of the hotspot VM. We might also work on supportability tools that are not part of the JDK like betterrev.

Thanks to everybody, who joined this session! I do believe that we are going to have great fun and learn a lot in the upcoming months!

Leave a Reply