Java - Memory dump analysis

From XennisWiki
Jump to: navigation, search

Memory dump analysis

Create a heap dump by using jcdm

Further information: jcmd documentation

Find the process

jcmd

Read the help manual of a task

jcmd <process> help <task>
jcmd <process> help GC.heap_dump

Create a dump for process 6. Use -all to create a dump without a full gc, i.e. a larger dump, but includes collectable objects.

jcmd <process> GC.heap_dump /tmp/heap.hprof

Enable JMX remote debugging

Command line parameters to enable JXM during development

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9010 
-Dcom.sun.management.jmxremote.local.only=false 
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

Start JMX

jcmd # Get process id
jcmd <process> ManagementAgent.start jmxremote.ssl=false jmxremote.port=9010 jmxremote.rmi.port=9010 jmxremote.authenticate=false

Tools

Eclipse with Memory Analyser plugin

Requirements:

Install the plugin Memory Analyzer for Eclipse IDE (Analyzer and Charts) from http://download.eclipse.org/mat/1.7/update-site/ . In Eclipse open the perspective Memory Analysis.

Visualvm

Installation
Usage

Connect

visualvm --openjmx <host>:<ip>

GC log analysis

Enable verbose GC logging

Verbose GC logging is disabled by default. But enabling is harmless.

-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintCodeCache
-Xloggc:/tmp/gc.log

Configure log rotation

-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=2M

Tools

GCeasy

Open the website and upload the GC log.

See also