GeezerVison is showing github.com — Async Profiler causes VM to become unresponsive · Issue #1147 · async-profiler/async-profiler
Async Profiler causes VM to become unresponsive #1147DescriptionDescribe the bug
When running async profiler normally from the CLI we asprof hangs and the VM eventually becomes unresponsive. This happens when attaching with the following command:
$ ./bin/asprof collect -d 10s <pid>
When running asprof, it never returns, we never see "profiling started" statement. The command just hangs indefinitely. This happens with 3.0 and all the latest nightly builds.
This may be circumstantial but in some instances running the load command before running a collect allows us to get samples, however we get the following error when attempt to load the profiler:
$ ./bin/asprof load <pid>
Connected to remote JVM
JVM response code = -1
was not loaded.
lib.so: cannot open shared object file: No such file or directory
Again i'm not sure if this is luck or an actual workaround but it has worked a handful of times.
In some cases, even when the VM becomes unresponsive, I do see that libasyncProfiler.so is mapped into the programs address space. However running any commands from the asprof binary simply hang.
7fc4ef787000-7fc4ef78d000 r--p 00000000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
7fc4ef78d000-7fc4ef7dd000 r-xp 00006000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
7fc4ef7dd000-7fc4ef7f1000 r--p 00056000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
7fc4ef7f1000-7fc4ef7f2000 ---p 0006a000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
7fc4ef7f2000-7fc4ef7f4000 r--p 0006a000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
7fc4ef7f4000-7fc4ef7f5000 rw-p 0006c000 00:1d 43533 /tmp/async-profiler-3.0-e6e0494-linux-x64/lib/libasyncProfiler.so
A note on the setup. Our JVM is prefixed with a custom ld.so for locating native libs that are deployed for JNI usage and not part of the program's jar.
/path/to/ld.so /path/to/java <args>
Another note is that we only see this on certain deployments. Some services can be successfully profiled where as a handful of others experience this issue. We see this issue across VM versions, both GraalVM & OpenJDK and on different version 11, 17 and 21. The one I'm focusing on in this bug report is a vanilla Java 17, Temurin VM.
If you have suggestions I can provide additional debug output. Thanks!
Expected vs. actual behavior
I expect that asprof would be able to attach and run a profile successfully
Reproduction Steps
Simply running a profile will trigger it
./bin/asprof collect -d 10s <pid>
Additional Information/Context
No response
Async-profiler version
async-profiler-3.0-e6e0494-linux-x64
Environment details
Linux 6.9.0 x86_64 GNU/Linux
openjdk 17.0.4 2022-07-19
OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8)
OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing) Activityapangin commented on Feb 23, 2025 Thank you for the report.
We haven't seen the symptoms you're describing - we will appreciate additional debugging details.
- What do you mean by "VM becomes unresponsive"? Does an application continue to run or does it freeze?
- During the issue, does Java process consume CPU or is it completely idle? If it consumes CPU, how much?
- Does the problem happen only with
cpu profiling? What about other profiling modes, e.g. -e alloc or -e lock?
- Try to get native thread dump using
gstack (or pstack on some systems). Mixed stack might be also helpful: jhsdb jstack --mixed --pid PID
j-bahr commented on Feb 27, 2025 Responses inline.
- What do you mean by "VM becomes unresponsive"? Does an application continue to run or does it freeze?
- During the issue, does Java process consume CPU or is it completely idle? If it consumes CPU, how much?
When we attach async profiler, we see that the server stops responding to requests. Our basic health check will time out. CPU utilization for the JVM drops from 60% to idle. Other tools like jstack jhsdb/jstack do not work at this time.
- Does the problem happen only with
cpu profiling? What about other profiling modes, e.g. -e alloc or -e lock?
At this time the behavior is consistent with cpu, lock and alloc profiling.
- Try to get native thread dump using
gstack (or pstack on some systems). Mixed stack might be also helpful: jhsdb jstack --mixed --pid PID
I am able to attach a debugger to the JVM and get stack traces for all threads. The output is quite large so I've included the stack frames for the aysnc profiler thread. It seems to be consistent across multiple runs getting stuck in CodeCache::add. I don't think the nightly builds of async profiler have debug symbols so I can see any of the local variables here. Maybe I can rebuild it locally and get more granular information. mutex=0x00007f5548a12320 is being locked by 17 or so threads in the vm, but I'm not sure if this is normal or not. It seems to be related to get_rs_cache in Gparser.c, in libunwind.
This host is running with jemalloc which may be related to the issues were seeing. If needed I can provide a sanitized dump of all the threads.
thread #495, name = 'Attach Listener', stop reason = signal SIGSTOP
frame #0: 0x00007f55484973dc libc.so.6`__GI___lll_lock_wait [inlined] futex_wait(private=0, expected=2, futex_word=0x00007f5548a12320) at futex-internal.h:146:13
frame #1: 0x00007f55484973c6 libc.so.6`__GI___lll_lock_wait(futex=0x00007f5548a12320, private=0) at lowlevellock.c:50:7
frame #2: 0x00007f554849dff1 libc.so.6`___pthread_mutex_lock [inlined] lll_mutex_lock_optimized(mutex=0x00007f5548a12320) at pthread_mutex_lock.c:49:5
frame #3: 0x00007f554849dfe8 libc.so.6`___pthread_mutex_lock(mutex=0x00007f5548a12320) at pthread_mutex_lock.c:89:7
frame #4: 0x00007f5548808fdb libunwind.so.8`_ULx86_64_dwarf_step [inlined] get_rs_cache(saved_maskp=0x00007f4f2bbfb010, as=0x00007f5548a122c0) at Gparser.c:610:7
frame #5: 0x00007f5548808f9a libunwind.so.8`_ULx86_64_dwarf_step [inlined] find_reg_state(sr=0x00007f4f2bbfb090, c=0x00007f4f2bbfb7e0) at Gparser.c:908:16
frame #6: 0x00007f5548808f9a libunwind.so.8`_ULx86_64_dwarf_step(c=0x00007f4f2bbfb7e0) at Gparser.c:965:14
frame #7: 0x00007f5548804b24 libunwind.so.8`_ULx86_64_step(cursor=0x00007f4f2bbfb7e0) at Gstep.c:71:9
frame #8: 0x00007f5548805977 libunwind.so.8`_ULx86_64_tdep_trace [inlined] trace_init_addr(rsp=<unavailable>, rbp=<unavailable>, rip=139966036685429, cfa=<unavailable>, cursor=0x00007f4f2bbfb7e0, f=<unavailable>) at Gtrace.c:248:10
frame #9: 0x00007f5548805773 libunwind.so.8`_ULx86_64_tdep_trace [inlined] trace_lookup(rsp=<unavailable>, rbp=<unavailable>, rip=139966036685429, cfa=<unavailable>, cache=<unavailable>, cursor=0x00007f4f2bbfb7e0) at Gtrace.c:330:10
frame #10: 0x00007f5548805750 libunwind.so.8`_ULx86_64_tdep_trace(cursor=0x00007f4f2bbfb7e0, buffer=0x00007f5452d190b8, size=0x00007f4f2bbfb424) at Gtrace.c:447:27
frame #11: 0x00007f5548802c47 libunwind.so.8`unw_backtrace(buffer=0x00007f5452d190b8, size=128) at backtrace.c:69:7
frame #12: 0x00007f5548c9fc37 libjemalloc-x86_64.so`jemalloc_je_prof_backtrace [inlined] prof_backtrace_impl(bt=0x00007f4f2bbfc050) at prof_sys.c:59:12
frame #13: 0x00007f5548c9fc29 libjemalloc-x86_64.so`jemalloc_je_prof_backtrace(tsd=0x00007f4f2bbfec08, bt=0x00007f4f2bbfc050) at prof_sys.c:279:2
frame #14: 0x00007f5548c91a20 libjemalloc-x86_64.so`jemalloc_je_prof_tctx_create(tsd=0x00007f4f2bbfec08) at prof.c:187:2
frame #15: 0x00007f5548c24283 libjemalloc-x86_64.so`jemalloc_je_malloc_default [inlined] prof_alloc_prep(sample_event=true, jemalloc_je_prof_active=<unavailable>, tsd=<unavailable>) at prof_inlines.h:141:9
frame #16: 0x00007f5548c24251 libjemalloc-x86_64.so`jemalloc_je_malloc_default [inlined] imalloc_body(tsd=<unavailable>, dopts=<unavailable>, sopts=<unavailable>) at jemalloc.c:2394:23
frame #17: 0x00007f5548c24228 libjemalloc-x86_64.so`jemalloc_je_malloc_default [inlined] imalloc(dopts=<unavailable>, sopts=<unavailable>) at jemalloc.c:2531:10
frame #18: 0x00007f4c61e5b276 libasyncProfiler.so`CodeCache::add(void const*, int, char const*, bool) (.constprop.1186) + 54
frame #19: 0x00007f4c61e6f7f1 libasyncProfiler.so`ElfParser::parseFile(CodeCache*, char const*, char const*, bool) + 721
frame #20: 0x00007f4c61e7043b libasyncProfiler.so`parseLibrariesCallback(dl_phdr_info*, unsigned long, void*) + 2107
frame #21: 0x00007f554857884a libc.so.6`__GI___dl_iterate_phdr(callback=(libasyncProfiler.so`parseLibrariesCallback(dl_phdr_info*, unsigned long, void*)), data=0x00007f54aa3a9428) at dl-iteratephdr.c:75:13
frame #22: 0x00007f4c61e70a2a libasyncProfiler.so`Symbols::parseLibraries(CodeCacheArray*, bool) + 58
frame #23: 0x00007f4c61e518de libasyncProfiler.so`_GLOBAL__sub_I_ + 2110
frame #24: 0x00007f554914b8af ld.so`call_init(l=<unavailable>, argc=72, argv=0x00007ffeebb38480, env=0x00007f5547c31500) at dl-init.c:70:3
frame #25: 0x00007f554914b9a9 ld.so`_dl_init [inlined] call_init(env=0x00007f5547c31500, argv=0x00007ffeebb38480, argc=72, l=<unavailable>) at dl-init.c:33:6
frame #26: 0x00007f554914b97b ld.so`_dl_init(main_map=0x00007f54aa218600, argc=72, argv=0x00007ffeebb38480, env=0x00007f5547c31500) at dl-init.c:117:5
frame #27: 0x00007f5548579a25 libc.so.6`__GI__dl_catch_exception(exception=0x0000000000000000, operate=(ld.so`call_dl_init at dl-open.c:481:3), args=0x00007f4f2bbfc750) at dl-error-skeleton.c:182:7
frame #28: 0x00007f5549150387 ld.so`dl_open_worker(a=0x00007f4f2bbfc920) at dl-open.c:794:5
frame #29: 0x00007f55485799d0 libc.so.6`__GI__dl_catch_exception(exception=0x00007f4f2bbfc900, operate=(ld.so`dl_open_worker at dl-open.c:486:1), args=0x00007f4f2bbfc920) at dl-error-skeleton.c:208:8
frame #30: 0x00007f554914f929 ld.so`_dl_open(file="/tmp/async-profiler-3.0-e6e0494-linux-x64/bin/../lib/libasyncProfiler.so", mode=<unavailable>, caller_dlopen=0x00007f55466170b4, nsid=-2, argc=72, argv=<unavailable>, env=0x00007f5547c31500) at dl-open.c:869:17
frame #31: 0x00007f55484968e0 libc.so.6`dlopen_doit(a=0x00007f4f2bbfcbd0) at dlopen.c:56:15
frame #32: 0x00007f55485799d0 libc.so.6`__GI__dl_catch_exception(exception=0x00007f4f2bbfcb10, operate=(libc.so.6`dlopen_doit at dlopen.c:48:1), args=0x00007f4f2bbfcbd0) at dl-error-skeleton.c:208:8
frame #33: 0x00007f5548579a95 libc.so.6`__GI__dl_catch_error(objname=0x00007f4f2bbfcb80, errstring=0x00007f4f2bbfcb88, mallocedp=0x00007f4f2bbfcb7f, operate=<unavailable>, args=<unavailable>) at dl-error-skeleton.c:227:19
frame #34: 0x00007f5548496433 libc.so.6`_dlerror_run(operate=<unavailable>, args=<unavailable>) at dlerror.c:138:17
frame #35: 0x00007f5548496968 libc.so.6`___dlopen [inlined] dlopen_implementation(dl_caller=<unavailable>, mode=<unavailable>, file=<unavailable>) at dlopen.c:71:10
frame #36: 0x00007f5548496949 libc.so.6`___dlopen(file=<unavailable>, mode=<unavailable>) at dlopen.c:81:12
frame #37: 0x00007f55466170b4 libjvm.so`os::Linux::dlopen_helper(char const*, char*, int) + 36
frame #38: 0x00007f554661732e libjvm.so`os::dll_load(char const*, char*, int) + 94
frame #39: 0x00007f554641f423 libjvm.so`JvmtiExport::load_agent_library(char const*, char const*, char const*, outputStream*) + 243
frame #40: 0x00007f5545e1d33d libjvm.so`attach_listener_thread_entry(JavaThread*, JavaThread*) + 509
frame #41: 0x00007f5546859204 libjvm.so`JavaThread::thread_main_inner() + 388
frame #42: 0x00007f554685c98e libjvm.so`Thread::call_run() + 222
frame #43: 0x00007f55466162c1 libjvm.so`thread_native_entry(Thread*) + 225
frame #44: 0x00007f554849abc9 libc.so.6`start_thread(arg=<unavailable>) at pthread_create.c:434:8
frame #45: 0x00007f554852ce4c libc.so.6`__clone3 at clone3.S:81
apangin commented on Feb 27, 2025 Thank you for the informative update. I believe the problem is understood now.
By coincidence, a similar issue with a was reported yesterday - #1151
In that case, it was caused by tcmalloc's heap profiler, while in your case it's the same bug in jemalloc's heap profiler. Both use libunwind which is deadlock-prone, see the related issues:
The workaround is to disable jemalloc's heap profiler. By the way, async-profiler now includes native memory profiler which can be used instead of jemalloc's one. j-bahr commented on Feb 27, 2025 Thanks for the quick feedback. We'll look at disabling heap profiling and ensuring jemalloc/libunwind are up to date in the event there are any fixes upstream.
I will test the new native memory profiler as well. Does lock/cpu profiling have an alternative until we can work around the jemalloc issues? j-bahr commented on Mar 3, 2025 I just wanted to come and confirm that disabling jemalloc profiling allows async profiler to work correctly. Thanks for the help! apangin commented on Mar 5, 2025 Thanks for confirming this. We are researching possibilities to workaround the issue in async-profiler. j-bahr commented on Mar 23, 2025 It looks like there is a PR in libunwind that addresses the issues, but it's been open for a number of months. I'll reach out to see if we can make any progress on this.
libunwind/libunwind#801 apangin commented on Apr 7, 2025 We've fixed the issue by eliminating dl_iterate_phdr call in async-profiler entirely.
Your feedback is welcome!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|