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:

Debug Hotspot Zero with Eclipse

 

 

About these ads

13 Responses to Hacking Hotspot in Eclipse

  1. jerboaa says:

    Hey Roman! Nice blog post :) Looking at all the error markers, you might find Roland’s blog post useful: http://rgrunber.wordpress.com/2012/04/25/adding-header-files-to-your-cc-project/

    • Roman Kennke says:

      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.

  2. Pingback: How to build OpenJDK projects in Eclipse (for Ubuntu 12.04 LTS) « Mani's blog

  3. neomatrix369 says:

    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:

    Eclipse projects for the OpenJDK:
    http://wp.me/p2DZ25-4

    Netbeans projects for the OpenJDK:
    http://jug.ua/2012/07/how-to-build-openjdk-projects-from-netbeans/

  4. Hi Roman,

    Thanks so much for providing this. I’ve added it to our Adopt OpenJDK wiki (http://java.net/projects/adoptopenjdk/pages/AdoptOpenJDKVMBuild#Hotspot) and will try to get it verified and set-up in our VM that we hand out to folks.

    Cheers,
    Martijn

  5. Jenny Z says:

    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!”

    Can you give more details, like what is the c/c++ application?

    Thanks,
    Jenny

    • Roman Kennke says:

      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.

  6. Jenny Z says:

    Roman,

    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.

    • Jenny Z says:

      Roman,

      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!

  7. Vlad says:

    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!

  8. Pingback: Hotspotâ„¢ is in focus again -aka- Hacking Hotspotâ„¢ in Eclipse Juno under Ubuntu 12.04! | Mani's useful blogs

  9. neomatrix369 says:

    Once again thanks to this blog along with other resources from the net, I have been able to write a new blog focussing on building Hotspot on Eclipse Juno under Ubuntu 12.04 using the new build-infra system: https://neomatrix369.wordpress.com/2013/03/12/hotspot-is-in-focus-again-aka-hacking-hotspot-in-eclipse-juno-under-ubuntu-12-04/, have a look comments and feedback are always welcome!

    Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 160 other followers

%d bloggers like this: