Fri, 17 May 2019 18:13:25 +0100
8151322: Implement os::set_native_thread_name() on Solaris
Reviewed-by: sla, kbarrett, gziemski
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.
2.1 --- a/src/os/solaris/vm/os_solaris.hpp Mon Oct 13 22:11:39 2014 +0200 2.2 +++ b/src/os/solaris/vm/os_solaris.hpp Fri May 17 18:13:25 2019 +0100 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -132,6 +132,9 @@ 2.11 static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; } 2.12 static void set_SIGasync(int newsig) { _SIGasync = newsig; } 2.13 2.14 + typedef int (*pthread_setname_np_func_t)(pthread_t, const char*); 2.15 + static pthread_setname_np_func_t _pthread_setname_np; 2.16 + 2.17 public: 2.18 // Large Page Support--ISM. 2.19 static bool largepage_range(char* addr, size_t size);
3.1 --- a/src/share/vm/utilities/globalDefinitions.hpp Mon Oct 13 22:11:39 2014 +0200 3.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp Fri May 17 18:13:25 2019 +0100 3.3 @@ -332,7 +332,7 @@ 3.4 // so far from the middle of the road that it is likely to be problematic in 3.5 // many C++ compilers. 3.6 // 3.7 -#define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value))) 3.8 +#define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value)) 3.9 #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr))) 3.10 3.11 // Unsigned byte types for os and stream.hpp