Skip to content

Commit df8f99d

Browse files
authored
Merge pull request #155 from bulasevich/GR-58070
[Backport][GR-58070] Update VisualVM documentation and add more validation for the option '--enable-monitoring'.
2 parents 689f168 + 109cb6a commit df8f99d

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

docs/tools/visualvm.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ VisualVM enables powerful yet easy-to-use Java tooling which includes heap analy
2424

2525
Immediately after startup, the tool shows all locally running Java processes in the Applications area, including the VisualVM process, itself.
2626

27+
### Using VisualVM with GraalVM Native Executables
28+
29+
> Note: VisualVM support for GraalVM native executables is not yet available on Windows.
30+
31+
When using GraalVM [Native Image](../reference-manual/native-image/README.md), VisualVM support is disabled by default.
32+
VisualVM support can be enabled when building a native executable with the option `--enable-monitoring=jvmstat,heapdump`:
33+
```shell
34+
native-image --enable-monitoring=jvmstat,heapdump JavaApplication
35+
```
36+
2737
### Capture a Heap Dump
28-
To capture a heap dump of, for example, a Ruby application for later analysis, start your application and let it run for a few seconds to warm up.
38+
To capture a heap dump for later analysis, start your application and let it run for a few seconds to warm up.
2939
Then right-click its process in VisualVM and invoke the Heap Dump action.
30-
A new heap viewer for the Ruby process opens.
31-
32-
__Note:__ Heap dump support must be explicitly enabled when using [Native Image](../reference-manual/native-image/README.md).
33-
Add the `--enable-monitoring=heapdump,jvmstat` option when invoking the `native-image` tool to enable the heap dump feature and allow VisualVM to detect native executables via `jvmstat`.
34-
This way your application will handle signals and capture a heap dump when it receives the `SIGUSR1` signal.
35-
See the [Generating Native Heap Dumps](../reference-manual/native-image/guides/create-heap-dump-from-native-executable.md) page for details on capturing heap dumps from a native image process.
3640

3741
### Analyzing Objects
3842
Initially the Summary view for the Java heap is displayed.

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public final class VMInspectionOptions {
5959
private static final String MONITORING_ALLOWED_VALUES = "'" + MONITORING_HEAPDUMP_NAME + "', '" + MONITORING_JFR_NAME + "', '" + MONITORING_JVMSTAT_NAME + "', '" + MONITORING_JMXSERVER_NAME +
6060
"' (experimental), '" + MONITORING_JMXCLIENT_NAME + "' (experimental), or '" + MONITORING_ALL_NAME +
6161
"' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";
62+
private static final List<String> NOT_SUPPORTED_ON_WINDOWS = List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME, MONITORING_JVMSTAT_NAME, MONITORING_JMXCLIENT_NAME, MONITORING_JMXSERVER_NAME);
6263

6364
@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME) //
6465
@Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES + ". " +
@@ -75,12 +76,23 @@ public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused")
7576
getDefaultMonitoringCommandArgument(),
7677
SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, String.join(",", List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME))));
7778
}
79+
7880
enabledFeatures.removeAll(List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME, MONITORING_JVMSTAT_NAME, MONITORING_JMXCLIENT_NAME, MONITORING_JMXSERVER_NAME, MONITORING_ALL_NAME,
7981
MONITORING_DEFAULT_NAME));
8082
if (!enabledFeatures.isEmpty()) {
8183
throw UserError.abort("The '%s' option contains invalid value(s): %s. It can only contain %s.", getDefaultMonitoringCommandArgument(), String.join(", ", enabledFeatures),
8284
MONITORING_ALLOWED_VALUES);
8385
}
86+
87+
if (Platform.includedIn(WINDOWS.class)) {
88+
Set<String> notSupported = getEnabledMonitoringFeatures();
89+
notSupported.retainAll(NOT_SUPPORTED_ON_WINDOWS);
90+
if (!notSupported.isEmpty()) {
91+
String warning = String.format("the option '%s' contains value(s) that are not supported on Windows: %s. Those values will be ignored.", getDefaultMonitoringCommandArgument(),
92+
String.join(", ", notSupported));
93+
LogUtils.warning(warning);
94+
}
95+
}
8496
}
8597

8698
@Platforms(Platform.HOSTED_ONLY.class)

0 commit comments

Comments
 (0)