Micrometer: Metaspace max is -1.0 when MaxMetaspaceSize is set with JAVA_TOOL_OPTIONS

Created on 19 Jan 2021  路  7Comments  路  Source: micrometer-metrics/micrometer

Most of the JVMs accepts passing JVM parameters through environment variable JAVA_TOOL_OPTIONS.
When passing -XX:MaxMetaspaceSize=256m through JAVA_TOOL_OPTIONS environment variable Micrometer reports:

jvm_memory_max_bytes{area="nonheap",id="Metaspace",} -1.0

If I print JVM flags on start (by adding -XX:+PrintFlagsFinal to JAVA_TOOL_OPTIONS) then I can see MaxMetaspaceSize has been set properly:

size_t MaxMetaspaceSize                         = 268435456                                 {product} {environment}

Micrometer behavior is correct if -XX:MaxMetaspaceSize=256m is passed through command line instead of environment variable.

jvm_memory_max_bytes{area="nonheap",id="Metaspace",} 2.68435456E8

I believe the value reported by Micrometer should be the same in both cases.

bug external-project

Most helpful comment

@jozala a bug ticket has been created in the JDK bug database now. See JDK-8260349

All 7 comments

Thank you for the detailed report. This does sound like a bug, but I'm not sure it can be fixed in Micrometer. You can check the memory MBeans from jconsole and see the same behavior (max missing or not depending on the configuration method). Micrometer is getting this information from the platform's MemoryPoolMXBeans, so what is available is limited by that. I think this needs to be fixed in the JVM, if possible.

As a workaround, if you're using Java 9 or newer, it seems you can use JDK_JAVA_OPTIONS instead and we are able to get the max Metaspace programmatically in that case.
https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE

I've submitted a Java bug report. I'll update here what the conclusion of that is. I don't think there is a reason to keep this issue open, though. The above workaround is available if you are on a recent version of Java.

@shakuzen Thank you for all the information and provided workaround. My applications run on JRE 11 from AdoptOpenJDK. I will check it works and report back to this issue.
Could you please provide link to the Java bug report you've submitted? I would be interested in following this ticket.

Thank you for taking care of this issue.

Could you please provide link to the Java bug report you've submitted? I would be interested in following this ticket.

Sorry, I should have mentioned: my submitted report is being reviewed. Pending review, a bug ticket will be made or not.

@jozala a bug ticket has been created in the JDK bug database now. See JDK-8260349

I forgot to mention it earlier. Mentioned workaround with using JDK_JAVA_OPTIONS works perfectly.
Thank you.

Was this page helpful?
0 / 5 - 0 ratings