8031968: Mac OS X: VM starts the agent by calling both Agent_OnAttach and Agent_OnAttach_L functions if its agent library is dynamically linked.
authorsla
Thu, 23 Jan 2014 09:06:21 +0100
changeset 22528 bd3821442010
parent 22527 a5de5537d8a6
child 22529 4db9ba24613d
8031968: Mac OS X: VM starts the agent by calling both Agent_OnAttach and Agent_OnAttach_L functions if its agent library is dynamically linked. Summary: Make sure we only look for statically linked agents in the main process image Reviewed-by: dsamersoff, bpittore, dcubed
hotspot/src/os/bsd/vm/os_bsd.cpp
hotspot/src/os/linux/vm/os_linux.cpp
hotspot/src/os/posix/vm/os_posix.cpp
hotspot/src/os/solaris/vm/os_solaris.cpp
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Thu Jan 23 08:12:12 2014 +0100
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Thu Jan 23 09:06:21 2014 +0100
@@ -1557,6 +1557,17 @@
 }
 #endif /* !__APPLE__ */
 
+void* os::get_default_process_handle() {
+#ifdef __APPLE__
+  // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
+  // to avoid finding unexpected symbols on second (or later)
+  // loads of a library.
+  return (void*)::dlopen(NULL, RTLD_FIRST);
+#else
+  return (void*)::dlopen(NULL, RTLD_LAZY);
+#endif
+}
+
 // XXX: Do we need a lock around this as per Linux?
 void* os::dll_lookup(void* handle, const char* name) {
   return dlsym(handle, name);
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Thu Jan 23 08:12:12 2014 +0100
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Thu Jan 23 09:06:21 2014 +0100
@@ -2104,6 +2104,9 @@
   return res;
 }
 
+void* os::get_default_process_handle() {
+  return (void*)::dlopen(NULL, RTLD_LAZY);
+}
 
 static bool _print_ascii_file(const char* filename, outputStream* st) {
   int fd = ::open(filename, O_RDONLY);
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Thu Jan 23 08:12:12 2014 +0100
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Thu Jan 23 09:06:21 2014 +0100
@@ -262,10 +262,6 @@
   return ::fdopen(fd, mode);
 }
 
-void* os::get_default_process_handle() {
-  return (void*)::dlopen(NULL, RTLD_LAZY);
-}
-
 // Builds a platform dependent Agent_OnLoad_<lib_name> function name
 // which is used to find statically linked in agents.
 // Parameters:
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp	Thu Jan 23 08:12:12 2014 +0100
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp	Thu Jan 23 09:06:21 2014 +0100
@@ -2146,6 +2146,10 @@
   return dlsym(handle, name);
 }
 
+void* os::get_default_process_handle() {
+  return (void*)::dlopen(NULL, RTLD_LAZY);
+}
+
 int os::stat(const char *path, struct stat *sbuf) {
   char pathbuf[MAX_PATH];
   if (strlen(path) > MAX_PATH - 1) {