Re: Extend jcmd to java application level

Denghui Dong denghui.ddh at
Sat Oct 9 06:14:44 UTC 2021


Thank you for the response.

I just made a PoC for this extension:

Here is the test code:


public class Test {

  public static void main(String... args) throws Exception {

@CmdMeta(name = "My.Echo")
class Echo implements Command {
    public Echo() {}

    @ParamMeta(name = "text", isMandatory = true)
    String text;

    public void execute(PrintWriter out) {
Verify steps:
1. javac --add-exports
1. java --add-exports Test
3. jcmd <pid> My.Echo text=message

At present, it is only the most basic implementation, mainly referring to the implementation of dmcd in the VM layer. and there are many places that need more careful design and implementation, such as security and timeout

If you think this extension is useful, I'm happy to continue this work.

From:董登辉(卓昂) <denghui.ddh at>
Send Time:2021年10月7日(星期四) 21:58
To:serviceability-dev <serviceability-dev at>; hotspot-runtime-dev at <hotspot-runtime-dev at>
Subject:Extend jcmd to java application level

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.

Denghui Dong

More information about the hotspot-runtime-dev mailing list