Incorrect Java methods called from CNI
Dave Menendez
dave@sycamore.us
Mon May 10 20:25:00 GMT 2004
On Fri, 2004年05月07日 at 16:56, Michael Koch wrote:
> Am Freitag, 7. Mai 2004 22:48 schrieb Dave Menendez:
> > I'm hoping that someone else has seen this problem and knows of a
> > possible workaround or fix. I am using GCC 3.4.0 and GCJ to compile
> > several Java -source- files. I use gcjh to generate header files for
> > all these Java files. I have some C++ code that successfully
> > instantiates the Java object and calls some methods on it. So far,
> > things are working great.
> >
> > However, I've just run into a problem that didn't seem to make any
> > sense, and by adding a few basic System.out.println statements
> > directly in the Java source and regenerating all the files, I've
> > determined that the method I invoke from C++ is actually calling the
> > wrong method on the Java object. For example, in C++ I invoked
> > SomeJavaObj->clear(), but according to the println's I placed in the
> > Java object itself, SomeJavaObj.add() was the actual method that got
> > invoked.
> >
> > Other methods work, but this is the first one I've come across where
> > the wrong method altogether was invoked. The method I'm calling
> > isn't anything out of the ordinary, like an implementation of an
> > interface method, and the pointer I'm using is a pointer of the
> > actual class type, not of an interface type, so I don't think I'm
> > doing anything wacky here. I even tried compiling without any
> > optimization (-O0) instead of the default used by autoconf/automake
> > (-O2).
>>> Can you provide a testcase for this ?
>>> Michael
I posted a message saying that it appeared I was mistaken and that the
correct method was indeed being called. Upon even closer observation,
however, I'm sure that my original observation was correct and that the
incorrect method is being called. Sorry for the flip flop.
The Java library I'm trying to use in C++ consists of a number of
classes, interfaces, static variables initialized from static variables
in other classes, and some static blocks that do some additional
operations on static final variables upon startup. Overall, the library
really just does a bunch of string manipulations, so it's really nothing
mind-blowing; just lots of pieces.
Anyway, I've been trying to create a test case from scratch, mimicking
the class in which I've observed the behavior, but unfortunately I can't
seem to duplicate the problem this way. I think unleashing the whole
Java library and singling out the one class would be too much to swallow
for you GCJ developers, plus I'd need to jump through some difficult
hoops to do that anyway.
I'm not sure what I can provide to help someone track this down short of
the actual library source, but it could be quite awhile before I'd be
able to come up with a small set of code that duplicates the problem,
since I have no idea what might be causing it. If you have any ideas in
the meantime, I'd be happy to provide what I can.
More information about the Java
mailing list