JavaOne talk proposal: feedback?

Adam Megacz adam@megacz.com
Thu Nov 20 10:26:00 GMT 2003


Hey guys,

As you are all truly elite Java Gurus (tm), I was wondering if any of
you could give me some feedback on this proposal for a technical talk
at JavaOne.  I'd especially appreciate feedback on how to tune it for
what the selection committees are looking for.

The library I describe (mips2java) was actually an idea born here on
the java@gcc.gnu.org list, and it actually works (and believe me,
freetype-rendered fonts look way, way, way better than Sun's bundled
fonts!). 

  - a


==============================================================================
Using C/C++ libraries without leaving the JVM

Quite a number of C/C++ libraries have no pure Java equivalent.
Important examples include:

  - the high quality FreeType2 font rendering library
  - the libmspack library for manipulating Microsoft CAB files
  - JPEG image decompression [*]

The most common solution for integrating C/C++ code is to use JNI to
call out to a native-code library.  Unfortunately this is not a viable
option in environments such as:

  - J2ME (does not offer JNI)
  - Java Applets
  - Applications which require architecture-neutral deployment
  - J2EE Servlets (JNI is prohibited by the SecurityManager)

Furthermore, calling native code opens up an application to possible
buffer-overflow and heap corruption attacks, which is an undesirable
security risk.

Mips2Java lets you run C/C++ code *inside* a JVM without any of these
disadvantages.  In order to do this, use any compiler to compile your
application into a statically linked MIPS binary.  This binary is then
fed to org.xwt.mips.Compiler, which emits Java source code.  That
source code is passed to a java compiler (javac or jikes), which
produces a standard Java .class file exporting a main() method that
runs the C/C++ program.  Facilities for calling back and forth between
the translated code and other Java classes are also provided.

Unlike source-to-source translation solutions, which provide
incomplete support for ANSI C and ANSI C++, Mips2Java works with any
compiler (such as gcc or Visual C++), so you don't have to alter your
build process.  Furthermore, the output from Mips2Java never requires
hand-tweaking.  This tweaking is a major disadvantage of
source-to-source translators, since it must be performed manually
every time the C/C++ source code changes (and is re-translated).
Finally, Mips2Java supports every single non-priviledged MIPS
instruction, so it provides hassle-free support for even the most
pathological pointer math, struct-casting, and stack manipulation.

Mips2Java leverages the striking similarities between the Java
Bytecode set and the MIPS instruction set to perform very efficient
translation.  Under HotSpot 1.4, translated MIPS binaries run about 7
times faster than interpreted binaries, and about 13 times slower than
native code compiled with full optimizations.  This makes it an
excellent candidate for code which is not performance-critical, or
situations where maintainability and ease of integration is more
important than performance.

Mips2Java is open source software.  It is fully functional today, and
is already in heavy use by the XWT project to perform high-quality
font rendering via the FreeType2 library.  The XWT project also uses
Mips2Java to decode JPEG images (via libjpeg) and to extract CAB
archives (via libmspack)

Fore more information, please see

  http://www.xwt.org/mips2java/

[*] java.awt uses JNI to invoke a native code JPEG decompressor.
    Several pure-Java JPEG *compressors* are available, but no
    decompressors are available.



More information about the Java mailing list