New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8275259: Add support for Java level DCmd #5938
Conversation
|
Webrevs
|
/label add hotspot-runtime |
/label remove hotspot |
@D-D-H |
@D-D-H |
An API that is expected to be used by application code can't go in the unsupported/internal-use-only sun.management namespace. This would have to be a new external facing supported API. Cheers, |
Thanks. |
Mailing list message from David Holmes on hotspot-runtime-dev: On 14/10/2021 4:32 pm, Denghui Dong wrote:
There are very specific rules related to the use of the javax namespace. I'm not sure exactly where this API would need to go. IIUC jcmd doesn't David |
IMO, Denghui |
Mailing list message from David Holmes on hotspot-runtime-dev: On 14/10/2021 5:14 pm, Denghui Dong wrote:
Ah right - so you're really looking at extending the capabilities of the David |
Yes, but we could not add registration API to DiagnosticCommandMBean directly. There are already some VM diagnostic commands that depend on Java methods directly, this extension could also bring benefit to this scenario I think. Hope folks from serviceability could take a look at it:) Denghui |
Hi, Interesting proposal. I have some questions.
Cheers, Thomas P.S. I think it may be worthwhile to discuss this on the serviceability-dev mailing list first. |
To understand what is needed (namespacing, error handling, safety, lifecycle etc.) and if this is actually useful for Java, I think you need to write 2-3 commands for a few popular frameworks, for example Spring. If we can't come up with 5-10 commands where this functionality would solve real problems users face, it's unlikely somebody will use it. It will just be a maintenance burden in the JDK. Once an API is added, it's hard to remove. The scope of this seem to be JEP level. (JFR is not a valid use case, since we don't want to add a dependency on annotation classes in the jdk.jcmd module). |
Hi Thomas,
In my current implementation, I use a simple timeout mechanism to solve this problem. Create a Thread to run the command, and use For more details please refer to Executor.java.
At present, I only extend the DCMD framework and do not modify the code of jcmd. So it works with any jcmd client and jmx client, up and downward JDK versions I think.
Denghui |
Hi Erik,
Thanks for the comments. I will investigate whether there is a scenario to apply this extension in the current mainstream framework. Denghui |
Hi Denghui, thanks for your answers. I'm ambivalent here. I worry about the growing complexity of jcmd, and about unforeseen consequences if we open this door. OTOH I can see this as a useful feature. I'll wait for a consensus. Thanks, Thomas |
Seems no more comments on this issue, but I still think this is a useful feature and want it could be a standard feature. The following is my thought. The idea of this feature originally came from our internal Java agent that detects the misusage of Unsafe API. This agent can collect the call sites that allocate or free direct memory in the application(NMT could not do it IMO) to detect direct memory leaks. In the beginning, it just prints call sites, without any statistical function, it's hard to use. So we plan to use a way similar to jeprof (from jemalloc) to generate a report file that aggregates all useful information. During the implementation process, we found that we need a mechanism to notify the agent to generate reports. The common practice is: But these three ways have certain problems. Essentially, this question is how to notify the application to do a certain task, or in other words, how do we issue a command to the application. Naturally, we think that This feature will be very useful for some lightweight tools, just like the scenario we encountered, to notify the tools to perform certain operations. In addition, this feature will also bring benefits to Java beginners.
If developers can easily and dynamically control the value of
I agree with what Erik said, we need to find applicable scenarios in some mainstream frameworks. After my preliminary investigation, I think we can apply this feature in the features of But to be honest, these frameworks are very mature and stable, and for compatibility purposes, it's hard to let them use this extension. In terms of code maintainability, the implementation of this extension does not need to destroy the existing framework. The current implementation only extends the DCmd framework and provides several simple APIs for users to use. I think there will not be too many costs after it's stable. If this feature could become a standard feature, I will be the first user:) Best, |
Hi Denghui, as I wrote before, I am neutral on this. But I agree with @egahlin that this seems to be more on JEP level. A PR is not the right first step for this, and I am afraid you won't build much consensus here. Maybe discuss this first on the serviceability ML? Or on hotspot-dev? Kind Regards, Thomas |
Okay, thanks! |
Mailing list message from Chris Plummer on hotspot-runtime-dev: On 10/14/21 12:38 AM, David Holmes wrote:
Just reviewing some previous emails and noticed this one since I https://docs.oracle.com/en/java/javase/15/docs/api/jdk.management/com/sun/management/DiagnosticCommandMBean.html DynamicMBean provides the invoke() interface, which when used on a
Yes to "add a way to register a Java diagnostic command", but the new In any case, I think having an API that allows you to invoke a Chris |
Mailing list message from Ioi Lam on hotspot-runtime-dev: On 11/9/21 2:07 PM, Chris Plummer wrote:
Is there anything in the proposal that cannot be done by JMX? If the app Granted, it's bit more tedious to connect to JMX than using "jcmd". Thanks |
Thanks for the commands, the following is my thought. Compared with the user's own implementation of a DiagnosticCommandMBean, the main benefits of this extension are: Users can directly use I am not an expert in the security field, but I feel that implementing a DiagnosticCommandMBean by the users does not seem to be more secure than the method in the proposal. I mean the users can still do whatever they want. Just like Chris said, it seems that not many people are interested in this proposal. I plan to close this PR first. Denghui, |
(RFC: https://mail.openjdk.java.net/pipermail/serviceability-dev/2021-October/039796.html)
I proposed to extend DCmd to allow Java developers to customize their own diagnostic commands last week.
At present, I have implemented a preliminary version.
In the current implementation, I provided some simple APIs in the Java layer (under sun.management.cmd) for defining and registering commands.
Java diagnostic commands need to implement this interface, the interface only contains a simple method:
Add two annotations (@command and @parameter) to describe the command meta info
Use Factory API to register command, the following forms are supported
Executor.executeCommand
to execute the command. In the implementation of Executor, I introduced a simple timeout mechanism to prevent the command channel from being blocked.At the VM layer, I extended the existing DCmd framework(implemented JavaDCmd and JavaDCmdFactoryImpl) to be compatible with existing functions (jmx, help, etc.).
In terms of security, considering that the SecurityManager will be deprecated, there are not too many considerations for the time being.
Any input is appreciated.
Thanks,
Denghui
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5938/head:pull/5938
$ git checkout pull/5938
Update a local copy of the PR:
$ git checkout pull/5938
$ git pull https://git.openjdk.java.net/jdk pull/5938/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5938
View PR using the GUI difftool:
$ git pr show -t 5938
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5938.diff