<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Compiling Open Babel to Pure Java Bytecode with NestedVM: Building A Runnable Classfile that Almost Works</title>
    <link>http://depth-first.com/articles/2007/11/26/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-building-a-runnable-classfile-that-almost-works</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Compiling Open Babel to Pure Java Bytecode with NestedVM: Building A Runnable Classfile that Almost Works</title>
      <description>&lt;p&gt;&lt;a href="http://openbabel.sf.net"&gt;&lt;img src="http://depth-first.com/files/Babel256.png" align="right"&gt;&lt;/img&gt;&lt;/a&gt;Previously, I described an &lt;a href="http://depth-first.com/articles/2007/11/19/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-an-unsuccessful-first-attempt#comment-268"&gt;unsuccessful first attempt&lt;/a&gt; to compile the popular cheminformatics C/C++ library &lt;a href="http://openbabel.sf.net"&gt;Open Babel&lt;/a&gt; to pure Java bytecode using &lt;a href="http://nestedvm.ibex.org/"&gt;NestedVM&lt;/a&gt;. This article follows that topic one step further, and shows how to obtain a runnable Java classfile. Although major functionality is missing, the principle of compiling arbitrary C/C++ code to both Java source code and Java bytecode is illustrated.&lt;/p&gt;

&lt;h4&gt;Getting Started&lt;/h4&gt;

&lt;p&gt;This articles assumes that you've &lt;a href="http://depth-first.com/articles/2007/11/19/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-an-unsuccessful-first-attempt#comment-268"&gt;installed NestedVM and downloaded Open Babel&lt;/a&gt; on your system. You'll then need to set up your environment (from the nestedvm installation directory):&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ source env.sh
&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Run the Configure Script&lt;/h4&gt;

&lt;p&gt;The configure script we used last time didn't attempt to statically compile the binary utilities in the &lt;strong&gt;tools&lt;/strong&gt; directory. This time, we'll add flags to allow this:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ ./configure --disable-dynamic-modules --enable-static=yes --enable-shared=no --enable-inchi --host=mips-unknown-elf
$ make
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Note: leaving out the static compile directives does not produce a fully-functioning classfile either.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Next, we'll attempt to directly create the &lt;tt&gt;babel&lt;/tt&gt; binary in Java classfile format, as we did last time:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ cd tools
$ java org.ibex.nestedvm.Compiler -outfile Babel.class Babel babel
Exception in thread "main" java.lang.IllegalStateException: unresolved phantom target
        at org.ibex.classgen.MethodGen.resolveTarget(MethodGen.java:555)
        at org.ibex.classgen.MethodGen._generateCode(MethodGen.java:664)
        at org.ibex.classgen.MethodGen.generateCode(MethodGen.java:618)
        at org.ibex.classgen.MethodGen.dump(MethodGen.java:888)
        at org.ibex.classgen.ClassFile._dump(ClassFile.java:193)
        at org.ibex.classgen.ClassFile.dump(ClassFile.java:160)
        at org.ibex.nestedvm.ClassFileCompiler.__go(ClassFileCompiler.java:380)
        at org.ibex.nestedvm.ClassFileCompiler._go(ClassFileCompiler.java:72)
        at org.ibex.nestedvm.Compiler.go(Compiler.java:259)
        at org.ibex.nestedvm.Compiler.main(Compiler.java:183)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;We're getting the same error as before. Although, an &lt;a href="http://groups.google.com/group/nestedvm/browse_thread/thread/b5d114a20a6b672b"&gt;announcement of a bugfix&lt;/a&gt; was posted to the NestedVM list, in my hands the new version of NestedVM caused the same error.&lt;/p&gt;

&lt;p&gt;As a workaround, we can compile to Java sourcecode first:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ java org.ibex.nestedvm.Compiler -outformat java -outfile Babel.java Babel babel
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;We now have a Java source file encoding the &lt;strong&gt;babel&lt;/strong&gt; program. Does it compile?&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ javac Babel.java
The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
        at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139)
        at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)
        at com.sun.tools.javac.parser.Scanner.getLineMap(Scanner.java:1105)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)
        at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:801)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
        at com.sun.tools.javac.main.Main.compile(Main.java:353)
        at com.sun.tools.javac.main.Main.compile(Main.java:279)
        at com.sun.tools.javac.main.Main.compile(Main.java:270)
        at com.sun.tools.javac.Main.compile(Main.java:69)
        at com.sun.tools.javac.Main.main(Main.java:54)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Not exactly. But this is a massive source file, so we'll need to increase the Java compiler's memory allowance:&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ javac Babel.java -J-Xms256m -J-Xmx256m
