1.1 --- a/src/os/solaris/vm/os_solaris.cpp Mon Oct 13 22:11:39 2014 +0200 1.2 +++ b/src/os/solaris/vm/os_solaris.cpp Fri May 17 18:13:25 2019 +0100 1.3 @@ -160,6 +160,7 @@ 1.4 1.5 address os::Solaris::_main_stack_base = NULL; // 4352906 workaround 1.6 1.7 +os::Solaris::pthread_setname_np_func_t os::Solaris::_pthread_setname_np = NULL; 1.8 1.9 // "default" initializers for missing libc APIs 1.10 extern "C" { 1.11 @@ -519,8 +520,15 @@ 1.12 } 1.13 1.14 void os::set_native_thread_name(const char *name) { 1.15 - // Not yet implemented. 1.16 - return; 1.17 + if (Solaris::_pthread_setname_np != NULL) { 1.18 + // Only the first 31 bytes of 'name' are processed by pthread_setname_np 1.19 + // but we explicitly copy into a size-limited buffer to avoid any 1.20 + // possible overflow. 1.21 + char buf[32]; 1.22 + snprintf(buf, sizeof(buf), "%s", name); 1.23 + buf[sizeof(buf) - 1] = '\0'; 1.24 + Solaris::_pthread_setname_np(pthread_self(), buf); 1.25 + } 1.26 } 1.27 1.28 bool os::distribute_processes(uint length, uint* distribution) { 1.29 @@ -4921,6 +4929,13 @@ 1.30 // the minimum of what the OS supports (thr_min_stack()), and 1.31 // enough to allow the thread to get to user bytecode execution. 1.32 Solaris::min_stack_allowed = MAX2(thr_min_stack(), Solaris::min_stack_allowed); 1.33 + 1.34 + // retrieve entry point for pthread_setname_np 1.35 + void * handle = dlopen("libc.so.1", RTLD_LAZY); 1.36 + if (handle != NULL) { 1.37 + Solaris::_pthread_setname_np = 1.38 + (Solaris::pthread_setname_np_func_t)dlsym(handle, "pthread_setname_np"); 1.39 + } 1.40 // If the pagesize of the VM is greater than 8K determine the appropriate 1.41 // number of initial guard pages. The user can change this with the 1.42 // command line arguments, if needed.