Article DetailsDetailsHelp Details This document provides the process of creating a heap dump from a Java virtual machine (JVM). Automatic Creation Heap dumps can be generated automatically when an OutOfMemoryError exception is thrown by specifying -XX:+HeapDumpOnOutOfMemoryError VM option. For example: dbms.jvm.additional=-XX:+HeapDumpOnOutOfMemoryError dbms.jvm.additional=-XX:HeapDumpPath=/data/dump The heap dump will be created in the path specified in -XX:HeapDumpPath. This should be changed to a suitable path in the environment. It can also be omitted, in which case the dump is created in the working directory of the Neo4j Java process. Manual Creation Heap dumps can be manually generated using the jmap tool. This tool will dump information about the heap to a file. This file can then be shared with Neo4j for analysis. 1. Find the DBMS Process ID The jmap tool requires the process ID of the JVM in which Neo4j's DBMS is running. Server Installations To get a list of Java processes running on a server, use the jps or jcmd commands. If jps or jcmd is not available, it is also possible to use ps as shown in the examples below. In these examples, the Neo4j JVM has process ID 854. Using jps $ jps -l 854 com.neo4j.server.enterprise.EnterpriseEntryPoint 1103 jdk.jcmd/sun.tools.jps.Jps Using jcmd $ jcmd 854 com.neo4j.server.enterprise.EnterpriseEntryPoint --home-dir=/var/lib/neo4j --config-dir=/etc/neo4j 1135 jdk.jcmd/sun.tools.jcmd.JCmd Using ps $ ps -aux | grep com.neo4j.server.enterprise.EnterpriseEntryPoint root 854 4.0 1.8 21046544 758084 pts/1 Sl 07:54 0:24 /usr/lib/jvm/java-17-amazon-corretto.aarch64/bin/java -cp /var/lib/neo4j/plugins/*:/etc/neo4j/*:/usr/share/neo4j/lib/* -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -XX:+DisableExplicitGC -XX:-RestrictContended -Djdk.nio.maxCachedBufferSize=1024 -Dio.netty.tryReflectionSetAccessible=true -Djdk.tls.ephemeralDHKeySize=2048 -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:FlightRecorderOptions=stackdepth=256 -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED --enable-native-access=ALL-UNNAMED -Dlog4j2.disable.jmx=true -Dlog4j.layout.jsonTemplate.maxStringLength=32768 -Dfile.encoding=UTF-8 com.neo4j.server.enterprise.EnterpriseEntryPoint --home-dir=/var/lib/neo4j --config-dir=/etc/neo4j root 1193 0.0 0.0 2472 1264 pts/1 S+ 08:04 0:00 grep com.neo4j.server.enterprise.EnterpriseEntryPoint Docker Deployments In an official Neo4j Docker container, the process will be com.neo4j.server.enterprise.EnterpriseEntryPoint and the Neo4j JVM typically has process ID 7. The jps command is provided within the official Neo4j image. $ jps -l 7 com.neo4j.server.enterprise.EnterpriseEntryPoint 1319 jdk.jcmd/sun.tools.jps.Jps 2. Generate the Heap Dump File The following command can be used to generate the heap dump. Make sure to change <filename> and <pid>, where <filename> is the file name of the resulting dump and <pid> is the process ID from step 1. jmap -dump:[live,]format=b,file=<filename>.bin <pid> The above will dump the Java heap in binary format to the <filename> specified and include the live objects from the heap. This is the format required by Neo4j. In Windows Systems where dbgeng.dll is not present, 'Debugging Tools For Windows' needs to be installed to have these tools working. Also, the PATH environment variable should contain the location of jvm.dll used by the target process or the location from which the Crash Dump file was produced. For example, set PATH=<jdk>\jre\bin\client;%PATH% An Example of Neo4j Running in a Docker Container Here is an example of how to collect Heap dumps from within a Docker container. Exec into the container $ docker exec -it --user neo4j <container_name> bash Use jps to find the Java process $ jps -l 7 com.neo4j.server.enterprise.EnterpriseEntryPoint 1421 jdk.jcmd/sun.tools.jps.Jps Use jcmd to generate the heap dump, here the filename is /tmp/heapdump.hprof and the process ID is 7 $ jmap -dump:live,format=b,file=/tmp/heapdump.hprof 7 The above sequence can be executed from outside the container as shown in the following example. Make sure to specify the <container_name> and the <neo4j_pid> docker exec -it --user neo4j <container_name> jmap -dump:live,format=b,file=/tmp/heapdumps.hprof <neo4j pid> The heap dumb file will then need to be copied out of the container (This assumes that the location where the heap dump is generated is not accessible from outside the container). To do this, exit the container $ exit Then copy the heap dump out of the container. Make sure to specify the <container_name> correctly. docker cp <container_namne>:/tmp/heapdump.hprof . Viewing heap dumps To browse heap dumps generated as above, one can use jhat (Java Heap Analysis Tool) to read the generated file. Some useful options to use with jmap are: -heap prints a heap summary instead of a binary dump.-histo[:live] prints a histogram of the heap.-F can be used with jmap -dump or jmap -histo option if the pid does not respond. We can use the jhat command to parse a java heap dump file and launch a web server to view heap dumps over a web browser. The default port is 7000, but we can change this by using the -port option Syntax: $ jhat [ options ] <heap-dump-file> e.g. jhat -port 7001 -debug 1 where -port determines the browser port the output can be viewed, and -debug <int> determines the level of debug detail presented. We can also use the jconsole tool to view CPU, memory and heap utilisation in a graphical format. $ jconsole [ options ] [ connection ... ] e.g. jconsole -interval=5 <pid> 127.0.0.1:7474 where -interval=n determines the report refresh interval in seconds, <pid> is the process id of the target JVM (the JVM must be running with the same user id as that running the jconsole) References: https://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.htmlhttps://docs.oracle.com/javase/7/docs/technotes/tools/share/jhat.htmlhttps://docs.oracle.com/javase/7/docs/technotes/tools/share/jconsole.htmlhttps://docs.oracle.com/en/java/javase/11/tools/jmap.htmlhttps://docs.oracle.com/en/java/javase/11/tools/jmap.htmlhttps://docs.oracle.com/en/java/javase/11/tools/jconsole.html Related ArticlesAnalyzing a java heap dumpHelpful Commands When Supporting Neo4j InformationTitleGenerating a JVM heap dumpArticle Created Date3/15/2024, 10:56 PMURL Name360000923248-Generating-a-JVM-heap-dumpLast Modified Date6/10/2025, 7:26 AM