jmap: Could not reserve enough space for object heap

If you get the following error message when using jmap to get a Java heap dump:

# $JAVA_HOME/bin/jmap -dump:file=/tmp/dump.hprof PID
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

it’s due to the default heap size used in the server VM so you just need to set some values for the Xmx and Xms parameters. With jmap you also need to prefix it with a -J meaning that this parameter will be transferred to the underlying JVM:

 # $JAVA_HOME/bin/jmap -F -J-Xms16m -J-Xmx128m -dump:file=/tmp/dump.hprof 24613
Attaching to process ID 24613, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.4-b02
Dumping heap to /tmp/dump.hprof ...
Finding object size using Printezis bits and skipping over...
...
Finding object size using Printezis bits and skipping over...
Heap dump file created

If you create multiple files, it makes sense to have a timestamp in the filename e.g.:

 # $JAVA_HOME/bin/jmap -F -J-Xms16m -J-Xmx128m -dump:file=/tmp/dump.`date '+%Y%m%d%H%M%S'`.hprof 24613

Leave a Reply

Your email address will not be published.