Posted on November 21, 2014

Building openJDK8 by myself (part 2)

back in April I did a build of OpenJDK 8, kind of just for fun, to see if I could do it and how hard it was. since I’m doing Java again and I wanted to experiment with the new things in Java 8, I decided to give it another go.

here’s a few things I learned (on a Debian system):

Make 4

if you’re already using make version 4, you’re going to have to downgrade. there’s a bug filled for it but the bottom line right now is that you’ll have to downgrade.

GCC 4.9

If you’re already on GCC 4.9 though, your build might end up a bit faster. For me it went from 8 minutes to 6 on a system which has exactly the same hardware.

update-alternatives

I tried to look for something like rvm or nvm but to no avail. So to keep both JDK versions on the same system, you can’t escape changing JAVA_HOME and calling update-alternatives.

Full log

Configure the build with bash configure and it produces the following:

    ====================================================
    A new configuration has been successfully created in
    /home/luis/dev/jdk8/build/linux-x86_64-normal-server-release
    using default settings.
    
    Configuration summary:
    * Debug level:    release
    * JDK variant:    normal
    * JVM variants:   server
    * OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
    
    Tools summary:
    * Boot JDK:       java version \"1.7.0_65\" OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-2) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)  (at /usr/lib/jvm/java-7-openjdk-amd64)
    * C Compiler:     gcc-4.9 (Debian 4.9.1-19) version 4.9.1 (at /usr/bin/gcc-4.9)
    * C++ Compiler:   g++-4.9 (Debian 4.9.1-19) version 4.9.1 (at /usr/bin/g++-4.9)
    
    Build performance summary:
    * Cores to use:   10
    * Memory limit:   32157 MB
    * ccache status:  installed, but disabled (version older than 3.1.4)

Now we build with make all and after 6 minutes:

    ----- Build times -------
    Start 2014-11-21 00:19:18
    End   2014-11-21 00:25:23
    00:00:15 corba
    00:00:06 demos
    00:01:07 docs
    00:01:41 hotspot
    00:00:12 images
    00:00:11 jaxp
    00:00:15 jaxws
    00:01:43 jdk
    00:00:26 langtools
    00:00:09 nashorn
    00:06:05 TOTAL
    -------------------------
    Finished building OpenJDK for target 'all'

Let’s put that JDK somewhere and reconfigure the environment:

And now let’s verify:

    $ update-alternatives --display java                                             
    java - auto mode
      link currently points to /opt/java8/jdk/bin/java
    /opt/java8/jdk/bin/java - priority 1100
    /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
      slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
    Current 'best' version is '/opt/java8/jdk/bin/java'.

and

    $ update-alternatives --display javac
    javac - auto mode
      link currently points to /opt/java8/jdk/bin/javac
    /opt/java8/jdk/bin/javac - priority 1100
    /usr/lib/jvm/java-7-openjdk-amd64/bin/javac - priority 1071
      slave javac.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/man/man1/javac.1.gz
    Current 'best' version is '/opt/java8/jdk/bin/javac'.

since the current best versions in both cases are java 8, we’re good. now let’s update JAVA_HOME in our .zshrc or equivalent:

    export JAVA_HOME=/opt/java8/jdk

After restarting the terminal, we’re ready to try this guy out:

    $ java -version
    openjdk version \"1.8.0-internal\"
    OpenJDK Runtime Environment (build 1.8.0-internal-luis_2014_11_20_23_36-b00)
    OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)

and

    $ mvn --version
    Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T15:51:42+02:00)
    Maven home: /opt/maven3
    Java version: 1.8.0-internal, vendor: Oracle Corporation
    Java home: /opt/java8/jdk
    Default locale: en_GB, platform encoding: UTF-8
    OS name: \"linux\", version: \"3.16.0-4-amd64\", arch: \"amd64\", family: \"unix\"

Now let’s try something new!

    import java.util.stream.IntStream;
    
    public class Range {
    
        public static void main(String[] args) {
    
            IntStream.range(0, 10).forEach(
                    nbr -> System.out.println(nbr)
            );
        }
    }

and let’s compile and run this with Java 8:

    $ javac Range.java   
    $ java Range
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9

and now let’s try with Java 7:

    $ /usr/lib/jvm/java-7-openjdk-amd64/bin/javac Range.java 
    Range.java:8: error: illegal start of expression
                    nbr -> System.out.println(nbr)
                         ^
    1 error

:-)