JDK-8177064: jcmd help command should not require the process identification

Gary Adams gary.adams at oracle.com
Fri Apr 12 11:47:52 UTC 2019


On 4/11/19, 8:16 PM, David Holmes wrote:
> Hi Gary,
>
> On 12/04/2019 4:24 am, Gary Adams wrote:
>> Two years ago a request was made to allow
>>
>>     jcmd help
>>
>> to be interpretted as a request for help from the current jcmd process
>> rather than requiring a separate target process to be involved.
>>
>> Some attempts were made to close the issue, because the
>> command was not documented to work that way.
>> It was also pointed out that the help from the running jcmd
>> might not match the cmds available from a subsequent
>> request to a different process possibly running a different version
>> of the vm.
>>
>> As proof of concept exercise this webrev shows a minimal set of
>> changes that could support
>>
>>    jcmd self help
>>
>> Before fleshing out additional changes in documentation and testing,
>> I'd like to know if this is still a worth while enhancement. Also,
>
> Given we allow a pid of 0 to mean all Java processes I can see scope 
> for a special value that means "the current Java process", but using a 
> text word like "self" seems awkward at best. Plus within a shell you 
> can use: 
> jcmd $$ help
$$ is the pid for the shell where the command is running,
not the jcmd pid.

$ jcmd $$ help
17076:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket 
file: target process not responding or HotSpot VM not loaded
     at sun.tools.attach.BsdVirtualMachine.<init>(BsdVirtualMachine.java:90)
     at 
sun.tools.attach.BsdAttachProvider.attachVirtualMachine(BsdAttachProvider.java:63)
     at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
     at sun.tools.jcmd.JCmd.executeCommandForPid(JCmd.java:147)
     at sun.tools.jcmd.JCmd.main(JCmd.java:131)

>
> to act on the jcmd VM itself, so there doesn't need to be special 
> treatment in that sense. Perhaps some tweaks to the "jcmd -h" text.
If we did allow the self attach, we would need to update the help text.
I initially worked with -1 as another special value, but that looks a lot
like -l the list argument.

>
>> I'd like to know more about the history of the checks preventing self 
>> attach.
>
> This may give you a start: 
> https://bugs.openjdk.java.net/browse/JDK-8177154
I understand the dangers of agent loading and the arguments against
command line options and default settings that took place in jdk9
release.

I'm looking for something older that explains the rationale about
not allowing attach to the current process.
>
> Cheers,
> David
>
>>    Webrev: http://cr.openjdk.java.net/~gadams/8177064/webrev/index.html
>>    Issue: https://bugs.openjdk.java.net/browse/JDK-8177064



More information about the serviceability-dev mailing list