Thomas Stüfe
2014-10-10 08:38:27 UTC
Hi all,
I'd like to contribute implementations for os::set_native_thread_name() on
Windows and Linux. We have added this feature to the SAP JVM and it has
been useful for debugging.
http://cr.openjdk.java.net/~simonis/webrevs/7102541/
Associated request:
https://bugs.openjdk.java.net/browse/JDK-7102541
On Windows, it uses the method described here:
http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
On Linux, it uses pthread_setname_np(2).
Notes for the windows implementation:
- os::set_native_thread_name() only has any effect if there is a debugger
attached to the process at the time of the function call. The reason is
that the debugger must observe the raised exception. This means that this
method works fine if the VM is being debugged right from the start; for
cases where the debugger attaches during VM life, threads started before
the attach will show default names.
- This was tested using Visual Studio 2013 and Windbg.
Notes for the Linux implementation:
- pthread_setname_np(2) needs glibc 2.12 or newer. The change loads the
function dynamically.
- Thread names are truncated to 15 characters.
- We can see the thread names with ps (eg " ps H -p 1234 -o 'pid tid comm'
") or with gdb >= 4.7
Note that not all threads show names. os::set_native_thread_name() was only
called for JavaThread* children before this change, this change adds the VM
thread, but there are some threads for which this function is not yet
called; they appear with their default names.
---
Note that when I was doing this change, I worked first on
https://bugs.openjdk.java.net/browse/JDK-8060033, so I was not aware that
Gerard Ziemski had done a lot of the same work before. But it looks like
his changes did not appear in the hotspot? Either that or I looked at the
wrong place... Anyway, I hope either his or my changes make it into the
hotspot, because the feature is quite useful.
Kind Regards,
Thomas
I'd like to contribute implementations for os::set_native_thread_name() on
Windows and Linux. We have added this feature to the SAP JVM and it has
been useful for debugging.
http://cr.openjdk.java.net/~simonis/webrevs/7102541/
Associated request:
https://bugs.openjdk.java.net/browse/JDK-7102541
On Windows, it uses the method described here:
http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
On Linux, it uses pthread_setname_np(2).
Notes for the windows implementation:
- os::set_native_thread_name() only has any effect if there is a debugger
attached to the process at the time of the function call. The reason is
that the debugger must observe the raised exception. This means that this
method works fine if the VM is being debugged right from the start; for
cases where the debugger attaches during VM life, threads started before
the attach will show default names.
- This was tested using Visual Studio 2013 and Windbg.
Notes for the Linux implementation:
- pthread_setname_np(2) needs glibc 2.12 or newer. The change loads the
function dynamically.
- Thread names are truncated to 15 characters.
- We can see the thread names with ps (eg " ps H -p 1234 -o 'pid tid comm'
") or with gdb >= 4.7
Note that not all threads show names. os::set_native_thread_name() was only
called for JavaThread* children before this change, this change adds the VM
thread, but there are some threads for which this function is not yet
called; they appear with their default names.
---
Note that when I was doing this change, I worked first on
https://bugs.openjdk.java.net/browse/JDK-8060033, so I was not aware that
Gerard Ziemski had done a lot of the same work before. But it looks like
his changes did not appear in the hotspot? Either that or I looked at the
wrong place... Anyway, I hope either his or my changes make it into the
hotspot, because the feature is quite useful.
Kind Regards,
Thomas