RFR: 8238649: Call new Win32 API SetThreadDescription in os::set_native_thread_name

Thomas Stuefe stuefe at openjdk.java.net
Fri Jun 11 06:21:52 UTC 2021


On Wed, 2 Jun 2021 02:19:52 GMT, David Holmes <dholmes at openjdk.org> wrote:

> From Windows 10 and Windows 2016 server, we have a direct API for setting the thread name/description. Use of this API was suggested by Markus Gaisbauer:
> 
> http://mail.openjdk.java.net/pipermail/serviceability-dev/2020-February/030366.html
> 
> Using the new API was quite straight forward, but verifying that it had worked correctly was far more challenging. It seems there are no tools that use the new GetThreadDescription API to display thread names, so no easy check that this had worked. While Visual Studio will use it, it also uses the old debugger mechanism, so we wouldn't be able to tell the difference.
> 
> Writing a Windows-only test was one possibility, but the conversion to/from Unicode and java.lang.String would make that test very cumbersome in itself (for something that should be trivial!).
> 
> So instead for debug builds I read back the thread name using GetThreadDescription and check that the name we set and the name we read are the same. I'm a bit concerned about the impact this may have on performance so I'm going to run some benchmarks.
> 
> I will also run benchmarks to watch for issues with the unicode conversion costs related to this.
> 
> The logging strategy is as follows:
> - info: show whether the new API is available or not
> - debug: report failures that are ignored (as we fallback to debugger mechanism)
> - trace: report successes for full tracking
> 
> Testing:
>   - internal self-verification in debug builds as previously described
>  - verified the logging output on different Windows systems that have, and don't have, the new API
>  - sanity testing for tiers 1-3
> 
> Thanks,
> David

Another issue with the check just occurred to me which is that there may be (its not documented) a limit to the thread name length. There is one on Linux. Which means a check would need to do a substring comparison.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4297


More information about the hotspot-runtime-dev mailing list