7102541: RFE: os::set_native_thread_name() cleanups

Implement os::set_native_thread_name() on windows, linux

Reviewed-by: sla, ctornqvi, simonis
This commit is contained in:
Thomas Stuefe 2014-10-13 22:11:39 +02:00 committed by Staffan Larsen
parent c5dbe0cf46
commit 51866388d1
5 changed files with 40 additions and 4 deletions

View file

@ -129,6 +129,7 @@ uintptr_t os::Linux::_initial_thread_stack_size = 0;
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 @@ void os::init(void) {
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 @@ int os::active_processor_count() {
}
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) {