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

Thomas Stuefe stuefe at openjdk.org
Wed Sep 24 15:38:59 UTC 2025


> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 12 additional commits since the last revision:

 - correct comment
 - comments
 - Merge branch 'master' into JDK-8368124-Show-useful-thread-names-in-ASAN-reports
 - giving up on general string truncation function; adding gtest for set_thread_name
 - review feedback
 - simplify truncation function
 - windows build error
 - fix comments
 - remove comment duplicates
 - factor out string utility; provide tests
 - ... and 2 more: https://git.openjdk.org/jdk/compare/6dde79fa...996a4958

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/27395/files
  - new: https://git.openjdk.org/jdk/pull/27395/files/62ab1b15..996a4958

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27395&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27395&range=03-04

  Stats: 118555 lines in 833 files changed: 108232 ins; 6579 del; 3744 mod
  Patch: https://git.openjdk.org/jdk/pull/27395.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27395/head:pull/27395

PR: https://git.openjdk.org/jdk/pull/27395


More information about the hotspot-dev mailing list