Something is wrong with JNI's jlong in JDK7
Scott Palmer
swpalmer at gmail.com
Fri Nov 16 06:21:46 PST 2012
On 2012-11-13, at 5:00 PM, Scott Palmer <swpalmer at gmail.com> wrote:
> On 2012-11-13, at 4:36 PM, Mike Swingler <swingler at apple.com> wrote:
>
>> On Nov 13, 2012, at 8:21 AM, Scott Palmer <swpalmer at gmail.com> wrote:
>>
>>> I just noticed that the criteria for defining jlong has changed from that given in Apple's JDK 6 vs. Oracle's JDK 7. This caused some code of mine to break because it seems to be wrong under some circumstances.
>>>
>>> JDK 7u10 has this. Note that sometimes a jlong is a C "long" and sometimes it is a C "long long":
>>>
>>> #ifndef _JAVASOFT_JNI_MD_H_
>>> #define _JAVASOFT_JNI_MD_H_
>>>
>>> #define JNIEXPORT
>>> #define JNIIMPORT
>>> #define JNICALL
>>>
>>> typedef int jint;
>>> #ifdef _LP64 /* 64-bit Solaris */
>>> typedef long jlong;
>>> #else
>>> typedef long long jlong;
>>> #endif
>>>
>>> typedef signed char jbyte;
>>>
>>> #endif /* !_JAVASOFT_JNI_MD_H_ */
>>>
>>>
>>>
>>> Whereas Apple's JDK 6 always uses "long long":
>>>
>>>
>>>
>>> #ifndef _JAVASOFT_JNI_MD_H_
>>> #define _JAVASOFT_JNI_MD_H_
>>>
>>> #define JNIEXPORT __attribute__((visibility("default")))
>>> #define JNIIMPORT
>>> #define JNICALL
>>>
>>> #if defined(__LP64__) && __LP64__ /* for -Wundef */
>>> typedef int jint;
>>> #else
>>> typedef long jint;
>>> #endif
>>> typedef long long jlong;
>>> typedef signed char jbyte;
>>>
>>> #endif /* !_JAVASOFT_JNI_MD_H_ */
>>
>> Have you filed a bug at <http://bugs.sun.com>?
>
> Just… I filed it against "javah" since there was no more appropriate category available.
>
Just in case anyone is wondering why this matters. The C++ linkage breaks because func(long) - a method taking the Java 7 version of jlong, and func(long long) a method taking the Java 6 version of jlong, are considered different, even though both types are 8 bytes. C++ name mangling comes out different.
We have a Java project that uses a lot of native code and depends a lot on a plugin mechanism where the plugins need to link with a native library we provide as well. When our library is compiled with Java 6 headers, plugins compiled against Java 7 headers can't link with it.
I neglected to point that out in my bug report (Review ID: 2381559), and I have not yet got any confirmation that it was accepted.
Scott
More information about the macosx-port-dev
mailing list