Yeah – download the sources, install the required libraries, compile. Simple!
WHY would anyone want to do that?
Not entirely for the kicks, I must tell you. Or for the fact that it is open source and you can get your hands on the sources. Or for running your cpu at 150% and making it impossibly hot? Well if you are in search for drama – we can exchange laptops (Though I may be forced to get a replacement soon 😛 )!
I recently was on an ‘Advanced Concurrency’ training (No! I wasn’t the instructor) and that’s where I picked this idea of compiling the JDK (Wouldn’t it make a very good friend once you get to know him?). You can make some low level changes (Think: Go Deep! The JVM level?). Our instructor did something very cool. He was trying to show us how modern JVMs, on runtime, do dynamic compilation and give massive performance boost. To show us that and for even much more (to look under the hood), he added his own code to the debug-jdk and from that marriage, something beautiful was born. He could map his source-code with the jvm-optimized-one.
JDK8 is required for the compilation process to begin so please get that first.
We’d be compiling JDK9 (which is still in Development).
# scm is done using hg - mercurial $ sudo apt-get install mercurial # tell hg your name $ echo "[ui]" >> ~/.hgrc $ echo "username=nikunjlahoti" >> ~/.hgrc # clone the dev branch of jdk9 to a folder called 9dev $ hg clone http://hg.openjdk.java.net/jdk9/dev 9dev $ cd 9dev/ # Next execute the get_source.sh script to download everything in the forest $ chmod u+x ./get_source.sh $ sh ./get_source.sh # this may take some time & bandwidth # Reading the README would make things more clear. Do open the README-builds.html $ cat README # Configure the environment $ bash ./configure # Configure may fail when a particular dev library would not be present. # It would tell you what to install to fix that issue. And run Configure again. # Below is a list of libraries which were missing from my Ubuntu 14.04 $ sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfreetype6-dev libasound2-dev # Begin the compilation $ make all
On my machine
Linux 3.13.0-35-generic x86_64 x86_64 GNU/Linux it took around 40 minutes.
## Starting verify-modules
Checking dependencies across JDK modules
Access verification succeeded.
## Finished verify-modules (build time 00:00:59)----- Build times ------- Start 2014-09-18 00:06:26 End 2014-09-18 00:46:02 00:00:59 verify-modules 00:39:36 TOTAL -------------------------
Finished building OpenJDK for target ‘all’
Thu Sep 18 00:46:02 IST 2014
How to execute
$ cd 9dev/build/linux-x86_64-normal-server-release/jdk/bin $ ./java -version # openjdk version '1.9.0-internal' # OpenJDK Runtime Environment (build 1.9.0-internal-nikunj_2014_09_18_00_01-b00) # OpenJDK 64-Bit Server VM (build 1.9.0-internal-nikunj_2014_09_18_00_01-b00, mixed mode)