RFR: 8368124: Show useful thread names in ASAN reports [v4]

David Holmes dholmes at openjdk.org
Wed Sep 24 06:53:18 UTC 2025


On Wed, 24 Sep 2025 05:45:42 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> src/hotspot/os/linux/os_linux.cpp line 4863:
>> 
>>> 4861:   // for thread names is to be both longer than 15 chars and have a trailing number
>>> 4862:   // ("DispatcherWorkerThread21", "C2 CompilerThread#54" etc), we truncate "smartly"
>>> 4863:   // by attempting to preserve the trailing number in the name if there is one
>> 
>> This "smart" aspect is no longer present right? If the name ends in a number the number will be presented (or at least a few digits) simply because it comes at the end.
>> 
>> There will always be cases where the truncation method results in a "worse" name than an alternate truncation method would - hence why I do not think it is worth over engineering this. For example if the name is `ForkJoinPool-5-worker-21` you will lose important information no matter what.
>
> This series of ASAN issues came from a real customer case we are working on, and in that one having the trailing number preserved was really useful. And certainly, something like "C2 Com..hread4" is more useful than "C2 CompilerThre"?

But in terms of the comment, you are not actually doing anything special if there happens to be a number at the end of the name.

>> src/hotspot/os/linux/os_linux.cpp line 4871:
>> 
>>> 4869:   if (Linux::_pthread_setname_np) {
>>> 4870:     // set name in pthread lib
>>> 4871:     rc = Linux::_pthread_setname_np(pthread_self(), buf);
>> 
>> This seems redundant given we have to do the `prctl` directly ourselves.
>
> `pthread_setname_np` does more than `prctl`, though. It also populates the task name entry in /proc. See `ls /proc/<pid>/task/comm | xargs cat` . 
> 
> We could do this ourselves, too, admittedly. That could get rid of the dlsym for the _pthread_setname, but goes a bit beyond the scope of this PR. And if glibc ever adds anything to `pthread_setname_np`, we will miss out. What do you think?

We only ever call setname on the current thread so we never reach the part that would populate /proc:

 if (pd == THREAD_SELF)
    return __prctl (PR_SET_NAME, name) ? errno : 0;

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27395#discussion_r2374627069
PR Review Comment: https://git.openjdk.org/jdk/pull/27395#discussion_r2374632340


More information about the hotspot-dev mailing list