MAT – Memory Analyzer Toolkit

MAT – Memory Analyzer Toolkit

What is the Memory Analyzer?

The SAP Memory Analyzer also known as the Memory Analyzer Toolkit (MAT) is a tool that can be used for in-depth Memory Analysis of Java heaps.  The beauty of this tool is the comprehensive views and canned queries that can be used to fully understand what is happening on the heap, which then allows you to better control how you develop with regards toward memory management.

Where can I get the Memory Analyzer?

The SAP is now a fully supported Eclipse project, known as the MAT (Memory Analyzer Toolkit) and can be downloaded either as a plug-in for Eclipse or as a stand alone application that uses the Eclipse RCP framework.  Both of these can be downloaded from: http://www.eclipse.org/mat/.

Are there any tutorials on the Memory Analyzer?

  • There is a great 10 minute screencast associated with the SAP’s site, which appears to still be valid.  You have to register to view it, but registration is free and I think it’s worth it to review.  The screen cast is available here: https://www.sdn.sap.com/irj/scn/wiki?path=/display/Java/Java+Memory+Analysis (on right side of page you will see a text block regarding screencam).
  • If you would rather have a more in-depth live review of the application and it’s functions the developers held a 45+ minute webcast which is hosted by live eclipse and is available here: http://live.eclipse.org/node/520 or as a link on the eclipse MAT project home page
  • (http://www.eclipse.org/mat/).

HeapDump

http://java.sun.com/developer/technicalArticles/Programming/HPROF.html

  • JConsole
    • Under the MBeans Tab expand the com.sun.management bean and using the dumpHeap option pass in the fully qualified path and filename to where the dump should be created.  NOTE:  The file must end in .hprof which is the standard file type for a heap dump.
  • Using JMAP
    • Navigate to the <JAVA_HOME>/bin
    • Find the process ID for the Java process that you want to take a heap dump of.
    • Run the following
      • jmap -dump:file=app.hprof <PID>

Start the MAT

  • Startup the MAT utility either via stand-alone or open/start your eclipse IDE if installed as a plug-in

Open the heap dump

  • Open the heap dump by dropping down file menu and clicking open file
  • The MAT will start indexing/parsing the heap for usage and then build you an initial view of what it believes are the biggest leak offenders.

Analysis

General

Available Views

  • Historgram
    • This view is essentially the data aggregated at the class level
  • The dominator tree
    • This is a view of the actual objects and can be recursively opened to give a view of what objects are being retained by their parents (i.e. if the parent went away what would be freed).

Analysis Process

  1. Take a look at the available leak chart that has been displayed by the MAT as being recorded as the biggest offenders (top consumers)
  2. Open up the dominator tree and look for these objects.  Hint: They will most likely be at the top
  3. Expand the top offender and then take a look at what is being retained to cause it’s offending footprint size
  4. Next review the logic around why this object is in memory and being retained, is it necessary or can it be done differently to avoid the problem.  Maybe the object is holding more data than required and causing the large heap footprint issue.

//

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.