Monday, December 15, 2008

Setting Up a Development Environment for Maxine in Eclipse

To be honest, I prefer Eclipse over NetBeans. This is mostly because of being used to using it; I won't start any religious wars on this topic. So, when I discovered that the Maxine Mercurial repository also contains Eclipse .project files, I decided to switch. It meant a bit of work, but here is another tutorial on how to set up a development environment for Maxine - this time in Eclipse, and using the correct steps for building. Those were pointed out by Doug Simon, whom I thank for his help!

First of all, Eclipse is not officially available for Solaris. That doesn't seem to be a major problem; Java's platform independence promises seem to be justified in this regard. A build of Eclipse is available; the ZIP file just needs to be uncompressed, it contains a complete Eclipse installation.

Once Eclipse is installed, some suggestions by the Maxine developers should be followed. For instance, I use these settings in eclipse/eclipse.ini:

-vm /usr/jdk/latest
-vmargs
-XX:MaxPermSize=512m
-Xmx1g
-Xms512m
-Duser.name=Michael Haupt

It is also recommended to install some plugins that are useful for development. One of them was not installable for me, though; nevertheless, the workspace runs fine, the problem does not seem to be vital. One plugin that is not mentioned by the Maxine developers is the one for Mercurial; it can be installed by following the instructions given on the plugin home page.

Maxine Sources: Getting Them Right

One thing I learned during the past few days is that the maxine~netbeans-inspector project in the Mercurial repository is currently not active. Eventually, it will yield a new implementation of the Inspector as a bunch of NetBeans plugins instead of the Swing application that exists now. So, this project is not of any further interest for now, especially given this article is about Eclipse.

The two repositories to be cloned are now these:

https://kenai.com/hg/maxine~maxine
https://kenai.com/hg/maxine~extras

Note that the maxine~extras repository is empty. It may contain interesting things in the future, though.

For each of them, the following steps need to be performed.
  1. From the menu, select File->Import....
  2. In the Mercurial category, choose the Clone Repository using Mercurial option and click Next >.
  3. Enter the repository URL in the URL field and tick the Search for .project files in clone and use them to create projects. checkbox. Finally, click Finish.
Two things are odd about this setting, at least for me:
  • The clone dialog window does not close after finishing.
  • Existing projects are not recognised.
I believe this is due to the status of the Mercurial plugin.

To make the various Maxine projects available in the Eclipse workspace, the following needs to be done for the two subdirectories named maxine~maxine and maxine~extras (once it contains projects) in the Eclipse workspace directory.
  1. From the menu, select File->Import....
  2. In the General category, choose Existing Projects into Workspace.
  3. Click the Browse... button next to the Select root directory: text box and select the workspace/maxine~maxine directory.
  4. A list of importable projects appears. For me, the list contains the projects Assembler, Base, Inspector, JDWP, Native, Tele, TeleJDWP, VM, and VMDI. Do not tick the Copy projects into workspace check box; they are already there. Click Finish.
Once this is done, Eclipse will build the projects in the workspace. Do not bother about this; there is an external tool responsible for doing it right. By the way, for me, the console output window in Eclipse turns black once the Native project is built. This is funny but not problematic.

Building Maxine

Before I get to building, I need to mention libproc.h once more - it is still important to get this file and put it in the right place in the sources. The location has changed since my last posting; the file is now to be placed in the Native/tele/solaris directory.

Here's another thing I learned from Doug Simon. There is a convenient wrapper script for all things Maxine; it resides in maxine~maxine/bin and is called max. For the script to be able to work, the JUNIT4_CP environment variable must be set. This has to point to the JAR file containing the JUnit 4 classes. I set this variable in my ~/.bashrc as follows, boldly exploiting the fact that Eclipse comes with a JUnit 4 plugin:

export JUNIT4_CP=/export/home/haupt/eclipse/plugins/org.junit4_4.3.1/junit.jar

Running the max script without any arguments gives an informative help message detailing all the options that can be given. For now, the two commands that are of interest are build and image. In fact, building a complete Maxine VM and boot image is as easy as invoking the max script twice from within the maxine~maxine directory:

~/workspace/maxine~maxine$ bin/max build
~/workspace/maxine~maxine$ bin/max image

It is safe to ignore the warnings.

Running Hello World

Guess what: the max script can also be used to run Maxine! Running the Hello World application coming with the VM is now trivial:

~/workspace/maxine~maxine$ bin/max vm -cp VM/bin util.HelloWorld

That's all it needs.

No comments:

Post a Comment