For a patch implementing this proposal, see the end of this Description. This proposal has been submitted to SUN as well, for inclusion in a future JDK. Below is the full text of the proposal to SUN and the answer.
************************************************ Dear Java Developer, Thank you for your interest in improving the quality of Java Technology. Your report has been assigned an internal review ID of 680323, which is NOT visible on the Sun Developer Network (SDN). Please be aware that the large volume of reports we receive sometimes prevents us from responding individually to each message. We currently have a three week average response time. If the information is determined to be a new Bug or RFE, or a duplicate of a known Bug or RFE, you will receive a followup email containing a seven digit bug number. You may search for, view, or vote for this bug in the Bug Database at http://bugs.sun.com/. If you just reported an issue that could have a major impact on your project and require a timely response, please consider purchasing one of the support offerings described at http://java.sun.com/support/index.html. The Sun Developer Network (http://developers.sun.com) is a free service that Sun offers. To join, visit http://developers.sun.com/global/join_sdn.html. For a limited time, SDN members can obtain fully licensed Java IDEs for web and enterprise development. More information is at http://developers.sun.com/prodtech/javatools/free/. Thank you for using our bug submit page. Regards, Java Developer Bug Report Review Team --------------------------------------------------------------- dateCreated: Fri Apr 07 07:41:29 MDT 2006 type: rfe cust_name: Jan Nijtmans cust_email: [EMAIL PROTECTED] jdcid: nijtmans status: Waiting category: java subcategory: native_interface company: LogicaCMG release: 5.0 hardware: x86 OSversion: linux priority: 4 synopsis: support for GCC4.0's -fvisibility option in JNIEXPORT macro description: A DESCRIPTION OF THE REQUEST : Currently, the macro JNIEXPORT is defined in jni_md.h as empty: #define JNIEXPORT This means that on UNIX, marking a symbols as exportable has no effect. However, GCC 4.x has a new option -fvisibility=hidden which allows all symbols which are not marked specially to be hidden from a shared library. This feature is similar to Windows, where only symbols marked with __declspec(dllexport) are exported from dll's. Therefore I suggest to change this line to: #if defined(__GNUC__) && __GNUC__ > 3 #define JNIEXPORT __attribute__ ((visibility("default"))) #else #define JNIEXPORT #endif This allows code to be compiled with gcc 4.x to be compiled with -fvisibility=hidden, while still all JNI functions are exported. JUSTIFICATION : This enhancements makes it possible to reduce the size of JNI libraries significantly. This helps the start-up time a lot. For more information, see: http://gcc.gnu.org/wiki/Visibility This page explains much better what is going on that I could do it here. For gcc 3.x and earlier or any other compiler, this change has no effect. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - If a JNI library is compiled with GCC 4.x using the option -fvisibility=hidden, I expect that still all JNI functions are exported. ACTUAL - When using -fvisibility=hidden with GCC 4.x, all JNI functions would be hidden, so this option is not usable with JNI libraries. CUSTOMER SUBMITTED WORKAROUND : A workaround is placing the following in all JNI code: #include <jni.h> #if !defined(_WIN32) && defined(__GNUC__) && __GNUC__ > 3 #undef JNIEXPORT #define JNIEXPORT __attribute__ ((visibility("default"))) #endif workaround: comments: (company - LogicaCMG , email - [EMAIL PROTECTED]) Index: libjava/include/jni_md.h =================================================================== --- libjava/include/jni_md.h (revision 122411) +++ libjava/include/jni_md.h (working copy) @@ -124,6 +124,19 @@ #define JNICALL __stdcall +#else /* !( _WIN32 || __WIN32__ || WIN32) */ + +#define JNIIMPORT +#if defined(__GNUC__) && __GNUC__ > 3 +#define JNIEXPORT __attribute__ ((visibility("default"))) +#else +#define JNIEXPORT +#endif + +#define JNICALL + +#endif /* !( _WIN32 || __WIN32__ || WIN32) */ + /* These defines apply to symbols in libgcj */ #ifdef __GCJ_DLL__ # ifdef __GCJ_JNI_IMPL__ @@ -135,14 +148,4 @@ # define _CLASSPATH_JNIIMPEXP #endif /* __GCJ_DLL__ */ -#else /* !( _WIN32 || __WIN32__ || WIN32) */ - -#define JNIIMPORT -#define JNIEXPORT -#define JNICALL -#define _CLASSPATH_JNIIMPEXP - -#endif /* !( _WIN32 || __WIN32__ || WIN32) */ - - #endif /* __GCJ_JNI_MD_H__ */ -- Summary: support for GCC4.0's fvisibility option in JNIEXPORT macro Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jan dot nijtmans at gmail dot com GCC target triplet: any target, except win32 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30999