JDK-8325530 : Vague error message when com.sun.tools.attach.VirtualMachine fails to load agent library
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 21,23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-02-09
  • Updated: 2024-03-05
  • Resolved: 2024-02-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23 b12Fixed
Related Reports
Relates :  
Relates :  
Description
The bug was originally reported against async-profiler [1], but it turned out to be a JDK issue.

Before JDK 21, AttachListener responded with return code -1 if `load` command failed, i.e. dlopen() wasn't successful. Since JDK 21, it started returning 0 whether a library was loaded or not. This caused misbehavior of tools that relied on dynamic attach protocol: particularly, jattach and async-profiler.

The issue can be also observed without external tools. Because of the same bug, Attach API [2] no longer passes dlerror() message to user, making it harder to troubleshoot agent loading.

Example of an error message in JDK 11 - JDK 20:

Exception in thread "main" com.sun.tools.attach.AgentLoadException: Failed to load agent library: libasyncProfiler.so was not loaded./lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by libasyncProfiler.so)
        at jdk.attach/sun.tools.attach.VirtualMachineImpl.execute(VirtualMachineImpl.java:221)
        at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:94)
        at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentPath(HotSpotVirtualMachine.java:128)
        at jdk.attach/com.sun.tools.attach.VirtualMachine.loadAgentPath(VirtualMachine.java:471)
        at AttachTest.main(AttachTest.java:8)

The error message in JDK 21 - JDK 23:

Exception in thread "main" com.sun.tools.attach.AgentLoadException: libasyncProfiler.so was not loaded.
        at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:108)
        at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentPath(HotSpotVirtualMachine.java:128)
        at jdk.attach/com.sun.tools.attach.VirtualMachine.loadAgentPath(VirtualMachine.java:471)
        at AttachTest.main(AttachTest.java:8)

Note that before JDK 21, the error message clearly pointed to the root cause related to GLIBC version. Since JDK 21, the error message is vague.

[1] https://github.com/async-profiler/async-profiler/issues/885
[2] https://docs.oracle.com/en/java/javase/21/docs/api/jdk.attach/com/sun/tools/attach/VirtualMachine.html

Comments
Changeset: fc67c2b4 Author: Alex Menkov <amenkov@openjdk.org> Date: 2024-02-26 23:18:49 +0000 URL: https://git.openjdk.org/jdk/commit/fc67c2b4f17216d4adcc0825d0f378ae4f150025
26-02-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17954 Date: 2024-02-21 21:13:36 +0000
21-02-2024

AttachListener (and Attach API protocol) is internal part of the Attach API implementation. So the original report "Dynamic Attach returns 0 even when library fails to load" should be considered as "not an issue" as far as Attach API throws correct AgentLoadException. JDK issue is a vague error message of AgentLoadException. I'll update the bug synopsis.
17-02-2024

Looks like the regression was introduced by JDK-8257967 New implementation of JvmtiAgentList::load_agent (instead of JvmtiExport::load_agent_library) always return JNI_OK
13-02-2024

The issue appeared after refactoring of agent loading made in JDK-8307478 and JDK-8257967.
09-02-2024