Difference between Mac and Windows JNI

Jenks, Robert rjenks at ti.com
Wed Jan 16 15:11:37 PST 2013


I would like to ask (and I'm not sure if I should enter a bug/RFE in
Oracle's java bug DB or not) that the definition of JNIEXPORT be changed
for mac.

I am in the process of moving a large cross-platform java/native
application from Apple Java 1.6 to Oracle Java 1.7 on mac and ran into an
issue.

JNIEXPORT is defined in jni_md.h on each platform:

Oracle Java for Windows:  #define JNIEXPORT __declspec(dllexport)
Apple Java for Mac:       #define JNIEXPORT
__attribute__((visibility("default")))
Oracle Java for Mac:      #define JNIEXPORT

The Oracle Java for Mac case is problematic if not broken.

In case it is not well understood, let me give some background.  On
Windows when you build a DLL functions have to be explicitly marked as
'__declspec(dllexport)'  to make them callable from outside the DLL.
Oracle java on windows' JNIEXPORT does this for you automatically.  On
Mac, GCC by default exports every function as callable from outside the
dylib.  However, to mimic the same behavior many developers build with
'­fvisibility=hidden' to set the default to hidden (or do not export from
the dylib).  With Apple java JNIEXPORT properly defines that JNI functions
must be callable from outside the dylib.  Oracle's doesn't.  Therefore if
you compile with default settings everything works as expected.  If you
compile with -fvisibility=hidden your JNI functions won't be exported from
the dylib.  

This worked with Apple's Java, but doesn't with Oracle's.  That, in
itself, isn't the issue, but I think that this should be consistent
between Oracle's Windows and Mac versions.  JNI functions should be
explicitly marked as exported from shared libraries by using the JNIEXPORT
macro.

I can work around this, but I would hope that this would be changed.  To
me this is a bug, but I could see the argument the other way too.  What is
the best way to proceed to officially request this change?

-Robert



More information about the macosx-port-dev mailing list