Compiling the InChI Toolkit to Pure Java Bytecode with NestedVM 6

Posted by Rich Apodaca Mon, 29 Oct 2007 15:13:00 GMT

Some time ago, a Depth-First article discussed some methods for compiling C to Java bytecode. Many factors make this approach attractive compared to the JNI approach. Some of them include security, portability, and use within applets. Unfortunately, none of the approaches discussed in the earlier article seemed particularly general.

Many cheminformatics libraries are written in C and C++; being able to reliably and automatically port them to Java could potentially save a great deal of effort.

One of the more important cheminformatics C libraries written in recent years is the InChI toolkit. With no pure Java port of this library, JNI is the only way to use InChI with Java. In some situations, this approach is either overly complicated or simply unacceptable.

All of this leaves us with the question: how can the InChI toolkit be converted into a pure Java library without writing any new code?

A partial answer to this question came from Evan Jones, who suggested I look at NestedVM. From the website:

NestedVM provides binary translation for Java Bytecode. This is done by having GCC compile to a MIPS binary which is then translated to a Java class file. Hence any application written in C, C++, Fortran, or any other language supported by GCC can be run in 100% pure Java with no source changes.

And it worked!

NestedVM was successfully used compile the InChI-API distribution to a Java class file that executed on nothing more than a standard JVM -- and with no JNI code. The InChI classfile and nestedvm runtime jarfile can be downloaded from SourceForge. Future articles in this series will describe the compilation, installation, and use of NestedVM, as well as the Java class file that it produced.

Image Credit: pmorgan

Comments

Leave a response

  1. Egon Willighagen Tue, 30 Oct 2007 06:03:47 GMT

    Hi Rich, that sounds very exciting! Is the resulting jar completely platform independent?

  2. Rich Apodaca Tue, 30 Oct 2007 12:58:31 GMT

    Egon - as far as I can tell, the jar has no native code and should be 100% portable. Give it a shot -- I'd be interested in your experience.

  3. Andrew Dalke Wed, 31 Oct 2007 12:36:18 GMT

    This is crazy-cool!

  4. Joerg Kurt Wegner Thu, 01 Nov 2007 20:08:39 GMT

    Just image you can port those nasty Fortran codes to Java? Wow, amazing! There are several Fortran codes around, but porting them to Java is even worse then porting C or C++.

  5. Rich Apodaca Fri, 02 Nov 2007 04:53:28 GMT

    Joerg,

    Could you think of some fairly simple FORTRAN examples to demonstrate the idea?

  6. Joerg Kurt Wegner Fri, 02 Nov 2007 17:00:36 GMT

    A highlight are defnitely the things of Petitjean or you can also find some nice examples on dmoz

Comments