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

David Holmes dholmes at openjdk.org
Thu Sep 25 21:47:31 UTC 2025


On Thu, 25 Sep 2025 05:59:59 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> On Linux, ASAN only shows some internal thread designation on reports, e.g. `T49`, which is useless.
>> 
>> This patch adds the ability to see the real internal JVM thread names or user-supplied Java thread names in ASAN. This makes it possible to correlate ASAN reports with hs-err file reports (if ASAN is run with `halt_on_error=0` to give us a chance to get an hs-err file) or with a thread dump done beforehand.
>> 
>> Note that it can only show up to 15 characters, though. Therefore, the patch tries to be smart about names that end in digits: such numbers are preserved such that the truncation happens in the middle of the name, e.g.:
>> 
>> `"MyAllocationWorkerThread#4411"` -> `"MyAllocat..4411"`
>> 
>> This latter improvement now also applies to thread names in gdb, since they are subject to the same limitation.
>> 
>> For a detailed analysis of why the old version, using libpthread's `pthread_setname_np`, is not sufficient for thread names in ASAN, please see the issue description.
>> 
>> -----
>> 
>> Some examples from ASAN report: 
>> 
>> Before:
>> 
>> WRITE of size 8 at 0x7b749d2d9190 thread T49
>> 
>> 
>> Now:
>> 
>> WRITE of size 8 at 0x7bfc2f0d8380 thread T49 (MyThread#0)
>> 
>> 
>> 
>> ==593899==ERROR: AddressSanitizer: attempting free .. in thread T76 (MyAllocati..29)
>
> Thomas Stuefe has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - reorder includes
>  - remove redundant pthread_setname call

Looks good. Thanks for the updates.

I just remembered something - will this work on Alpine Linux with Musl-C?

src/hotspot/os/linux/os_linux.cpp line 4869:

> 4867:   // since this is the only way to make ASAN aware of our thread names. Even
> 4868:   // though ASAN intercepts both prctl and pthread_setname_np, it only processes
> 4869:   // the thread name given to the former.

Suggestion:

  // the thread name given to the former. The two are equivalent when we only set
  // the name of the current thread, which is the case here.

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

Marked as reviewed by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27395#pullrequestreview-3269551455
PR Comment: https://git.openjdk.org/jdk/pull/27395#issuecomment-3336040943
PR Review Comment: https://git.openjdk.org/jdk/pull/27395#discussion_r2380390874


More information about the hotspot-dev mailing list