Custom OpenJDK 12 Builds on Ubuntu 18.04

December 19, 2018

I wrote before about creating a custom build of OpenJDK 10 and 9, this post is an update for OpenJDK 12.

This post is basically a summary of <OpenJDK 12 repo>/doc/ document and a specific tutorial for Ubuntu 18.04.

As usual, I am using a linux container for this build. So, lets create a container first.

$ lxc launch ubuntu:18.04 openjdk12
Creating openjdk12
Starting openjdk12
$ lxc exec openjdk12 -- su - ubuntu

You can clone the OpenJDK 12 repo or get a snapshot. The repo is not small (cloned repo at the time of writing this post is 2.5G), so it takes some time to clone. I will download the snapshot of jdk-12+24 tag, it is 83M.

$ wget
$ bunzip2 7d4397b43fa3.tar.bz2
$ tar xvf 7d4397b43fa3.tar

You need to install required packages for build.

$ sudo apt-get install build-essential autoconf unzip zip

In order to build the OpenJDK, you need a boot JDK. Typically if you are building the version N of JDK, you need version N-1 of JDK installed. If you run bash configure, it will say you need openjdk-8-jdk but it is an error, it should be OpenJDK 11. If you install openjdk-8-jdk, then bash configure will also raise an error, and say you need either 11 or 12 as boot jdk. So I will download the OpenJDK 11.0.1.

$ wget
$ tar xvf openjdk-11.0.1_linux-x64_bin.tar.gz

Lets now try to configure:

$ cd jdk12-7d4397b43fa3
$ bash configure --with-boot-jdk=../jdk-11.0.1

configure: error: Could not find X11 libraries. You might be able to fix this by running 'sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev'.
configure exiting with result code 1

So lets install them:

$ sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev

We need a few more packages, I actually run bash configure a few more times and see what it asks for. Below is all the packages needed:

$ sudo apt-get install libcups2-dev libfontconfig1-dev libasound2-dev
$ bash configure --with-boot-jdk=../jdk-11.0.1

Finally everything is OK.

If you are going to build it multiple times, it is better to install and enable ccache, and I will do that. I will also later use --enable-ccache option of configure.

$ sudo apt-get install ccache

Use make dist-clean to clean all intermediate files and configuration before doing another build.

$ make dist-clean
$ bash configure --with-boot-jdk=../jdk-11.0.1 --enable-ccache

Configuration summary:
* Debug level:    release
* HS debug level: product
* JVM variants:   server
* JVM features:   server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc' 
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 12-internal+0-adhoc.ubuntu.jdk12-7d4397b43fa3 (12-internal)

Tools summary:
* Boot JDK:       openjdk version "11.0.1" 2018-10-16 OpenJDK Runtime Environment 18.9 (build 11.0.1+13) OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)  (at /home/ubuntu/jdk-11.0.1)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 7.3.0 (at /usr/bin/gcc)
* C++ Compiler:   Version 7.3.0 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   4
* Memory limit:   31929 MB
* ccache status:  Active (3.4.1)

$ time make

Finished building target 'default (exploded-image)' in configuration 'linux-x86_64-server-release'

real  8m52.763s
user  25m29.245s
sys   2m5.928s

It is a success. Default make target builds the exploded-image, if you want a normal JDK like build, use make images.

$ make images
$ export JAVA_HOME=$HOME/jdk12-7d4397b43fa3/build/linux-x86_64-server-release/images/jdk
$ export PATH=$JAVA_HOME/bin:$PATH
$ java -version
openjdk version "12-internal" 2019-03-19
OpenJDK Runtime Environment (build 12-internal+0-adhoc.ubuntu.jdk12-7d4397b43fa3)
OpenJDK 64-Bit Server VM (build 12-internal+0-adhoc.ubuntu.jdk12-7d4397b43fa3, mixed mode, sharing)