Skip to content
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

Support of visualvm monitoring on native image #1268

Open
cnico opened this issue Aug 7, 2024 · 3 comments
Open

Support of visualvm monitoring on native image #1268

cnico opened this issue Aug 7, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@cnico
Copy link

cnico commented Aug 7, 2024

I tried to use the monitoring of native image build for my javafx application with gluonfx maven plugin.
I am on windows and my build and native app following gluon docs works correctly :)

I followed : https://www.graalvm.org/latest/tools/visualvm/ to add --enable-monitoring=all to the native image build.

I did this configuration in the pom.xml :

         <properties>
		<gluonfx.plugin.version>1.0.23</gluonfx.plugin.version>
		<gluonfx.target>host</gluonfx.target>
		<gluonfx.nativeImageArgs>--enable-monitoring=all</gluonfx.nativeImageArgs>
                  ...
	</properties>
...

	<plugin>
				<groupId>com.gluonhq</groupId>
				<artifactId>gluonfx-maven-plugin</artifactId>
				<version>${gluonfx.plugin.version}</version>
				<configuration>
					<target>${gluonfx.target}</target>
					<mainClass>${main.class}</mainClass>
					<verbose>true</verbose>
					<runtimeArgs>${runtime.arguments}</runtimeArgs>
					...

The build failed with the logs :
[mer. ao├╗t 07 10:03:10 CEST 2024][INFOS] [SUB] Error: Unrecognized option: --enable-monitoring=all
[mer. août 07 10:03:10 CEST 2024][PRÉCIS] Result for compile: 1
[mer. ao├╗t 07 10:03:10 CEST 2024][GRAVE] Process compile failed with result: 1

Expected Behavior

I expect the option of monitoring is supported and I can then connect with visualvm to my native application in order to profile it.

Current Behavior

Build fail.

Context

I try to analyze ressource usage (cpu, memory) of the native image and optimize it because cpu usage is excessive by now.

@cnico cnico added the enhancement New feature or request label Aug 7, 2024
@jperedadnr
Copy link
Contributor

The option --enable-monitoring was added to this commit oracle/graal@8e6bbfd

If you are using Gluon build of GraalVM (22.1.0.1-Final), that commit didn't make it to the build.

If you check the changes in that commit:

- To build a native executable with JFR, use the `-H:+AllowVMInspection` flag:
+ To build a native executable with JFR, use the `--enable-monitoring=jfr` flag:

the "old" way to enable VM inspection works with GluonFX and GraalVM 22.1.0.1-Final:

<nativeImageArgs>-H:+AllowVMInspection</nativeImageArgs>

Note also that if you want to test on desktop, you can try a more recent GraalVM official build with the GluonFX plugin, and the new flag.

@cnico
Copy link
Author

cnico commented Aug 9, 2024

Hi,
Thanks you for your feedback.
I tried various options and did have no success with neither of them.

Here are my attemps :
1/ With the "old" way, I added the option in the pom.xml
<nativeImageArgs>-H:+AllowVMInspection</nativeImageArgs>

It fails with the following error :

Exception in thread "main" java.lang.IllegalArgumentException: Installing signal handlers is not enabled
at jdk.internal.misc.Signal.handle0(Signal.java:63)
at jdk.internal.misc.Signal.handle(Signal.java:170)
at sun.misc.Signal.handle(Signal.java:157)
at com.oracle.svm.core.DumpAllStacks.install(VMInspection.java:101)
at com.oracle.svm.core.VMInspectionStartupHook.execute(VMInspection.java:88)
at com.oracle.svm.core.jdk.RuntimeSupport.executeHooks(RuntimeSupport.java:151)
at com.oracle.svm.core.jdk.RuntimeSupport.initialize(RuntimeSupport.java:96)
at org.graalvm.nativeimage.VMRuntime.initialize(VMRuntime.java:65)

As my app is only a Desktop one, with a recent version of graalVM set in the PATH (version 22.0.1 of april), I tried various syntax for the options :

2/ With this maven conf :
<nativeImageArgs>--enable-monitoring=heapdump,jvmstat</nativeImageArgs>
Maven build fails because it converts the , as a separator for args

3/ With :

<nativeImageArgs>
  <nativeImageArg>--enable-monitoring=heapdump,jvmstat</nativeImageArg>
</nativeImageArgs>

Build is OK but native exe crashes at startup with a :

Exception in thread "main" java.lang.IllegalArgumentException: Signal handlers can't be installed if signal handling is disabled, see option 'EnableSignalHandling'.
at [email protected]/jdk.internal.misc.Signal.handle0(Signal.java:63)
at [email protected]/jdk.internal.misc.Signal.handle(Signal.java:170)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.DumpAllStacks.install(DumpThreadStacksOnSignalFeature.java:71)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.DumpThreadStacksOnSignalStartupHook.execute(DumpThreadStacksOnSignalFeature.java:64)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.RuntimeSupport.executeHooks(RuntimeSupport.java:168)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.RuntimeSupport.initialize(RuntimeSupport.java:99)
at org.graalvm.nativeimage/org.graalvm.nativeimage.VMRuntime.initialize(VMRuntime.java:65)

4/ With an extensive search, I found other options and after many tries :

<nativeImageArgs>
  <nativeImageArg>--install-exit-handlers</nativeImageArg>
  <nativeImageArg>--enable-monitoring=all</nativeImageArg>
  <nativeImageArg>-R:+EnableSignalHandling</nativeImageArg>
</nativeImageArgs>

Build is OK and native exe starts correctly.
But in visualVM, my native image is not detected :(

If you have any idea on how to make it work, I really would appreciate it.

@cnico
Copy link
Author

cnico commented Sep 1, 2024

For information, I isolated and reproduced the problem with the latest version of graalvm and reported a bug here : oracle/graal#9563
Waiting for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants