On Jan 24, 2014, at 12:00 PM, Alan Bateman <alan.bate...@oracle.com> wrote:
> > I need a reviewer to fix an issue with the changes in JDK 8 to support > statically linked JNI libraries. The issue arises with tests that have both > JNI_OnLoad and JNI_OnLoad_libname functions defined, and code attempts to > load the library more than once. In that scenario then both functions are > called. > > Staffan Larsen did the hard work in JDK-8031968 where he observed that > dlopen(NULL, RTLD_LAZY) behaves differently on OS X and that we should be > using dlopen(NULL, RTLD_FIRST) to get the handle of the main program. Staffan > has fixed this in the hotspot repository for JVM TI agent libraries, we need > to do the same in the libjava code used by ClassLoader's native methods. > IIUC from reading the docs: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dlopen.3.html ... discovered during the call to dlopen(). If neither RTLD_LAZY nor RTLD_NOW is specified, the default is RTLD_LAZY. ... RTLD_FIRST The retuned handle is tagged so that any dlsym() calls on the handle will only search the image specified, and not subsequent images. If path is NULL and the option RTLD_FIRST is used, the handle returned will only search the main executable. So more precisely that is "RTLD_LAZY | RTLD_FIRST" ? Paul. > Note that the include of string.h is not directly part of the issue here, > instead it's just a drive-by fix to the warning related to the strcat usages. > > -Alan > > > diff --git a/src/solaris/native/common/jni_util_md.c > b/src/solaris/native/common/jni_util_md.c > --- a/src/solaris/native/common/jni_util_md.c > +++ b/src/solaris/native/common/jni_util_md.c > @@ -23,6 +23,8 @@ > * questions. > */ > > +#include <string.h> > + > #include "jni.h" > #include "jni_util.h" > #include "dlfcn.h" > @@ -40,7 +42,11 @@ > if (procHandle != NULL) { > return procHandle; > } > - procHandle = (void*)dlopen(NULL, RTLD_LAZY); > +#ifdef __APPLE__ > + procHandle = (void*)dlopen(NULL, RTLD_FIRST); > +#else > + procHandle = (void*)dlopen(NULL, RTLD_LAZY); > +#endif > return procHandle; > } >