This patch looks fine.
For JDK 9, it might be worth considering using the common code via JVM
functions to replace getProcessHandle, JDK_FindJvmEntry,
JDK_InitJvmEntry for native symbol lookup (jni_util.h and jdk_util.h)
Mandy
On 1/24/2014 3:00 AM, Alan Bateman 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.
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;
}