--- a/hotspot/src/os/linux/vm/os_linux.cpp Fri Oct 10 21:47:04 2014 +0000
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Mon Oct 13 22:11:39 2014 +0200
@@ -129,6 +129,7 @@
int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL;
int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
+int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
Mutex* os::Linux::_createThread_lock = NULL;
pthread_t os::Linux::_main_thread;
int os::Linux::_page_size = -1;
@@ -4695,6 +4696,11 @@
StackRedPages = 1;
StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
}
+
+ // retrieve entry point for pthread_setname_np
+ Linux::_pthread_setname_np =
+ (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np");
+
}
// To install functions for atexit system call
@@ -4894,8 +4900,14 @@
}
void os::set_native_thread_name(const char *name) {
- // Not yet implemented.
- return;
+ if (Linux::_pthread_setname_np) {
+ char buf [16]; // according to glibc manpage, 16 chars incl. '/0'
+ snprintf(buf, sizeof(buf), "%s", name);
+ buf[sizeof(buf) - 1] = '\0';
+ const int rc = Linux::_pthread_setname_np(pthread_self(), buf);
+ // ERANGE should not happen; all other errors should just be ignored.
+ assert(rc != ERANGE, "pthread_setname_np failed");
+ }
}
bool os::distribute_processes(uint length, uint* distribution) {