Hacking Hotspot in Eclipse

I recently started working on Hotspot, with the goal of getting the Zero port up-to-date with respect to he recent developments in MLVM. In order to work most efficiently, I set up a work environment in Eclipse, and thought it’d be useful to share a little HOW-TO.

First of all, you need to install Eclipse/CDT if you haven’t already. This gives you a very powerful C/C++ development environment in Eclipse.

You can then open an OpenJDK source tree as C/C++ project by selecting: File -> New -> Other and then ‘C/C++’ -> ‘Makefile project with existing code’. Enter project name, e.g. OpenJDK8, and the path to the existing location. Select the appropriate ‘Toolchain for indexer Settings’ below. Click Finish.

Then open the project properties by right-clicking on the project, and selecting ‘Properties’. There we need to setup a couple of things.Under ‘C/C++ Build’ -> Environment, enter all environment variables that you would normally set on the command line for building OpenJDK. At the very least, you need ‘ALT_BOOTDIR’ and LANG=C. Under ‘C/C++ Build’, click the tab ‘Refresh Policy’ and remove the only path that is there (otherwise the whole workspace will be refreshed after a build, which takes looooong’). Optionally, add any paths under ‘build’ that you are interested in. Under ‘C/C++ General’ -> ‘Paths and Symbols’, select the tab ‘Source Location’ and remove the toplevel project path, and enter any source paths you are working with (e.g. hotspot/src). This limits what is visible to the indexer, etc. In order to take full advantage of Eclipse for debugging, I also changed ‘C/C++ Build’, ‘Behavior’ tab, replace ‘all’ with ‘debug_build’ This will normally do a debug build of OpenJDK, which means that you get all the symbols and no compiler optimizations in the binaries. In order to be able to load the symbols in gdb, add ‘ZIP_DEBUGINFO_FILES=0′ into the environment variables.Then click ‘Apply’ and ‘OK’ to close the settings dialog. Select ‘Project -> Build Project’ to launch the first build of OpenJDK in Eclipse.

Debugging with Eclipse is similarily straightforward, open Debug Configurations, add a new C/C++ application, set up its properties for the binary, arguments and environment variables (make sure you use a debug-build binary) and run the thing! Being able to fully debug in Eclipse, navigating stack, inspecting variables, setting breakpoints and stepping through the code is so much more useful than doing the same in plain GDB:

Yes, that sounds useful indeed. Although in this case I don’t think it’s related to missing header files. I took the screenshot on a fresh setup, without doing a full build, and the symbols have not been discovered yet. After doing a full build, there should be much less markers.

Thanks for your blog, myself (mani) and Andrii Rodionov (JUG Ukraine) have used your blog as inspiration to come up with our own sets of instructions for Eclipse and Netbeans respectively, please have a look and feedback:

Nice post. The steps I am missing is
“Debugging with Eclipse is similarily straightforward, open Debug Configurations, add a new C/C++ application, set up its properties for the binary, arguments and environment variables (make sure you use a debug-build binary) and run the thing!”

Jenny: Yes, sorry. Under application, you need to enter the path to the java launcher binary (usually it’s under build/$PLATFORM/bin/java), then the command line parameters (like -classpath, the main classname, etc, just as you would launch the program from the command line). Let me know if you need anything else.

Thanks for the quick response. The issue I am facing, after setting c/c++ application as /bin/java -classpath HelloWorld, and debug as local c/c++ application, it gives error “Launch failed, Binary not found”. The libjvm.so is rebuilt. If I copy the newly build libjvm to a bootstrap jdk, it works.

I have a c++ project helloworld, under it has Binaries. But the jdk project does not have that.

I got it work…but do not understand why it works in one way but not the other.
Does not work: right click project ->Properties->Run/Debug Settings -> create new configuration: under Main, c/c++ application: click browse and select the bootstrap jdk. Under Arguments, enter -classpath Hello. Right click project, select debug as Local c/c++ application. ERROR: binary not Found

Works: From the menu Run-> Debug Configurations (or Run Configurations). Left panel lists the applications, under c/c++ application, select my project. In right panel, under Main, c/c++ application: click browse and select the bootstrap jdk. Under Arguments, enter -classpath Hello and Apply. From the Run Menu, select Run or Debug.

Not sure why it works one way not the other. But as long as it works. I am happy. Thanks!

Thanks a lot for the tutorial, it was great to find all the instructions on the web!

I encountered a problem and thought I share the solution here: the source code of hotspot/src/cpu/x86/c1/c1_Canonicalizer.hpp was littered with errors. Ctrl-clicking on the symbols took me to the root of the problem: jint and jlong were defined twice (and incompatibly) by:
– the openjdk headers in hotspot/src/cpu/x86/vm/jni_x86.h
– the gcc include directory /usr/lib/gcc/x86_64-linux-gnu/4.6/include/jni_md.h

And transitively this would lead to Eclipse reporting errors everywhere throughout the hotspot code.

I couldn’t find a way to exclude the gcc standard jni_md.h file (maybe there is a way to do it, I just couldn’t find it) so I looked at the package that installs it:
$ dpkg -S /usr/lib/gcc/x86_64-linux-gnu/4.6/include/jni_md.h
gcj-4.6-jdk: /usr/lib/gcc/x86_64-linux-gnu/4.6/include/jni_md.h
$ sudo apt-get install gcj-4.6-jdk

Restarted Eclipse, right-click on the hotspot project, Index > Rebuild and opened the file again — woohoo, no more errors!