-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add documentation for jcmd
support
#9987
Open
roberttoyonaga
wants to merge
1
commit into
oracle:master
Choose a base branch
from
roberttoyonaga:jcmd-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
layout: docs | ||
toc_group: debugging-and-diagnostics | ||
link_title: Java Diagnostic Command | ||
permalink: /reference-manual/native-image/debugging-and-diagnostics/jcmd/ | ||
--- | ||
|
||
# Java Diagnostic Command (jcmd) with Native Image | ||
|
||
Native Image now supports the Java Diagnostic Command (`jcmd`), enabling users to interact with native executables using the same `jcmd` tool they use for Java applications. | ||
This support complements existing Native Image monitoring features, including JDK Flight Recorder, heap dumps, and native memory tracking. | ||
|
||
## Enabling `jcmd` Support | ||
|
||
Support for `jcmd` is disabled by default and must be explicitly enabled at build time. | ||
|
||
Use the `--enable-monitoring=jcmd` option to build a native executable with `jcmd` enabled. | ||
```shell | ||
native-image --enable-monitoring=jcmd YourApplication | ||
``` | ||
|
||
When enabling support for `jcmd`, you may also want to include additional monitoring features, such as JDK Flight Recorder or heap dumps. | ||
Including multiple monitoring features during the Native Image build process unlocks access to more diagnostic commands at runtime. For example: | ||
```shell | ||
native-image --enable-monitoring=jcmd,jfr,heapdump YourApplication | ||
``` | ||
|
||
To use `jcmd` at runtime, start your native executable as usual and obtain its process ID (PID). | ||
With the PID, you can use `jcmd` to connect to the running native application. | ||
For example, to list the available commands for a specific executable, run: `jcmd <pid> help`. | ||
```shell | ||
jcmd 388454 help | ||
|
||
388454: | ||
The following commands are available: | ||
GC.heap_dump | ||
GC.run | ||
JFR.start | ||
JFR.stop | ||
JFR.check | ||
JFR.dump | ||
Thread.dump_to_file | ||
Thread.print | ||
VM.command_line | ||
VM.native_memory | ||
VM.system_properties | ||
VM.uptime | ||
VM.version | ||
help | ||
|
||
For more information about a specific command use 'help <command>'. | ||
``` | ||
|
||
roberttoyonaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
You might find it useful to also enable the `jvmstat` monitoring feature so your native executable can be discovered and listed with `jcmd -l` or `jcmd` with no arguments provided. | ||
```shell | ||
native-image --enable-monitoring=jcmd,jvmstat YourApplication | ||
``` | ||
|
||
```shell | ||
jcmd -l | ||
1455557 YourApplication | ||
1455667 jdk.jcmd/sun.tools.jcmd.JCmd -l | ||
``` | ||
|
||
## Supported Diagnostic Commands | ||
roberttoyonaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The following key-value pairs are supported: | ||
|
||
| Name | Included with `--enable-monitoring=` | Description | | ||
|--------------------------|-------------------------------------------------|-----------------------------------------------------------------------------------------------------| | ||
| Compiler.dump_code_cache | Only available with Truffle runtime compilation | Print information about all compiled methods in the code cache. | | ||
| GC.heap_dump | heapdump | Generate a HPROF format dump of the Java heap. | | ||
| GC.run | Always available | Call `java.lang.System.gc()`. | | ||
| JFR.start | jfr | Starts a new JFR recording. | | ||
| JFR.stop | jfr | Stops a JFR recording. | | ||
| JFR.check | jfr | Checks running JFR recording(s). | | ||
| JFR.dump | jfr | Copies contents of a JFR recording to file. Either the name or the recording id must be specified. | | ||
| Thread.dump_to_file | Always available | Dump threads, with stack traces, to a file in plain text or JSON format. | | ||
| Thread.print | Always available | Print all threads with stacktraces. | | ||
| VM.command_line | Always available | Print the command line used to start this VM instance. | | ||
| VM.native_memory | nmt | Print native memory usage. | | ||
| VM.system_properties | Always available | Print native memory usage | | ||
| VM.uptime | Always available | Print VM uptime. | | ||
| VM.version | Always available | Print JVM version information. | | ||
| help | Always available | Display help information. | | ||
|
||
## Performance | ||
|
||
Adding `jcmd` support to Native Image has minimal impact on performance when the application is idle. | ||
However, the performance impact varies significantly depending on the diagnostic commands used and how frequently they are invoked. | ||
For example, triggering multiple garbage collections will have a much greater overhead than dumping a single native memory tracking report. | ||
You can use `jcmd <pid> help <command>` to print the help information for a specific command which also lists its expected performance impact. | ||
|
||
roberttoyonaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Limitations | ||
|
||
Currently, this feature is not available on Windows. | ||
|
||
### Further Reading | ||
|
||
- [Debugging and Diagnostics](DebuggingAndDiagnostics.md) | ||
- [Build and Run Native Executables with JFR](guides/build-and-run-native-executable-with-jfr.md) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please briefly mention
jvmstat
as well (withoutjvmstat
support,jcmd
won't list the native image process ifjcmd
is executed without any arguments).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I've added a note about jvmstat