Building a debug JVM
26 Aug 2015If 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.
Java, like any complex project, has a dizzying number of branches. I recommend the jdk8u
branch, aka Java 8 with updates.
Java uses nested repositories to manage different parts of its codebase. Thankfully there is already a script to download all of those for us
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
(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
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
.
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?
That wasn’t too bad was it?