Skip to content

Commit 42fa59e

Browse files
Update VisualVM documentation and add more validation for the option '--enable-monitoring'.
1 parent 5cc94b9 commit 42fa59e

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

docs/tools/visualvm.md

+11-7
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

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.oracle.svm.core.heap.dump.HeapDumping;
3838
import com.oracle.svm.core.jdk.management.ManagementAgentModule;
3939
import com.oracle.svm.core.option.APIOption;
40-
import com.oracle.svm.core.option.HostedOptionKey;
4140
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
41+
import com.oracle.svm.core.option.HostedOptionKey;
4242
import com.oracle.svm.core.option.RuntimeOptionKey;
4343
import com.oracle.svm.core.option.SubstrateOptionsParser;
4444
import com.oracle.svm.core.util.UserError;
@@ -63,6 +63,7 @@ public final class VMInspectionOptions {
6363

6464
private static final List<String> MONITORING_ALL_VALUES = List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME, MONITORING_JVMSTAT_NAME, MONITORING_JMXCLIENT_NAME, MONITORING_JMXSERVER_NAME,
6565
MONITORING_THREADDUMP_NAME, MONITORING_NMT_NAME, MONITORING_ALL_NAME, MONITORING_DEFAULT_NAME);
66+
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);
6667
private static final String MONITORING_ALLOWED_VALUES_TEXT = "'" + MONITORING_HEAPDUMP_NAME + "', '" + MONITORING_JFR_NAME + "', '" + MONITORING_JVMSTAT_NAME + "', '" + MONITORING_JMXSERVER_NAME +
6768
"' (experimental), '" + MONITORING_JMXCLIENT_NAME + "' (experimental), '" + MONITORING_THREADDUMP_NAME + "', '" + MONITORING_NMT_NAME + "' (experimental), or '" +
6869
MONITORING_ALL_NAME + "' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";
@@ -93,11 +94,22 @@ public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused")
9394
getDefaultMonitoringCommandArgument(),
9495
SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, String.join(",", List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME))));
9596
}
97+
9698
enabledFeatures.removeAll(MONITORING_ALL_VALUES);
9799
if (!enabledFeatures.isEmpty()) {
98100
throw UserError.abort("The '%s' option contains invalid value(s): %s. It can only contain %s.", getDefaultMonitoringCommandArgument(), String.join(", ", enabledFeatures),
99101
MONITORING_ALLOWED_VALUES_TEXT);
100102
}
103+
104+
if (Platform.includedIn(WINDOWS.class)) {
105+
Set<String> notSupported = getEnabledMonitoringFeatures();
106+
notSupported.retainAll(NOT_SUPPORTED_ON_WINDOWS);
107+
if (!notSupported.isEmpty()) {
108+
String warning = String.format("the option '%s' contains value(s) that are not supported on Windows: %s. Those values will be ignored.", getDefaultMonitoringCommandArgument(),
109+
String.join(", ", notSupported));
110+
LogUtils.warning(warning);
111+
}
112+
}
101113
}
102114

103115
@Platforms(Platform.HOSTED_ONLY.class)

0 commit comments

Comments
 (0)