[kaffe] Re: [Sablevm-developer] Re: [Java-gnome-developer] Java-Gnome: jni or cni

Etienne Gagnon gagnon.etienne_m at uqam.ca
Sat Mar 13 09:12:01 PST 2004

Momchil Velikov wrote:
>   How about asking Sun to support CNI then ? Because it's they who
> limit your "freedoom of choice", by supporting only one (the
> technically inferior, AIUI) interface.

Who says that JNI is technically inferior than CNI technically?  As
a JVM specialist, I can say that it is not clearcut.  JNI is by far
the most flexible of the two *binary* interfaces, giving much more
freedom to the JVM implementer.  It is far from easy (if it is at
all possible) to get CNI to support things like precise moving garbage
collectors (such as copying/compacting collectors), or allowing for
non-traditional object layouts (bidirectional, split objects, etc.).

In fact, CNI imposes a deep dependency between a JVM and a CNI library.
For example, if a CNI implementation was adapted to support a
bidirectional object layout, then a compiled CNI library would only work
with JVMs that implement this bidirectional object layout.

JNI, on the other hand, allows a compiled JNI library to work with any
JVM, regardless of the internal JVM organization (object layout, GC, etc).

JNI is preperly a "binary interface" between a library and a JVM.  CNI,
on the pther hand, is a mix of a binary interface, and a C++ level
programming interface that requires specific compiler support.

Depending on your needs, you can argue that each of JNI and CNI is
technically superior.

As for the initial question of this thread:

 > The big question is: should we switch to CNI?

Unless the java-gnome project wants to restrict java-gnome to work
with gcj/gij, or wants to provide CNI implementations for other
JVMs [;-)] and is willing to provide several binary packages for
each platform (one per JVM that supports a different CNI
implementation), I recommend that they use the JNI binary interface
for their library, for maximum compatibility with Free (and non-free,
if they care) JVMs.


Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/

More information about the kaffe mailing list