Re: 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X

2014-01-24 Thread Staffan Larsen
Looks good!  :-)

Thanks,
/Staffan

On 24 jan 2014, at 12:00, 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.
 
 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;
 }
 



Re: 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X

2014-01-24 Thread Chris Hegarty

The change looks good to me Alan.

-Chris.

On 24/01/14 11:00, 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;
  }



Re: 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X

2014-01-24 Thread Paul Sandoz

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;
 }
 



Re: 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X

2014-01-24 Thread Alan Bateman

On 24/01/2014 11:19, Paul Sandoz wrote:

:

So more precisely that is RTLD_LAZY | RTLD_FIRST ?


Either will do, I went for RTLD_FIRST to be consistent with the hotspot 
change.


-Alan


Re: 8032456: vm/jni/Miscellaneous/misc001/misc00101m1/misc00101m1.html failing on OS X

2014-01-24 Thread Mandy Chung

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;
 }