Note: Babel.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This seems to have worked. Can we run the classfile?&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ java Babel -H
Open Babel converts chemical structures from one file format to another

Usage: Babel &amp;lt;input spe&amp;gt; &amp;lt;output spec&amp;gt; [Options]

Each spec can be a file whose extension decides the format.
Optionally the format can be specified by preceding the file by
-i&amp;lt;format-type&amp;gt; e.g. -icml, for input and -o&lt;format-type&gt; for output

--truncated--
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Success! But before we get too excited, let's make sure Open Babel's file formats are recognized by testing for "SMILES":&lt;/p&gt;

&lt;div class="console"&gt;
&lt;pre&gt;
$ java Babel -Hsmi
Format type: smi was not recognized
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;As you can see, we have successfully converted the &lt;tt&gt;babel&lt;/tt&gt; program to an executable classfile, but this classfile is missing most of the features of the native binary.&lt;/p&gt;

&lt;p&gt;This may seem hopeless, but consider that natively compiling Open Babel using the above &lt;tt&gt;configure&lt;/tt&gt; flags also produces a binary that doesn't know about SMILES or any other format.&lt;/p&gt;

&lt;p&gt;So, it's very likely that if we can produce a native, statically compiled, self contained &lt;tt&gt;babel&lt;/tt&gt; executable, then we will have solved the problem of running Open Babel entirely on a JVM.&lt;/p&gt;

&lt;p&gt;This doesn't seem like a difficult problem, &lt;a href="http://sourceforge.net/mailarchive/forum.php?thread_name=819391.60947.qm%40web34201.mail.mud.yahoo.com&amp;amp;forum_name=openbabel-discuss"&gt;but apparently it is&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Mon, 26 Nov 2007 10:10:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:24f162e9-dafd-4f32-8458-0dc45acb5345</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2007/11/26/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-building-a-runnable-classfile-that-almost-works</link>
      <category>Tools</category>
      <category>openbabel</category>
      <category>nestedvm</category>
      <category>java</category>
      <category>crosscompile</category>
      <category>bytecode</category>
    </item>
    <item>
      <title>"Compiling Open Babel to Pure Java Bytecode with NestedVM: Building A Runnable Classfile that Almost Works" by Rich Apodaca</title>
      <description>&lt;p&gt;Egon, after the language module loading issue is resolved it will be very interesting to run some benchmarks with both the native executable and the NestedVM version of babel. There would have to be some allowance for JVM startup and warming up the hot-spot compiler.&lt;/p&gt;

&lt;p&gt;I've seen zero benchmark studies - only nonspecific estimates of performance differences w/ NestedVM.&lt;/p&gt;

&lt;p&gt;We could try benchmarking with cInChI and &lt;a href="http://depth-first.com/articles/2007/10/31/jinchi-run-inchi-anywhere-java-runs" rel="nofollow"&gt;JInChI&lt;/a&gt; today, though...&lt;/p&gt;</description>
      <pubDate>Tue, 27 Nov 2007 09:29:51 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:6e7ac372-b21a-4d91-a41d-5f6b16a192b0</guid>
      <link>http://depth-first.com/articles/2007/11/26/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-building-a-runnable-classfile-that-almost-works#comment-272</link>
    </item>
    <item>
      <title>"Compiling Open Babel to Pure Java Bytecode with NestedVM: Building A Runnable Classfile that Almost Works" by Egon Willighagen</title>
      <description>&lt;p&gt;This is all very exciting, and makes deployment of such libraries in, for example, Bioclipse a lot easier. I can see a solution where the support value of a opensource-based company is in providing a JNI-based, and faster, version of the same code, while the slower, free/free version is NestedVM-based.&lt;/p&gt;</description>
      <pubDate>Tue, 27 Nov 2007 01:22:55 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:598281d0-dbb9-4813-8f39-d13958b8df6a</guid>
      <link>http://depth-first.com/articles/2007/11/26/compiling-open-babel-to-pure-java-bytecode-with-nestedvm-building-a-runnable-classfile-that-almost-works#comment-271</link>
    </item>
  </channel>
</rss>
