On 10/7/21 6:25 PM, David Holmes wrote:
Hi Denghui,

On 7/10/2021 11:58 pm, Denghui Dong wrote:
Hi team,

The `jcmd` command can be used to call some built-in diagnostic commands in vm. Can we consider extending it to the java layer like perf data, so that Java developers can
customize their diagnostic commands and then call them through `jcmd`?

One application scenario I can think of for this extension is that some statistical information may be collected in a java application. Triggering the output of this statistical information through the `jcmd` command seems to me relative to other mechanisms that trigger output (such as through
an HTTP service, or periodic Printing) is more convenient.

Any input is appreciated.

If the intent is that you could issue a jcmd:

jcmd <vmid> MyClass.foo

to have it run/use a Java thread to execute arbitrary code then I think a lot of careful consideration would need to be given to making this facility safe and secure. I can easily imagine that the thread used, and the timing, could cause failures. Executing arbitrary code may be far too general, so it might mean we need a new "service" interface defined that the target class has to implement.

It might well be useful but will need some deep thought IMO.


If I understood correctly, the app would need to call an API like:


    JcmdProvider.register("mycmd1", new JcmdHandler() {
       public void handleCommand(String args[], PrintStream out) {
           out.print("my response is ");

      ... }
    });

and then the user can issue:

    jcmd <pid> mycmd1 args .....

which will reach the handleCommand() method provided by the app.

Thanks
- Ioi






Cheers,
David

Thanks,
Denghui Dong

Reply via email to