RFR: 8368124: Show useful thread names in ASAN reports [v7]
Matthias Baesken
mbaesken at openjdk.org
Thu Sep 25 07:16:36 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
Marked as reviewed by mbaesken (Reviewer).
Tested it on our CI runs; the thread names look like below now ; for the JLI thread we seem to have no 'good' name just
'Thread T1 created by T0 here' ... but that's what it is right now. The others show the Java/JVM thread names .
==18331==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x506000028974 at pc 0x7f50ed88327a bp 0x7f5098f44c50 sp 0x7f5098f44c48
READ of size 1 at 0x506000028974 thread T60 (Command..212m9])
#0 0x7f50ed883279 in ClassFileParser::skip_over_field_signature(char const*, bool, unsigned int, JavaThread*) const src/hotspot/share/classfile/classFileParser.cpp:4685
#1 0x7f50ed88c48b in ClassFileParser::verify_legal_method_signature(Symbol const*, Symbol const*, JavaThread*) const src/hotspot/share/classfile/classFileParser.cpp:4916
#2 0x7f50ed89c33c in ClassFileParser::parse_method(ClassFileStream const*, bool, ConstantPool const*, bool*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:2189
#3 0x7f50ed89f7f7 in ClassFileParser::parse_methods(ClassFileStream const*, bool, bool*, bool*, bool*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:2741
#4 0x7f50ed89f7f7 in ClassFileParser::parse_methods(ClassFileStream const*, bool, bool*, bool*, bool*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:2717
#5 0x7f50ed8a8190 in ClassFileParser::parse_stream(ClassFileStream const*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5708
#6 0x7f50ed8abf05 in ClassFileParser::parse_stream(ClassFileStream const*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5436
#7 0x7f50ed8abf05 in ClassFileParser::ClassFileParser(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const*, ClassFileParser::Publicity, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5433
#8 0x7f50eef01ba5 in KlassFactory::create_from_stream(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const&, JavaThread*) src/hotspot/share/classfile/klassFactory.cpp:202
#9 0x7f50f003fc92 in SystemDictionary::resolve_class_from_stream(ClassFileStream*, Symbol*, Handle, ClassLoadInfo const&, JavaThread*) src/hotspot/share/classfile/systemDictionary.cpp:874
#10 0x7f50ee9c4ef7 in jvm_define_class_common src/hotspot/share/prims/jvm.cpp:888
#11 0x7f50ee9c5dd7 in JVM_DefineClassWithSource src/hotspot/share/prims/jvm.cpp:1055
#12 0x7f50f32cb914 in Java_java_lang_ClassLoader_defineClass1 src/java.base/share/native/libjava/ClassLoader.c:139
#13 0x7f50da46c16f ()
0x506000028974 is located 0 bytes after 52-byte region [0x506000028940,0x506000028974)
allocated by thread T60 (Command..212m9]) here:
#0 0x7f50f42f7237 in malloc (/usr/lib64/libasan.so.8+0xf7237) (BuildId: 976da020d733554aded39770c1e088dce0154259)
#1 0x7f50ef5b5517 in permit_forbidden_function::malloc(unsigned long) src/hotspot/share/utilities/permitForbiddenFunctions.hpp:63
#2 0x7f50ef5b5517 in os::malloc(unsigned long, MemTag, NativeCallStack const&) src/hotspot/share/runtime/os.cpp:660
#3 0x7f50ecf0773b in AllocateHeap(unsigned long, MemTag, NativeCallStack const&, AllocFailStrategy::AllocFailEnum) src/hotspot/share/memory/allocation.cpp:39
#4 0x7f50ecf0773b in AllocateHeap(unsigned long, MemTag, AllocFailStrategy::AllocFailEnum) src/hotspot/share/memory/allocation.cpp:49
#5 0x7f50f000dc90 in SymbolTableConfig::allocate_node_impl(unsigned long, Symbol const&) src/hotspot/share/classfile/symbolTable.cpp:195
#6 0x7f50f000dc90 in SymbolTableConfig::allocate_node(void*, unsigned long, Symbol const&) src/hotspot/share/classfile/symbolTable.cpp:137
#7 0x7f50f000dc90 in ConcurrentHashTable::Node::create_node(void*, Symbol const&, ConcurrentHashTable::Node*) src/hotspot/share/utilities/concurrentHashTable.hpp:93
#8 0x7f50f000dc90 in bool ConcurrentHashTable::internal_insert_get::insert(Thread*, SymbolTableLookup&, Symbol const&, bool*, bool*)::NOP>(Thread*, SymbolTableLookup&, Symbol const&, ConcurrentHashTable::insert(Thread*, SymbolTableLookup&, Symbol const&, bool*, bool*)::NOP&, bool*, bool*) src/hotspot/share/utilities/concurrentHashTable.inline.hpp:896
#9 0x7f50f000dc90 in bool ConcurrentHashTable::insert(Thread*, SymbolTableLookup&, Symbol const&, bool*, bool*) src/hotspot/share/utilities/concurrentHashTable.hpp:471
#10 0x7f50f000dc90 in SymbolTable::do_add_if_needed(char const*, int, unsigned long, bool) src/hotspot/share/classfile/symbolTable.cpp:520
#11 0x7f50f0011c7a in SymbolTable::new_symbols(ClassLoaderData*, constantPoolHandle const&, int, char const**, int*, int*, unsigned int*) src/hotspot/share/classfile/symbolTable.cpp:498
#12 0x7f50ed8a38c0 in ClassFileParser::parse_constant_pool_entries(ClassFileStream const*, ConstantPool*, int, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:390
#13 0x7f50ed8a6b8f in ClassFileParser::parse_constant_pool(ClassFileStream const*, ConstantPool*, int, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:425
#14 0x7f50ed8a6b8f in ClassFileParser::parse_stream(ClassFileStream const*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5571
#15 0x7f50ed8abf05 in ClassFileParser::parse_stream(ClassFileStream const*, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5436
#16 0x7f50ed8abf05 in ClassFileParser::ClassFileParser(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const*, ClassFileParser::Publicity, JavaThread*) src/hotspot/share/classfile/classFileParser.cpp:5433
#17 0x7f50eef01ba5 in KlassFactory::create_from_stream(ClassFileStream*, Symbol*, ClassLoaderData*, ClassLoadInfo const&, JavaThread*) src/hotspot/share/classfile/klassFactory.cpp:202
#18 0x7f50f003fc92 in SystemDictionary::resolve_class_from_stream(ClassFileStream*, Symbol*, Handle, ClassLoadInfo const&, JavaThread*) src/hotspot/share/classfile/systemDictionary.cpp:874
#19 0x7f50ee9c4ef7 in jvm_define_class_common src/hotspot/share/prims/jvm.cpp:888
#20 0x7f50ee9c5dd7 in JVM_DefineClassWithSource src/hotspot/share/prims/jvm.cpp:1055
#21 0x7f50f32cb914 in Java_java_lang_ClassLoader_defineClass1 src/java.base/share/native/libjava/ClassLoader.c:139
#22 0x7f50da46c16f ()
#23 0x7f50da4679e1 ()
#24 0x7f50da4679e1 ()
#25 0x7f50da4679e1 ()
#26 0x7f50da4679e1 ()
#27 0x7f50d30a7c5b ()
#28 0x7f50da4679e1 ()
#29 0x7f50da4679e1 ()
#30 0x7f50da467847 ()
#31 0x7f50da467d55 ()
#32 0x7f50da467847 ()
#33 0x7f50da4606a6 ()
#34 0x7f50ee5bfaf7 in JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:415
#35 0x7f50ee5c83a1 in JavaCalls::call(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:323
#36 0x7f50ee5c83a1 in JavaCalls::call_virtual(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:179
#37 0x7f50ee5c83a1 in JavaCalls::call_virtual(JavaValue*, Handle, Klass*, Symbol*, Symbol*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:185
#38 0x7f50ee97ebd8 in thread_entry src/hotspot/share/prims/jvm.cpp:2707
#39 0x7f50ee61e5c2 in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:775
#40 0x7f50ee633317 in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:755
#41 0x7f50ee633317 in JavaThread::run() src/hotspot/share/runtime/javaThread.cpp:760
Thread T60 (Command..212m9]) created by T29 (Agent0) here:
#0 0x7f50f42ef0c1 in pthread_create (/usr/lib64/libasan.so.8+0xef0c1) (BuildId: 976da020d733554aded39770c1e088dce0154259)
#1 0x7f50ef5d3bb0 in os::create_thread(Thread*, os::ThreadType, unsigned long) src/hotspot/os/linux/os_linux.cpp:1091
#2 0x7f50ee9c912c in JVM_StartThread src/hotspot/share/prims/jvm.cpp:2770
#3 0x7f50da46c16f ()
#4 0x7f50da467847 ()
#5 0x7f50da467847 ()
#6 0x7f50da4679e1 ()
#7 0x7f50da4679e1 ()
#8 0x7f50da4679e1 ()
#9 0x7f50da467847 ()
#10 0x7f50da467847 ()
#11 0x7f50da467847 ()
#12 0x7f50da467d55 ()
#13 0x7f50da467847 ()
#14 0x7f50da4606a6 ()
#15 0x7f50ee5bfaf7 in JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:415
#16 0x7f50ee5c83a1 in JavaCalls::call(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:323
#17 0x7f50ee5c83a1 in JavaCalls::call_virtual(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:179
#18 0x7f50ee5c83a1 in JavaCalls::call_virtual(JavaValue*, Handle, Klass*, Symbol*, Symbol*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:185
#19 0x7f50ee97ebd8 in thread_entry src/hotspot/share/prims/jvm.cpp:2707
#20 0x7f50ee61e5c2 in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:775
#21 0x7f50ee633317 in JavaThread::thread_main_inner() src/hotspot/share/runtime/javaThread.cpp:755
#22 0x7f50ee633317 in JavaThread::run() src/hotspot/share/runtime/javaThread.cpp:760
#23 0x7f50f013df8f in Thread::call_run() src/hotspot/share/runtime/thread.cpp:243
#24 0x7f50ef5d0972 in thread_native_entry src/hotspot/os/linux/os_linux.cpp:898
#25 0x7f50f425eef5 (/usr/lib64/libasan.so.8+0x5eef5) (BuildId: 976da020d733554aded39770c1e088dce0154259)
Thread T29 (Agent0) created by T1 here:
#0 0x7f50f42ef0c1 in pthread_create (/usr/lib64/libasan.so.8+0xef0c1) (BuildId: 976da020d733554aded39770c1e088dce0154259)
#1 0x7f50ef5d3bb0 in os::create_thread(Thread*, os::ThreadType, unsigned long) src/hotspot/os/linux/os_linux.cpp:1091
#2 0x7f50ee9c912c in JVM_StartThread src/hotspot/share/prims/jvm.cpp:2770
#3 0x7f50da46c16f ()
#4 0x7f50da467847 ()
#5 0x7f50da467847 ()
#6 0x7f50da467847 ()
#7 0x7f50da467847 ()
#8 0x7f50da467847 ()
#9 0x7f50da4606a6 ()
#10 0x7f50ee5bfaf7 in JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*) src/hotspot/share/runtime/javaCalls.cpp:415
#11 0x7f50ee8dca93 in jni_invoke_static src/hotspot/share/prims/jni.cpp:881
#12 0x7f50ee8e80c9 in jni_CallStaticVoidMethod src/hotspot/share/prims/jni.cpp:1710
#13 0x7f50f41df05b in invokeStaticMainWithArgs src/java.base/share/native/libjli/java.c:392
#14 0x7f50f41e2cef in JavaMain src/java.base/share/native/libjli/java.c:640
#15 0x7f50f41e7fd8 in ThreadJavaMain src/java.base/unix/native/libjli/java_md.c:646
#16 0x7f50f425eef5 (/usr/lib64/libasan.so.8+0x5eef5) (BuildId: 976da020d733554aded39770c1e088dce0154259)
Thread T1 created by T0 here:
#0 0x7f50f42ef0c1 in pthread_create (/usr/lib64/libasan.so.8+0xef0c1) (BuildId: 976da020d733554aded39770c1e088dce0154259)
#1 0x7f50f41e9928 in CallJavaMainInNewThread src/java.base/unix/native/libjli/java_md.c:687
#2 0x7f50f41e5580 in ContinueInNewThread src/java.base/share/native/libjli/java.c:2340
#3 0x7f50f41e6edd in JLI_Launch src/java.base/share/native/libjli/java.c:330
#4 0x55a3f79d70fc in main src/java.base/share/native/launcher/main.c:150
#5 0x7f50f3e40e6b in __libc_start_call_main (/lib64/libc.so.6+0x40e6b) (BuildId: 16dc6ffdd6165c6cb0346d683a041c90daa99730)
-------------
PR Review: https://git.openjdk.org/jdk/pull/27395#pullrequestreview-3266121314
PR Comment: https://git.openjdk.org/jdk/pull/27395#issuecomment-3332494824
More information about the hotspot-dev
mailing list