Hi,
Buffer size for receiving packets from client is determined at [1].
It defines length of command name and of argument.
It is passed via Unix domain, so we fill '\0' to remaining bytes and
might be able to assume all arguments are passed with empty string.
BTW length of arguments is defined to 1024 in [2].
jcmd and jmap might pas file path - it might be JVM_MAXPATHLEN (4097 bytes).
Buffer size which is used in AttachListener seems not to be enough.
We might have to change more.
Thanks,
Yasumasa
[1]
http://hg.openjdk.java.net/jdk/jdk/file/df3d253aaf81/src/hotspot/os/linux/attachListener_linux.cpp#l254
[2]
http://hg.openjdk.java.net/jdk/jdk/file/df3d253aaf81/src/hotspot/share/services/attachListener.hpp#l106
On 2019/02/27 15:00, 臧琳 wrote:
Another solution I can figure out is try to add timeout for socket read. I will
also investigate whether is works.
Cheers,
Lin
-----Original Message-----
From: 臧琳
Sent: Wednesday, February 27, 2019 1:52 PM
To: 'David Holmes' <david.hol...@oracle.com>; Yasumasa Suenaga
<yasue...@gmail.com>
Cc: serviceability-dev@openjdk.java.net
Subject: RE: Protocol version of Attach API
Dear David, Yasumasa,
I think it is hard to know how long the buffer is passed from socket
without changing the info of the message from the receiver side.
So how about when str_count reach to 3, we test it with non_blocking
read?
Cheers,
Lin
-----Original Message-----
From: David Holmes <david.hol...@oracle.com>
Sent: Wednesday, February 27, 2019 1:44 PM
To: Yasumasa Suenaga <yasue...@gmail.com>; 臧琳 <zangl...@jd.com>
Cc: serviceability-dev@openjdk.java.net
Subject: Re: Protocol version of Attach API
Hi Yasumasa,
On 27/02/2019 1:05 pm, Yasumasa Suenaga wrote:
Hi Lin,
My proposal is a just idea, so you need to tweak it.
AttachListener receives raw command.
For example, jcmd is `jcmd\0<arg strings>`. Please see
HotSpotVirtualMachine and extended classes.
In case of jcmd, I guess AttachListener will receive message
`<version>\0jcmd\0<args>\0\0\0` (I did not check it well).
So I guess we can add '\0' when `str_count` does not reach to maximum.
I don't see how this approach can work. You have to know how many
arguments are coming in the "packet", but that information is not
available in the current Linux implementation.Without it you can't
know when to stop calling read().
The protocol would need to be changed to send the "packet" size, but
that's not compatible with older JDKs.
Otherwise I think we have no choice but to use a non-blocking read ...
though I'm still unsure if you can know for certain that you've
reached the end of the "packet" ...
Thanks,
David
Thanks,
Yasumasa
On 2019/02/27 11:50, zangl...@jd.com wrote:
Dear Yasumasa,
The fix you mentioned seems not work as expected.
I have done an experiment that use jdk1.8's "jcmd <pid> help" to
attach to latest jdk.
it seem the whole "jcmd <pid> help" buffer is not
read completely at one time. in my case it is "jcmd", "<pid>",
"help", and then block at while().
After applied your change, it seems only the "jcmd" is
processed, the "<pid>", "help" is replaced by '\0'.
BRs,
Lin