oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.19k stars 1.62k forks source link

[GR-55881] Issue with JDK Mission Control and Native Image Application Using JMX #9349

Closed albertattard closed 1 month ago

albertattard commented 1 month ago

I would like to report an issue I've encountered with GraalVM. While the JDK Mission Control is able to connect to a native image application using JMX, it does not display all fields correctly. Specifically, while LocalDateTime fields work well with Java, they fail with the native image, resulting in the following warning:

WARNING: Error getting attributes: error unmarshalling return; nested exception is: java.io.EOFException

This issue is not limited to application MBeans but also affects the default MBeans available.

To demonstrate this problem, I have created an example which you can find here: graalvm-observability-jmx. Simply build the native image and then run the application. This application will keep running until either the exit operation is executed through JMX or it is manually terminated.

I am using the latest GraalVM 21 version on macOS (M1 chip).

java 21.0.4 2024-07-16 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41, mixed mode, sharing)

I would appreciate any assistance or guidance you can provide regarding this issue. Thank you very much for your time and support.

selhagani commented 1 month ago

Hi @albertattard , thank you for reporting this.

I just reproduced the issue and I confirm the issue you're facing. We'll take a further look into this and I will keep you updated.

albertattard commented 1 month ago

Thank you @selhagani. Let me know if you require any further information.

fniephaus commented 1 month ago

@roberttoyonaga is this something you could look into?

roberttoyonaga commented 1 month ago

@fniephaus Yup, I can look into this issue.

roberttoyonaga commented 1 month ago

I was able to reproduce the issue. It looks like the problem is that you need to add serialization configuration for LocalDateTime.

Adding the below json in serialization-config.json inside the META-INF directory should fix the problem.

{
  "types":[

    {
      "name":"java.time.LocalDateTime"
    },
    {
      "name":"java.time.Ser"
    }
  ],
  "lambdaCapturingTypes":[
  ],
  "proxies":[
  ]
}

image

Running the Native Image Tracing Agent will help you generate the correct configuration automatically.

It's unfortunate that JMX requires extra configuration, but there isn't a good way of pre-configuring for all use-cases without greatly increasing image size (and remote JMX is already quite heavyweight). Maybe I'll update the JMX docs to suggest users run the tracing agent to generate their custom reflection configuration before using remote JMX.

albertattard commented 1 month ago

Thank you very much @roberttoyonaga. I've noticed that some of the attributes that are exposed by the VM have the same issue. How can I address these too, please?

roberttoyonaga commented 1 month ago

image I think "java.lang.Double" needs to be added to the serialization config as well. All those "[N/A]" attribute values are doubles.

I'll open a PR to add java.lang.Double to the remote JMX Feature serialization config. It ought to be added there since its required for the OS platformMXBean.

Until that PR is integrated, you can use this for now:

{
  "types":[
    {
      "name":"java.time.LocalDateTime"
    },
    {
      "name":"java.lang.Double"
    },
    {
      "name":"java.time.Ser"
    }
  ],
  "lambdaCapturingTypes":[
  ],
  "proxies":[
  ]
}
albertattard commented 1 month ago

That's great @roberttoyonaga.

roberttoyonaga commented 1 month ago

I've put a PR up here: https://github.com/oracle/graal/pull/9357

fniephaus commented 1 month ago

Thanks, Robert! I just took a look :)

fniephaus commented 1 month ago

This just got fixed on the main branch, and hopefully we can still backport it into the JDK 23 release.