Thursday, December 14, 2006

Brilliant: C to MIPS to Java bytecode

NestedVM is one of the cleverest solutions to the problem of legacy C and C++ code I have ever seen: use GCC to compile to MIPS machine instructions, then translate those directly into Java bytecode.

There is also a good slideshow.

A straight-forward example is a pure-Java translation of the SQLite JDBC driver.

3 comments:

Brian Oxley said...

The GCJ approach has been around for years, but misses some important pieces:

* The syscalls: NestedVM provides the missing system calls which underly the C library.

* Memory allocation: NestedVM has an approach to the problem of sbrk(), malloc() and friends.

* No specific to GCC: Any MIPS binary is translatable, not just those compiled by GCC.

* There is little performance cost: The translation between MIPS and JVM bytecode is very direct, MIPS is a simple architecture.

Curt said...

The biggest limitation for NestedVM is tool support. It has been this way for several years. All of the major Java IDEs have plugins to support C. Tool support is so bad, that it is just easier to compile the binaries whatever the native platform is and use JNI.

In order to be widely adopted, NestedVM doesn't need to get faster. It simple needs to move from a technology that can be made to work, to one that is easy to work with. The increased user base will uncover any optimizations still available.

There are several independent MIPS emulators available for the JVM. The JavaOne presentation linked to below (free, but requires registration) is definitely worth watching if this stuff interests you.

"High Performance: Writing a Sony PlayStation Emulator in Java Technology : TS-5547, 2006"
http://developers.sun.com/learning/javaoneonline/sessions/2006/TS-5547/index.html

"Cibyl"
http://spel.bth.se/index.php/Cibyl

CARFIELD said...

I feel main problem of those project is it in fact not working for real library... or my library.

Too good to know that a database driver port to java using this project, see if I have time to give it a try later