Cygwin progress, Storing references to objects in CNI code

Julian Hall
Tue Jul 17 06:37:00 GMT 2001

Hi folks, just thought I'd give you an update on how things are going
with getting gcj running on cygwin.

I've been doing some testing on the version I built with SjLj
exceptions, and it mostly now seems to be working OK; after a little
experimentation I've decided that the cygwin thread code is not stable
enough to support libgcj as yet, but that the windows threading code in
libgcj can be made to work suitably on the cygwin platform.

I've also had a few problems with a library developed in-house here that
uses JNI; I've made a few updates to get dynamic loading & JNI calls to
work correctly and managed to get some basic JNI code to work correctly,
but when I tried more complex scenarios I experienced a number of
NullPointerExceptions from various parts of the code, most specifically
when calling NewGlobalRef().  Also, when building a DLL with GCC windows
persistently failed to load the DLL, however a DLL built by MSVC++ from
the same code functioned adequately.  I also couldn't persuade 'ld' to
export any symbols from an EXE even though Windows does support this,
hence I couldn't statically link against the JNI code.

Another random comment: 'gcjh -jni' does not output the values of 'final
static <primitive type>'s as const declarations, whereas Sun's javah

I decided that the best thing to do would be to rewrite everything using
CNI (the library was fairly small anyway, and I figured that the
performance improvement of not having to use indirection would be
worthwhile).  The one thing I haven't quite figured out about CNI is how
to perform the equivalent operation of JNI's NewGlobalRef() - I
initially assumed that the garbage collector would find pointers stored
in blocks allocated with JvMalloc() but this seems to not be the case
(that caused a bug that was rather amusing to track down, I can tell
you...!).  I'm currently storing the references in a Vector (which as
I'm only expecting in the order of 10-100 references at a time seems
relatively efficient), but wonder if there's a better way?

Anyway... I'm getting close to the point where I can send some patches
in, although I haven't been able to get the paperwork sorted out yet,
and haven't quite got the entire thing automatically configuring
properly for a fresh build (I'm still tweaking some things by hand after
running configure...)


More information about the Java mailing list