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

David Holmes dholmes at openjdk.org
Mon Sep 22 06:18:14 UTC 2025


On Mon, 22 Sep 2025 06:10:37 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Thomas Stuefe has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   windows build error
>
> src/hotspot/os/linux/os_linux.cpp line 4867:
> 
>> 4865:   StringUtils::abbreviate_preserve_trailing_number(name, buf, sizeof(buf));
>> 4866:   // set name in kernel
>> 4867:   int rc = prctl(PR_SET_NAME, buf);
> 
> So really this little part is the actual crux of this PR - the thing that makes the name appear to ASAN. But why do we have to do this for ASAN  and not gdb for example? According to the doc:
>>    PR_SET_NAME (since Linux 2.6.9)
>               Set  the name of the calling thread, using the value in the location pointed to by (char *) arg2.  The name can be
>               up to 16 bytes long, including the terminating null byte.  (If the length of the string, including the terminating
>               null  byte,  exceeds  16 bytes, the string is silently truncated.)  This is the same attribute that can be set via
>               pthread_setname_np(3) and retrieved  using  pthread_getname_np(3).   The  attribute  is  likewise  accessible  via
>               /proc/self/task/tid/comm  (see  proc(5)),  where  tid  is the thread ID of the calling thread, as returned by get?
>               tid(2).
> 
> So as we already use `pthread_setname_np` why is this not sufficient for ASAN? And given both of these API's claim to write the name to the same place in /proc why would we now do it twice??
> 
> FWIW I think your truncation approach is over-engineered given the type of names it will actually be useful for. Why not simply print the first and last 6 chars with `...` between them?

I see now in JBS that you say you don't know why what we have doesn't work for ASAN, but I think we need to determine that.

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

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


More information about the hotspot-dev mailing list