Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JVM Boolean Options

DZone's Guide to

JVM Boolean Options

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

While trying to generate a a Java Heap Dump, I remembered there is one JVM option I could use for this purpose. Since I can’t always remember these options’ names, I went to the Oracle documentation.

So I could extract the following arguments:

-XX:-HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs/jvm/dumps/

After limiting my Java Heap size to a value that I know it’s too low, I was expecting the Heap Dump to be generated whenever I got an OutOfMemoryError. But no dump got generated. I googled the issue, checked for JMV bugs but the only reported issue was a miss-usage when you give the JVM options after the Java Main class, but that wasn’t my case.

Then I stumbled on a slightly different version of my original setting (the one that I copy-pasted from the Oracle site):

-XX:+HeapDumpOnOutOfMemoryError

Then, I remember I once read about Boolean JVM options, and the very same Oracle site details this usage:

“Boolean options are turned on with -XX:+ and turned off with -XX:-.”

If you enjoy reading this article, you might want to subscribe to my newsletter and get a discount for my book as well.

Vlad Mihalcea's Newsletter

I think the Oracle JVM options table should show the “+” version, since that’s usually what you are looking for, especially because it’s disabled by default (so the “-” version behaves like not giving it at all).

If you enjoyed this article, I bet you are going to love my book as well.






The HeapDumpPath should point to a folder, but if your setting is something like /logs/jvm/dumps/, and your OS only contains /logs/jvm, then you won’t get a “java_pid.hprof” file within the /logs/jvm/dumps/ folder, but a dump file in /logs/jvm/, as the JVM doesn’t create the missing folders (a.k.a mkdirs).

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:
java ,tips and tricks

Published at DZone with permission of Vlad Mihalcea. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}