In this post we will learn how to download, compile and debug OpenJDK 8 using Ubuntu and NetBeans IDE.
Downloading and compiling OpenJDK 8
To get OpenJDK sources using Git, we need to clone OpenJDK repository mirror
provided by AdoptOpenJDK project.
To speed things up we will only clone
master branch without commit history:
Now when we have sources, its time to compile OpenJDK. First we need to install all required dependencies:
Then we must run
configure with two options:
--with-debug-level=slowdebug- enables generating debug information when compiling OpenJDK
--with-target-bits=64- we will generate 64-bit binaries
It may happen than
configure will return error telling you that you need
to install some additional tool/library. This is something to be expected,
just follow instructions printed by
You may need to do this several times until you will
have all required dependencies installed on your system.
Now it’s time to actually build OpenJDK:
This may take some time…
Now we may use our newly built
java to run “Hello, world!” program:
Creating project for OpenJDK 8 in NetBeans
You need to download and install NetBeans IDE. Since HotSpot is written in C++ we will need NetBeans with C/C++ support.
Now it is time to create project for OpenJDK in NetBeans. Select File->New Project…->C/C++ Project with Existing Sources…
Then select “Custom” configuration mode:
We must use the same
configure arguments that we used on command line:
Now click “Next” a few more times and then click “Finish”.
NetBeans should now run
configure and build OpenJDK, you should
see compiler output in Build tab:
After build ends you should see output similar to:
Now we should try to run our “Hello, World!” program from NetBeans.
Click on project and then select “Properties”:
Then go to “Run” category and click on “…” next to “Run command”, then
write any command that you want to run. Assume that
Now select Run->Run Project, NetBeans will ask you what binary you want to
Now you should see “Hello, world!” written in Output window:
Debugging with NetBeans
System.out.println(...) in Java will ultimately be handled
writeBytes function in
(this is only valid for Linux builds of OpenJDK).
Lets put a breakpoint inside that function and see what will happen when we try to debug Hello world program:
Select Debug->Debug Main Project. After executing this command you
may see window:
SIGSEGV for its internal purposes, from our point of view
we may just ignore it (select “Don’t Catch this Singla Again” and
“Forward and Continue”). After a few seconds we should be able to
catch a breakpoint and see what JVM is doing:
And that’s it! Now you will be able to check and understand how JVM is working under cover.