JvInitClass calls exit?

Andi Vajda andi@osafoundation.org
Fri Dec 9 17:37:00 GMT 2005


On Fri, 9 Dec 2005, tsuraan wrote:

> I'm trying to write a simple app in c++ using the java lucene
> libraries.  Basically, what the app wants to do it open a lucene
> index, and then close it.  The problem I have is that when calling a
> static method of a java class from c++, the program fails.  It doesn't
> throw an exception, and the function being called never reaches its
> first line.  My first thought was that maybe the gcj-compiled lucene
> was not properly initializing static classes, so I decided to "fix"
> this by explicitly calling JvInitClass on the object's class$
> variable.  This causes my program to abort there, instead of when I
> call the static method of the class I'm trying to use.  So, since gcj
> supposedly inserts JvInitClass transparently at the beginning of each
> static method, it's looking like JvInitClass is seeing something bad,
> and exiting.  The program's return code is 1, if that helps anything.

You should take a look at the PyLucene project, 
http://pylucene.osafoundation.org, which has been doing something very similar 
for about two years now. I just released a version of PyLucene built from Java 
Lucene 1.9rc1. PyLucene is a python extension built around a gcj compile of 
Java Lucene. I've had to add a number of calls to JvInitClass() for classes 
that have static methods invoked on them without being first instantiated. 
FSDirectory is one of them. See lines 4794 and on in 
http://svn.osafoundation.org/pylucene/trunk/PyLucene.i for the complete list.

> I'm using gcc-4.1-20051029 to compile these, and lucene 1.4.3.  I have
> a small set of patches to make gcjh and gcj less angry.

As for patches, compiling from .jar files keeps gcj a lot happier, but I've 
still got a few, http://svn.osafoundation.org/pylucene/trunk/patches.lucene, 
the most disturbing being the one in QueryParser.py where the uninitialized 
required and prohibited boolean variables have to be initialized to prevent 
their values from being swapped at some point in the addClause() method.

I used gcj 3.4.4 in this release, I've been having problems building gcj 4.1 
snapshots on OS X for a while but now that Apple released a new version of 
their customized toolchain, I need to try it again. For instance, I now can 
step through java code in gdb, and even inspect non object variables. Given 
that when there is an error, I don't get a stacktrace, being able to step 
through Java code is welcome progress.

Andi..



More information about the Java mailing list