On Thu, 22 Feb 2024 21:43:23 GMT, Alex Menkov <[email protected]> wrote:
>> VirtualMachine.loadAgentPath/loadAgentLibrary can fail with
>> AgentLoadException in 2 cases:
>> - attach listener returns error; in the case the exception is thrown from
>> HotSpotVirtualMachine.processCompletionStatus (called from
>> HotSpotVirtualMachine.execute);
>> - attach listener returns success, but reply does not contain Agent_onAttach
>> return code ("return code: %d" message).
>>
>> before jdk21 if attach listener fails to load required library, it returned
>> error (case 1)
>> from jdk21 attach listener always returns success (case 2)
>> Both cases are ok, but for 2nd case HotSpotVirtualMachine.loadAgentLibrary
>> read only single line of the response message, so exception message didn't
>> contain error details.
>>
>> The fix updates HotSpotVirtualMachine.loadAgentLibrary to read the whole
>> response message.
>> Walking through the code, fixed some other minor things in attach listener
>> and attach API implementation (commented in the code)
>>
>> Testing:
>> - test/jdk/com/sun/tools;
>> - tier1,tier2,tier5-svc
>
> Alex Menkov has updated the pull request incrementally with one additional
> commit since the last revision:
>
> feedback
In invoke_Agent_OnAttach(), I think the second print_cr() should start with a
space:
st->print_cr("%s was not loaded.", agent->name());
if (*ebuf != '\0') {
st->print_cr("%s", &ebuf[0]);
}
return false;
Otherwise in the output you see the reason for the failure start right after
the period:
`com.sun.tools.attach.AgentLoadException: Failed to load agent library:
FailedLoadAgentTestNotExists was not loaded.libFailedLoadAgentTestNotExists.so:
cannot open shared object file: No such file or directory`
Also, ebuf is of size 1024 and is getting truncated sometimes. See your macosx
log files on mdash. This doesn't necessarily have to be fixed, but something to
consider.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17954#issuecomment-1960431370