Bug in JNI RegisterNatives?

Juerg Lehni juerg@scratchdisk.com
Tue May 30 00:08:00 GMT 2006


I went ahead and wrote a first version of the patch.

It fixes the problem I encountered, and also a memory leak that  
happens when the table is rehashed (the old table was not freed before).

I introduced a new struct called NativeMethod to be used in the hash  
table.

But the questions bellow are still valid, as I'm quite sure it could  
be done in a better way.

The patch is against gcc-4.1.1, but I doubt that many things have  
change in jni.cc since.

Coding and naming conventions need to be checked. NativeMethod  
probably will need another name.

Jürg

-------------- next part --------------
A non-text attachment was scrubbed...
Name: jni-gcc411.diff
Type: application/octet-stream
Size: 6316 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20060530/d27e91ca/attachment.obj>
-------------- next part --------------

Am 30.05.2006 um 00:28 schrieb Juerg Lehni:

> I'm happy to write the patch but would need to know a few more  
> things first.
>
> Some questions:
>
> - Is _Jv_LookupJNIMethod used each time a methods registered in  
> that way is called, or is it only called once, and then linked  
> directly to the native pointer?
>
> - Should I create a new struct as a base for nathash, or continue  
> to use JNINativeMethod and just concatenate the class name and the  
> method name, seperated with a '.' and store that in the  
> JNINativeMethod name field? I guess a new struct would be cleaner,  
> as JNINativeMethod is also used outside jni.cc.
>
> - What is the easiest way to retrieve the class name in UTF8  
> format? Is there something faster / easier than klass->getName()  
> and then convert?
>
> Jürg
>
> Am 29.05.2006 um 23:14 schrieb Tom Tromey:
>
>>>>>>> "Juerg" == Juerg Lehni <juerg@scratchdisk.com> writes:
>>
>> Juerg> I believe I discovered a rather serious bug in GCJ's  
>> implementation
>> Juerg> of JNI RegisterNatives.
>>
>> Yes, I think you're right.
>>
>> Juerg> This should not be too hard to fix. One could for example  
>> use the
>> Juerg> class name plus the mehtod name instead of only the method  
>> name when
>> Juerg> storing native methods in nathash.
>>
>> Yeah, I think we should do this.
>>
>> If you're not planning to submit a patch, could you file this in
>> bugzilla?
>>
>> Tom
>



More information about the Java mailing list