Using Netbeans to Hack OpenJDK9 in Ubuntu

In a previous post I wrote about how to build OpenJDK 9.  This is cool,  but my objective was to mess around with the sources of Hotspot and modify it, so I must have a way to write my changes and debug them.

I’m using as main source of reference a very good book from Kasko, Kobylyanski and Mironchenk the OpenJDK Cookbook.  Unfortunately the book only describes the building until JDK 8, so I’m writing my way to have a development environment to play with the Hotspot code of the OpenJDK 9.

Install Netbeans

I downloaded the ALL distribution installer of Netbeans from their download page. The installer is a .sh that you simply execute:


The only remarkable point here is to customize the installation and select only the needed components:


I could have simply selected them all, but you’ll spend space useless of your HDD.

Afterwards I needed to increase the RAM available for Netbeans. To do so:

  1. I went to the $HOME/.netbeans/<YOUR_NETBEANS_VERSION>/etc directory (create it if it does not exist)
  2. If the folder does not contain the netbeans.conf file, copy it from the folder where Netbeans is installed.
  3. Opened the netbeans.conf file and look for the netbeans_default_options parameter which looks like listing 1, then give it more memory by adding the -J-Xmx2g option is not already present (2g is for 2 Gigas, I put 4G, since my machine has 8):
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m
-J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.
noddraw=true -J-Dsun.java2d.dpiaware=true
disableMemoryMapping=true -J-Xmx4g"

 Listing 1. How the netbeans_default_options variable should look.

Create the project

After Netbeans is installed, I executed it and created a project for OpenJDK, by going to File | New Project. On the new project Dialog, I selected C/C++ Project with Existing Sources:


Following, I specified the path for my OpenJDK sources and choose the Custom configuration mode.


At the end of the text in the Configure Arguments box, I added the following lines:

--with-debug-level=slowdebug --with-target-bits=64 --with-native-debug-symbols=external


Then pressed Next. This will create a folder named linux-x86_64-normal-server-slowdebug in the build folder. No more configuration needs to be done, unless another configuration folder already exists in the build directory (i.e. linux-x86_64-normal-server-release). In this case you may simply delete the old folder or change the build command in the Build Actions tab to make an specific configuration.

At the end of this process, Netbeans will build the complete OpenJDK project, which will be a length operation, so you can go for a break.

Working only with Hotspot

By default, the configuration I just created builds the whole OpenJDK, which is pretty lengthy to compile. Therefore, I needed to create a build configuration to build only Hotspot.

To do so, I went to the menu Run | Set project configuration | Customize. Clicked on Manage Configurations and duplicated the existing configuration. Then, in the Build | Make tab, I modified the  Build Command and Clean Command parameters like so:

Build Command: build/
Clean Command:${MAKE} clean
Build Result: build/linux-x86_64-normal-server-slowdebug/jdk/bin/java


Basically, I indicated Netbeans to run a custom shell script for us each time the project is going to be built. The Build Result parameter is configured to tell Netbeans the executable or library we are going to use to debug or run, in this case the java exectutable created in the first complete compilation.

Now, I proceeded into creating the shell script that will launch the compilation of Hotspot only, using make hotspot command. This way we ensure that the make command only launches the build of Hotspot.

make hotspot && echo Copying resulting files to the JDK folder
cp -u $srcFolder/libjsig.debuginfo $destFolder
cp -u $srcFolder/ $destFolder
cp -u $srcFolder/libjvm.debuginfo $destFolder
cp -u $srcFolder/ $destFolder

The rest of the commands are to copy the result of the Hotspot compilation into the JDK image, so they are actually used.

Launching the debugger

Go to the Run tab of the project properties. In the Run Command parameter, you may configure the arguments to your run. In my case, I’m running some JMH microbenchmarks tracing the loop predicate optimization. My OpenSDK9 Java is stored in the ${OUTPUT_PATH} variable.


Afterwards, you may place a break anywhere you want and launch the debugger with Ctrl+F5.


To the people of the AdoptOpenJDK, mailing list, specially to Volker Simonis for his help.


  1. OpenJDK Cookbook
  2. Open Heart Surgery: Analyzing and Debugging the Java HotSpot VM at the OS Level
  3. Hotspot Development Linux Netbeans Part 2
  4. Debuggin OpenJDK


Leave a Reply

Your email address will not be published. Required fields are marked *