Building a debug JVM

If you’re interested in learning more about the Hotspot’s internals, theres no way around it - you have to read the code. If you really want to learn, you’ll want to build and run a debug build. This isn’t too bad to do, but a dearth of online documentation makes this much rougher than it should be. I recently reimaged my VPS and recorded every step along the way, which I have relayed here.

Grabbing the source

To grab the code, you’ll need mercurial if you don’t have it aready.

sudo apt-get install mercurial

Java, like any complex project, has a dizzying number of branches. I recommend the jdk8u branch, aka Java 8 with updates.

hg clone

Java uses nested repositories to manage different parts of its codebase. Thankfully there is already a script to download all of those for us

cd jdk8u
bash ./

OS X users exit stage left

Unfortunately, actually building on newer versions of OS X is a bit of a mess. This blog post has what apparently is a working solution, but I have yet to try it. I keep a copy of the source on my Macbook for easy grepping but do all the actual work elsewhere.

Building the beast

Before you try to configure & make, might as well get all of the dependencies out of the way. This is every package I had to install on a fresh Ubuntu 14 build. If you skip this the ./configure script gives helpful hints on what install commands to run, but this is even easier. Yes, you need Java (7+) to compile Java

sudo apt-get install zip build-essential make openjdk-7-jdk libcups2-dev libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libfreetype6-dev libasound2-dev

(Replace apt with your distro’s package manager of choice. I built this on my work server fine using yum, although the package names may not have been identical)

Next up is the massive ./configure script. The --enable-debug tells it to configure the makefiles for a debug build

bash ./configure --enable-debug

On my server it kept complaining about freetype being missing, even after being installed. I got around this by finding the file locations via dpkg -L libfreetype6-dev and then manually specifying the lib and header locations to ./configure.

bash ./configure --enable-debug --with-freetype-include=/usr/include/freetype2/ --with-freetype-lib=/usr/lib/x86_64-linux-gnu/

With everything set up, all you need to do is run make all. Good time go to grab a cup of coffee/water, or maybe sword fight on chairs. When its done, why not quickly try our new binary?

jackson@serv:/home/jackson/dev/jdk8u$ build/linux-x86_64-normal-server-fastdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-jackson_2015_08_27_04_18-b00)
OpenJDK 64-Bit Server VM (build 25.66-b00-fastdebug, mixed mode)

That wasn’t too bad was it?